public ActionResult <ListingDTO> AddListing(ListingDTO ldto) { var owner = GetOwner(); try{ Animal an = _aRepo.GetAnimal(ldto.AnimalID); if (an == null) { throw new Exception("The specified animal could not be found"); } if (an.Owner != owner) { throw new InvalidListingException("You can't put up someone elses animal for sale or breeding."); } if (_listingRepo.AnimalIsInListing(an)) { throw new InvalidListingException("This animal is already in a listing"); } Listing listing; if (ldto.BreedAmount == 0 && ldto.AdoptAmount == 0) { listing = new Listing(an, ldto.IsAdoptable, ldto.IsBreedable); } else { listing = new Listing(an, ldto.IsAdoptable, ldto.IsBreedable , ldto.AdoptAmount, ldto.BreedAmount); } _listingRepo.AddListing(listing); _listingRepo.SaveChanges(); var list = _listingRepo.GetListingWithID(listing.ID); return(CreatedAtAction(nameof(GetListingWithID), new { id = listing.ID } , new ListingDTO(list))); }catch (Exception e) { ModelState.AddModelError("Error", e.Message); return(BadRequest(ModelState)); } }