Example #1
0
        public HttpResponseMessage Create(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
                {
                    var newpages = new Footer();
                    newpages.UpdateFooter(footerViewModel);

                    _footerService.Add(newpages);
                    _footerService.Save();

                    var responseData = Mapper.Map <Footer, FooterViewModel>(newpages);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
Example #2
0
        public HttpResponseMessage Create(HttpRequestMessage request, FooterViewModel footerVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newFooter = new Footer();
                    newFooter.UpdateFooter(footerVm);
                    _footerService.Add(newFooter);
                    _footerService.Save();

                    var responseData = Mapper.Map <Footer, FooterViewModel>(newFooter);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
Example #3
0
 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());
 }