예제 #1
0
 public HttpResponseMessage Update(HttpRequestMessage request, LOAI_SAN_PHAM loaiSanPhamModel)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var loaiSanPhamDb = _loaiSanPhamService.GetByID(loaiSanPhamModel.ID);
             _loaiSanPhamService.Update(loaiSanPhamDb);
             _loaiSanPhamService.SaveChange();
             response = request.CreateResponse(HttpStatusCode.OK);
         }
         return response;
     }));
 }
예제 #2
0
        public HttpResponseMessage Update(HttpRequestMessage request, LoaiSanPham loaiSanPham)
        {
            LoaiSanPham modelLoaiSanPham = null;

            try
            {
                _loaiSanPhamService.Update(loaiSanPham);
                _loaiSanPhamService.SaveChange();
                modelLoaiSanPham = _loaiSanPhamService.GetById(loaiSanPham.IdLoaiSanPham);
                if (modelLoaiSanPham != null)
                {
                    Message = "Sửa thông tin loại sản phẩm thành công";
                }
                else
                {
                    throw new DbEntityValidationException("sửa thông tin loại sản phẩm không thành công");
                }
            }
            catch (DbEntityValidationException ex)
            {
                LogException(ex);
            }
            return(GetResponseMessage(IsSuccess, Message, 1, modelLoaiSanPham));
        }