public HttpResponseMessage Update(HttpRequestMessage request, FooterViewModel footerViewModel) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { //trả về lỗi để bên ngoài bắt được sự kiện lỗi này response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { Footer dbPages = _footerService.GetSingleByString(footerViewModel.ID); dbPages.UpdateFooter(footerViewModel); _footerService.Update(dbPages); _footerService.Save(); var responseData = Mapper.Map <Footer, FooterViewModel>(dbPages); response = request.CreateResponse(HttpStatusCode.Created, responseData); } return response; })); }
public HttpResponseMessage Update(HttpRequestMessage request, FooterViewModel footerVm) { return(CreateHttpResponse(request, () => { if (ModelState.IsValid) { Footer footerDb = _footerService.GetAll(); footerDb.UpdateFooter(footerVm); _footerService.Update(footerDb); _footerService.SaveChange(); return request.CreateResponse(HttpStatusCode.Created, footerVm); } else { return request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } })); }
public ActionResult Put(FooterViewModel footer) { if (ModelState.IsValid) { var model = _FooterService.GetById(footer.ID); if (model == null) { ModelState.AddModelError("", "Không tìm thấy nội dung"); } model.UpdateFooter(footer); _FooterService.Update(model); _FooterService.Save(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Cập nhật không thành công"); } return(View()); }
public HttpResponseMessage Put(HttpRequestMessage request, FooterViewModel footerVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { var footerDb = _footerService.GetByID(footerVm.ID); footerDb.UpdateFooter(footerVm); _footerService.Update(footerDb); _footerService.SaveChanges(); response = request.CreateResponse(HttpStatusCode.OK); } return response; })); }
public async Task <HttpResponseMessage> Put(HttpRequestMessage request, FooterViewModel footerVm) { //Khoi tao var footerDb = await _footerService.GetById(footerVm.ID); //AutoMapper footerDb.UpdateFooter(footerVm); return(await CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { _footerService.Update(footerDb); _footerService.SaveAsync(); response = request.CreateResponse(HttpStatusCode.OK); } return response; })); }
public HttpResponseMessage Update(HttpRequestMessage request, FooterViewModel footerVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { var dbFooter = _footerService.GetById(footerVm.ID); dbFooter.UpdateFooter(footerVm); _footerService.Update(dbFooter); _footerService.Save(); var responseData = Mapper.Map <Footer, FooterViewModel>(dbFooter); response = request.CreateResponse(HttpStatusCode.Created, responseData); } return response; })); }