Add first sanity check
This commit is contained in:
@@ -44,6 +44,14 @@ namespace GerbilManagerWebAPI.Controllers
|
|||||||
[HttpPost()]
|
[HttpPost()]
|
||||||
public ActionResult<LitterDto> CreateLitter(CreateLitterDto dto)
|
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{
|
Litter litter = new Litter{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Date = dto.Date,
|
Date = dto.Date,
|
||||||
|
|||||||
Reference in New Issue
Block a user