From fe72a360ae44cf2452852ec00684e4ab8d413fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Desc=C3=B4teaux?= <125318411+marcdescotes@users.noreply.github.com> Date: Thu, 21 Sep 2023 08:50:01 -0400 Subject: [PATCH 1/5] Started new branch --- .../Controllers/RobotsController.cs | 35 ++++++++++++++++--- RobotsWantedLeague/Models/Robot.cs | 3 ++ .../Services/CountryConstants.cs | 10 ++++++ RobotsWantedLeague/Views/Robots/Robot.cshtml | 5 ++- 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 RobotsWantedLeague/Services/CountryConstants.cs diff --git a/RobotsWantedLeague/Controllers/RobotsController.cs b/RobotsWantedLeague/Controllers/RobotsController.cs index f9f783f..c408ef9 100644 --- a/RobotsWantedLeague/Controllers/RobotsController.cs +++ b/RobotsWantedLeague/Controllers/RobotsController.cs @@ -8,13 +8,43 @@ namespace RobotsWantedLeague.Controllers; public class RobotRequest { + // [AllowedCountry(ErrorMessage = "Le pays n'est pas autorisé.")] + // public string NewCountry { get; set; } public string Country { get; set; } public string Name { get; set; } public int Height { get; set; } public int Weight { get; set; } +// public static readonly List AllowedCountries = new List +// { +// "Canada", +// "United States of America", +// "Mexico", + +// }; + } +// public class AllowedCountryAttribute : ValidationAttribute +// { +// protected override ValidationResult IsValid(object value, ValidationContext validationContext) +// { +// string country = value as string; +// if (string.IsNullOrEmpty(country)) +// { +// return ValidationResult.Success; +// } + +// if (!CountryConstants.AllowedCountries.Contains(country, StringComparer.OrdinalIgnoreCase)) +// { +// return new ValidationResult(ErrorMessage); +// } + +// return ValidationResult.Success; +// } +// } + + public class RobotsController : Controller { private readonly ILogger _logger; @@ -51,10 +81,7 @@ public class RobotsController : Controller [HttpPost] public IActionResult CreateRobot([FromBody] RobotRequest robot) { - if (!ModelState.IsValid) - { - return View(robot); - } + Robot r = robotsService.CreateRobot(robot.Name, robot.Weight, robot.Height, diff --git a/RobotsWantedLeague/Models/Robot.cs b/RobotsWantedLeague/Models/Robot.cs index b18f2f4..e76a8d6 100644 --- a/RobotsWantedLeague/Models/Robot.cs +++ b/RobotsWantedLeague/Models/Robot.cs @@ -7,7 +7,9 @@ public class Robot public int Weight { get; set; } public int Height { get; set; } public string Country { get; set; } + // public string NewCountry { get; set; } public List VisitedCountries { get; set; } = new List(); + public Robot(int Id, string Name, int Weight, int Height, string Country) { @@ -16,6 +18,7 @@ public class Robot this.Weight = Weight; this.Height = Height; this.Country = Country; + // this.NewCountry = NewCountry; } diff --git a/RobotsWantedLeague/Services/CountryConstants.cs b/RobotsWantedLeague/Services/CountryConstants.cs new file mode 100644 index 0000000..5107611 --- /dev/null +++ b/RobotsWantedLeague/Services/CountryConstants.cs @@ -0,0 +1,10 @@ +// public static class CountryConstants +// { +// public static readonly List AllowedCountries = new List +// { +// "Canada", +// "United States of America", +// "Mexico", +// // Ajoutez les 7 autres pays autorisés ici +// }; +// } \ No newline at end of file diff --git a/RobotsWantedLeague/Views/Robots/Robot.cshtml b/RobotsWantedLeague/Views/Robots/Robot.cshtml index 1e750a6..db84651 100644 --- a/RobotsWantedLeague/Views/Robots/Robot.cshtml +++ b/RobotsWantedLeague/Views/Robots/Robot.cshtml @@ -49,6 +49,7 @@ +@Html.ValidationSummary(true) +@*
+
+
+ +
+
+
*@ + + + @@ -66,9 +76,7 @@
+ + + + + + + + + + + + + + + + + + + + + +
Nom@Model.Name
Id@Model.Id
Continent@Model.Continent
+ + + diff --git a/RobotsWantedLeague/Views/Agents/Index.cshtml b/RobotsWantedLeague/Views/Agents/Index.cshtml new file mode 100644 index 0000000..a205d75 --- /dev/null +++ b/RobotsWantedLeague/Views/Agents/Index.cshtml @@ -0,0 +1,17 @@ +@{ + ViewData["Title"] = "Home Page"; +} +@model List + +

LISTE DES AGENTS

+ +
+
    + @foreach (Agent agent in Model){ +
  • + @agent.Name +
  • + } +
+
+ diff --git a/RobotsWantedLeague/Views/Robots/Robot.cshtml b/RobotsWantedLeague/Views/Robots/Robot.cshtml index aaee6d1..e1d0770 100644 --- a/RobotsWantedLeague/Views/Robots/Robot.cshtml +++ b/RobotsWantedLeague/Views/Robots/Robot.cshtml @@ -12,17 +12,6 @@ -@*
-
-
- -
-
-
*@ - - - - diff --git a/RobotsWantedLeague/Views/Shared/_Layout.cshtml b/RobotsWantedLeague/Views/Shared/_Layout.cshtml index d5b0dbb..c23b51d 100644 --- a/RobotsWantedLeague/Views/Shared/_Layout.cshtml +++ b/RobotsWantedLeague/Views/Shared/_Layout.cshtml @@ -71,6 +71,11 @@
- + + + + + + - - - - - @@ -35,6 +35,3 @@
Id@Model.Id
Nom @Model.Name
Id@Model.Id
Continent @Model.Continent
- - - diff --git a/RobotsWantedLeague/Views/Agents/Index.cshtml b/RobotsWantedLeague/Views/Agents/Index.cshtml index a205d75..b8a001d 100644 --- a/RobotsWantedLeague/Views/Agents/Index.cshtml +++ b/RobotsWantedLeague/Views/Agents/Index.cshtml @@ -1,5 +1,5 @@ @{ - ViewData["Title"] = "Home Page"; + ViewData["Title"] = "Agent List"; } @model List diff --git a/RobotsWantedLeague/Views/Robots/Robot.cshtml b/RobotsWantedLeague/Views/Robots/Robot.cshtml index e1d0770..dd8d05c 100644 --- a/RobotsWantedLeague/Views/Robots/Robot.cshtml +++ b/RobotsWantedLeague/Views/Robots/Robot.cshtml @@ -14,7 +14,7 @@ - +
Nom