public IActionResult BreedFish([FromBody] FishBreeding breeding) { try { //Access level var id = _accountService.GetCurrentUserId(); var m = _fishService.GetFishById(breeding.MotherId); var d = _fishService.GetFishById(breeding.FatherId); var access = _accountService.CanModify(id, m); var access2 = _accountService.CanModify(id, d); if (!access || !access2) { return(Unauthorized()); } _logger.LogInformation($"POST /v1/Fish/Breed called"); var breed = _fishService.Breed(breeding); return(new OkObjectResult(breed)); } catch (Exception ex) { _logger.LogError($"POST /v1/Fish/Breed endpoint caught exception: { ex.Message } Details: { ex.ToString() }"); return(NotFound()); } }
public FishBreeding Breed(FishBreeding breeding) { //todo check if fish can breed with eachother var mother = _aquariumDao.GetFishById(breeding.MotherId); var father = _aquariumDao.GetFishById(breeding.FatherId); if (mother.SpeciesId != father.SpeciesId) { throw new Exception("These species cannot breed with eachother"); } if (breeding.Amount > 25) { throw new Exception("This is too large of a breeding"); } var newBreeding = _aquariumDao.AddBreeding(breeding); return(newBreeding); }