public IHttpActionResult CreateDanhSach(SacheDto sache) { if (!ModelState.IsValid) { //throw new HttpResponseException(HttpStatusCode.BadRequest); return(BadRequest()); } var sach = MappingConfig.Mapping.Map <SacheDto, Sache>(sache); context.Saches.Add(sach); context.SaveChanges(); return(Created(new Uri(Request.RequestUri + "/" + sache.Id), sach)); // MappingConfig.Mapping.Map<Sache, SacheDto>(sache); }
public void UpdateDanhSach(int id, SacheDto sache) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var sacheInDB = context.Saches.SingleOrDefault(c => c.Id == id); if (sacheInDB == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } MappingConfig.Mapping.Map <SacheDto, Sache>(sache, sacheInDB); context.SaveChanges(); }