Adding visited countries by robot + it stays #2
No files matched your search
@@ -8,13 +8,43 @@ namespace RobotsWantedLeague.Controllers;
|
|||||||
|
|
||||||
public class RobotRequest
|
public class RobotRequest
|
||||||
{
|
{
|
||||||
|
// [AllowedCountry(ErrorMessage = "Le pays n'est pas autorisé.")]
|
||||||
|
// public string NewCountry { get; set; }
|
||||||
public string Country { get; set; }
|
public string Country { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public int Height { get; set; }
|
public int Height { get; set; }
|
||||||
public int Weight { 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
|
public class RobotsController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<RobotsController> _logger;
|
private readonly ILogger<RobotsController> _logger;
|
||||||
@@ -51,10 +81,7 @@ public class RobotsController : Controller
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult CreateRobot([FromBody] RobotRequest robot)
|
public IActionResult CreateRobot([FromBody] RobotRequest robot)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
|
||||||
{
|
|
||||||
return View(robot);
|
|
||||||
}
|
|
||||||
Robot r = robotsService.CreateRobot(robot.Name,
|
Robot r = robotsService.CreateRobot(robot.Name,
|
||||||
robot.Weight,
|
robot.Weight,
|
||||||
robot.Height,
|
robot.Height,
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ public class Robot
|
|||||||
public int Weight { get; set; }
|
public int Weight { get; set; }
|
||||||
public int Height { get; set; }
|
public int Height { get; set; }
|
||||||
public string Country { get; set; }
|
public string Country { get; set; }
|
||||||
|
// public string NewCountry { get; set; }
|
||||||
public List<string> VisitedCountries { get; set; } = new List<string>();
|
public List<string> VisitedCountries { get; set; } = new List<string>();
|
||||||
|
|
||||||
|
|
||||||
public Robot(int Id, string Name, int Weight, int Height, string Country)
|
public Robot(int Id, string Name, int Weight, int Height, string Country)
|
||||||
{
|
{
|
||||||
this.Id = Id;
|
this.Id = Id;
|
||||||
@@ -16,6 +18,7 @@ public class Robot
|
|||||||
this.Weight = Weight;
|
this.Weight = Weight;
|
||||||
this.Height = Height;
|
this.Height = Height;
|
||||||
this.Country = Country;
|
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
|
||||||
|
// };
|
||||||
|
// }
|
||||||
@@ -49,6 +49,7 @@
|
|||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@Html.ValidationSummary(true)
|
||||||
|
|
||||||
<!-- Modal -->
|
<!-- Modal -->
|
||||||
<div class="modal fade" id="changeRobotCountryModal" tabindex="-1" role="dialog"
|
<div class="modal fade" id="changeRobotCountryModal" tabindex="-1" role="dialog"
|
||||||
@@ -65,7 +66,9 @@
|
|||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="newCountry">Entrez le nouveau pays :</label>
|
<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>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|||||||
Reference in new issue
Block a user