public async Task <ActionResult> CreateKid([FromBody] SaveKidResource newKid) { if (!(await _cabinRepository.CabinExistsAsync(newKid.CabinId))) { return(BadRequest()); } var kidInDb = newKid.ToData(); _kidRepository.Add(kidInDb); await _unitOfWork.CompleteAsync(); kidInDb = await _kidRepository.GetKidAsync(kidInDb.Id, includeRelated : true); return(Ok(KidResource.FromData(kidInDb, includeRelated: true))); }
public async Task <ActionResult> UpdateKid(int id, [FromBody] SaveKidResource kid) { if (!(await _cabinRepository.CabinExistsAsync(kid.CabinId))) { return(BadRequest()); } var kidInDb = await _kidRepository.GetKidAsync(id); if (kidInDb == null) { return(NotFound()); } await kid.UpdateDataAsync(kidInDb, _cabinRepository); await _unitOfWork.CompleteAsync(); return(Ok()); }