Adding visited countries by robot + it stays #2

Closed
marcdescotes wants to merge 7 commits from main into main
pull from: main
4 changed files with 48 additions and 5 deletions
Showing only changes of commit fe72a360ae - Show all commits

No files matched your search

@@ -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<string> AllowedCountries = new List<string>
// {
// "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<RobotsController> _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,
+3
View File
@@ -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<string> VisitedCountries { get; set; } = new List<string>();
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;
}
@@ -0,0 +1,10 @@
// public static class CountryConstants
// {
// public static readonly List<string> AllowedCountries = new List<string>
// {
// "Canada",
// "United States of America",
// "Mexico",
// // Ajoutez les 7 autres pays autorisés ici
// };
// }
+4 -1
View File
@@ -49,6 +49,7 @@
</table>
@Html.ValidationSummary(true)
<!-- Modal -->
<div class="modal fade" id="changeRobotCountryModal" tabindex="-1" role="dialog"
@@ -65,7 +66,9 @@
<div class="modal-body">
<div class="form-group">
<label for="newCountry">Entrez le nouveau pays :</label>
<input type="text" class="form-control" name="newCountry" id="newCountry" placeholder="Italie">
<input type="text" class="form-control" name="NewCountry" id="newCountry" placeholder="Italie">
@* à mettre dans input du haut : data-val="true"
<span asp-validation-for="NewCountry" class="text-danger"></span> *@
</div>
</div>
<div class="modal-footer">