Exemple #1
0
 public HttpResponseMessage Create(HttpRequestMessage request, LOAI_SAN_PHAM loaiSanPhamModel)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var loaiSanPham = _loaiSanPhamService.Add(loaiSanPhamModel);
             _loaiSanPhamService.SaveChange();
             response = request.CreateResponse(HttpStatusCode.Created, loaiSanPham);
         }
         return response;
     }));
 }
Exemple #2
0
        public HttpResponseMessage Create(HttpRequestMessage request, LoaiSanPham loaiSanPham)
        {
            LoaiSanPham modelLoaiSanPham = null;

            try
            {
                modelLoaiSanPham = _loaiSanPhamService.Add(loaiSanPham);
                if (modelLoaiSanPham != null)
                {
                    Message = "Tạo mới loại sản phẩm thành công";
                    _loaiSanPhamService.SaveChange();
                }
                else
                {
                    throw new DbEntityValidationException("tạo mới loại sản phẩm không thành công");
                }
            }
            catch (DbEntityValidationException ex)
            {
                LogException(ex);
            }
            return(GetResponseMessage(IsSuccess, Message, 1, modelLoaiSanPham));
        }