Add first sanity check

This commit is contained in:
2023-10-30 21:20:19 +01:00
parent d3d2b4b989
commit 6556e17146

View File

@@ -44,6 +44,14 @@ namespace GerbilManagerWebAPI.Controllers
[HttpPost()]
public ActionResult<LitterDto> CreateLitter(CreateLitterDto dto)
{
//Sanity check if father is male and mother is female
var father = this.unitOfWork.GerbilRepository.GetByID(dto.Father ?? Guid.Empty);
var mother = this.unitOfWork.GerbilRepository.GetByID(dto.Mother ?? Guid.Empty);
if(father?.Gender == Gender.female || mother?.Gender == Gender.male)
{
return BadRequest($"The mothers gender is {mother?.Gender.ToString() ?? "unknown"} and the fathers {father?.Gender.ToString() ?? "unknown"}.");
}
Litter litter = new Litter{
Id = Guid.NewGuid(),
Date = dto.Date,