public IHttpActionResult CreateDonor(DonorsDto donorDto) { if (!ModelState.IsValid) { return(BadRequest()); } var donor = Mapper.Map <DonorsDto, Donors>(donorDto); _context.Donors.Add(donor); _context.SaveChanges(); donorDto.id = donorDto.id; return(Created(new Uri(Request.RequestUri + "/" + donor.id), donorDto)); }
public void UpdateDonor(int id, DonorsDto donorDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var donorInDb = _context.Donors.SingleOrDefault(c => c.id == id); if (donorInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map(donorDto, donorInDb); _context.SaveChanges(); }