Ejemplo n.º 1
0
        public HttpResponseMessage Delete(HttpRequestMessage request, int id)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    ProductCategory delProductCategory = productCategoryService.GetById(id);

                    if (delProductCategory == null)
                    {
                        response = request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid ProductCategory.");
                    }
                    else
                    {
                        productCategoryService.Delete(id);
                        productCategoryService.Save();
                        ProductCategoryViewModel productCategoryVM = Mapper.Map <ProductCategory, ProductCategoryViewModel>(delProductCategory);
                        response = request.CreateResponse(HttpStatusCode.OK, productCategoryVM);
                    }
                }

                return response;
            }));
        }
 public HttpResponseMessage Delete(HttpRequestMessage request, int id)
 {
     if (id > 0)
     {
         return(CreateHttpResponse(request, () =>
         {
             HttpResponseMessage response = null;
             //check issue
             if (!ModelState.IsValid)
             {
                 //get status
                 response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
             }
             else
             {
                 //Delete
                 var reponse = _productCategoryService.Delete(id);
                 //Save change
                 _productCategoryService.Save();
                 //Mapping data to dataView
                 var responseData = Mapper.Map <ProductCategory, ProductCategoryViewModel>(reponse);
                 //Check request
                 response = request.CreateResponse(HttpStatusCode.Created, responseData);
             }
             return response;
         }));
     }
     else
     {
         return(request.CreateResponse(HttpStatusCode.BadRequest));
     }
 }
Ejemplo n.º 3
0
        public HttpResponseMessage Delete(HttpRequestMessage request, int id)
        {
            HttpResponseMessage response = null;

            if (!ModelState.IsValid)
            {
                response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
            }
            else
            {
                var result = productCategoryService.GetSingleById(id);
                if (result != null)
                {
                    IDictionary <string, object> dic = new Dictionary <string, object>();
                    dic.Add("CategoryID", result.CategoryID);
                    Product objPro = productService.Search(dic).FirstOrDefault();

                    if (objPro == null)
                    {
                        productCategoryService.Delete(id);
                        productCategoryService.SaveChanges();
                        response = request.CreateResponse(HttpStatusCode.OK, result);
                        return(response);
                    }
                    string msg = string.Format("Xóa thất bại! Thể loại {0} đã được sử dụng.", result.ProductCategoryName);
                    response = request.CreateResponse(HttpStatusCode.BadGateway, msg);
                }
                else
                {
                    response = request.CreateResponse(HttpStatusCode.NotFound);
                }
            }
            return(response);
        }
        public HttpResponseMessage Delete(HttpRequestMessage request, int id)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var oldProductCategory = _productCategoryService.Delete(id);
                    var identity = (ClaimsIdentity)User.Identity;
                    IEnumerable <Claim> claims = identity.Claims;
                    _productCategoryService.Save();
                    Log log = new Log()
                    {
                        AppUserId = claims.FirstOrDefault().Value,
                        Content = Notification.DELETE_PRODUCTCATEGORY,
                        Created = DateTime.Now
                    };
                    _logService.Create(log);
                    _logService.Save();
                    var responseData = Mapper.Map <ProductCategory, ProductCategoryViewModel>(oldProductCategory);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
        public JsonResult Delete(int id)
        {
            var target = _productCategoryService.Delete(id);

            _productCategoryService.Save();
            return(Json(new
            {
                message = ResultState.Delete_SUCCESS
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
 public IActionResult Delete(Guid id)
 {
     if (!ModelState.IsValid)
     {
         return(new BadRequestResult());
     }
     _productCategoryService.Delete(id);
     _productCategoryService.Save();
     return(new OkResult());
 }
 public HttpResponseMessage Delete(HttpRequestMessage req, int id)
 {
     return(CreateHttpResponse(req, () =>
     {
         HttpResponseMessage res = null;
         var productCategories = _productCategoryService.Delete(id);
         _productCategoryService.SaveChanges();
         res = req.CreateResponse(HttpStatusCode.OK, productCategories);
         return res;
     }));
 }
 public HttpResponseMessage Delete(HttpRequestMessage request, int id)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         var oldProductCategory = _productCategoryService.Delete(id);
         _productCategoryService.Save();
         var responseData = Mapper.Map <ProductCategory, ProductCategoryViewModel>(oldProductCategory);
         response = request.CreateResponse(HttpStatusCode.OK, responseData);
         return response;
     }));
 }
Ejemplo n.º 9
0
 public HttpResponseMessage Delete(HttpRequestMessage request, int id)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         var model = _productCategoryService.Delete(id);
         var mapper = Mapper.Map <ProductCategory, ProductCategoryViewModel>(model);
         _productCategoryService.SaveChange();
         response = request.CreateResponse(HttpStatusCode.OK, mapper);
         return response;
     }));
 }
Ejemplo n.º 10
0
        public IHttpActionResult Delete(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            else
            {
                var oldProductCategory = _productCategoryService.Delete(id);
                _productCategoryService.Save();

                var responseData = Mapper.Map <ProductCategory, ProductCategoryViewModel>(oldProductCategory);
                return(Ok(responseData));
            }
        }
        public ActionResult Delete(ProductCategory vm)
        {
            var cat = _productCategoryService.GetProductCategoryById(vm.ProductCategoryId);

            _productCategoryService.Delete(cat);
            return(RedirectToAction("List", "ProductCategory"));
        }
        public IHttpActionResult Delete([FromODataUri] System.Guid key)
        {
            logger.Trace("Call ProductCategoriesController Delete");

            productCategoryService.Delete(key);
            return(Ok());
        }
        public async Task <IActionResult> Delete(int id)
        {
            if (id == 0)
            {
                return(new BadRequestResult());
            }
            else
            {
                var notificationId = Guid.NewGuid().ToString();
                var announcement   = new AnnouncementViewModel
                {
                    Title       = User.GetSpecificClaim("FullName"),
                    DateCreated = DateTime.Now,
                    Content     = $"Product Category {_productCategoryService.GetById(id).Name} has been deleted",
                    Id          = notificationId,
                    UserId      = User.GetUserId(),
                    Image       = User.GetSpecificClaim("Avatar"),
                    Status      = Status.Active
                };
                var announcementUsers = new List <AnnouncementUserViewModel>()
                {
                    new AnnouncementUserViewModel()
                    {
                        AnnouncementId = notificationId, HasRead = false, UserId = User.GetUserId()
                    }
                };
                await _hubContext.Clients.All.SendAsync("ReceiveMessage", announcement);

                _productCategoryService.Delete(announcement, announcementUsers, id);
                _productCategoryService.Save();
                return(new OkObjectResult(id));
            }
        }
Ejemplo n.º 14
0
        public HttpResponseMessage DeleteMulti(HttpRequestMessage request, string selectedProductCategories)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (ModelState.IsValid)
                {
                    var productCategories = new JavaScriptSerializer().Deserialize <List <int> >(selectedProductCategories);
                    foreach (var item in productCategories)
                    {
                        _productCategoryService.Delete(item);
                    }
                    _productCategoryService.SaveChanges();

                    response = request.CreateResponse(HttpStatusCode.OK, productCategories.Count());
                }
                else
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }

                return response;
            }));
        }
Ejemplo n.º 15
0
        public HttpResponseMessage Delete(HttpRequestMessage request, int id)
        {
            HttpResponseMessage response = null;

            if (ModelState.IsValid)
            {
                var oldProductCategory = _productCategoryService.Delete(id);
                _productCategoryService.Save();
                var responseData = Mapper.Map <ProductCategory, ProductCategory>(oldProductCategory);
                response = request.CreateResponse(HttpStatusCode.OK, responseData);
            }
            else
            {
                response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
            }
            return(response);
        }
 public IActionResult Delete(int id)
 {
     _productCategoryService.Delete(id);
     return(Json(new
     {
         status = true
     }));
 }
 public HttpResponseMessage Delete(HttpRequestMessage request, int id)
 {
     return(CreateHttpRespone(request, () =>
     {
         HttpResponseMessage respone = null;
         if (!ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             _TagService.Delete(id);
             _TagService.SaveChanges();
             respone = request.CreateResponse(HttpStatusCode.OK);
         }
         return respone;
     }));
 }
 public HttpResponseMessage Delete(HttpRequestMessage request, int id)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             _productCategoryService.Delete(id);
             _productCategoryService.Save();
             response = request.CreateResponse(HttpStatusCode.OK);
         }
         return response;
     }));
 }
        [HttpPost("delete")]//
        public async Task <IActionResult> Delete(ProductCategory productCategory)
        {
            var result = await _productCategoryService.Delete(productCategory);

            if (result.Success)
            {
                return(Ok(result.Message));
            }
            return(BadRequest(result.Message));
        }
Ejemplo n.º 20
0
 public HttpResponseMessage Delete(HttpRequestMessage request, int id)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (ModelState.IsValid)
         {
             var productCategory = _productCategoryService.Delete(id);
             _productCategoryService.Save();
             var productCategoryVM = Mapper.Map <ProductCategoryViewModel>(productCategory);
             response = request.CreateResponse(HttpStatusCode.Created, productCategoryVM);
         }
         else
         {
             response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
         return response;
     }));
 }
        public ActionResult <ProductCategory> Delete(int id)
        {
            ProductCategory deletedCountry = _productCategoryService.Delete(id);

            if (deletedCountry == null)
            {
                return(NotFound($"Did not find ProductCategory with ID: {id}"));
            }
            return(Ok(deletedCountry));
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> Delete(int id)
        {
            var result = await _productCategoryService.Delete(CurrentUser.TenantId, id);

            if (result.Code <= 0)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }
 public IActionResult DeleteProductCategory(int id)
 {
     if (id == 0)
     {
         return(BadRequest());
     }
     _productCategoryService.Delete(id);
     _productCategoryService.Save();
     return(new OkObjectResult(id));
 }
Ejemplo n.º 24
0
        public IHttpActionResult Delete(int id)
        {
            var result = _productCategoryService.Delete(id);

            if (result != null)
            {
                return(Ok(new { status = true }));
            }
            return(BadRequest());
        }
Ejemplo n.º 25
0
        public HttpResponseMessage Delete(HttpRequestMessage request, ProductCategoryViewModel productCategoryViewModel, int id)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var dbProductCategory = _productCategoryService.Delete(id);

                    try
                    {
                        _productCategoryService.Save();
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                              eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                  ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                        throw;
                    }


                    var responseData = Mapper.Map <ProductCategory, ProductCategoryViewModel>(dbProductCategory);
                    response = request.CreateResponse(HttpStatusCode.OK, responseData);
                }


                return response;
            }));
        }
Ejemplo n.º 26
0
        public IActionResult Delete(int id)
        {
            if (id == 0)
            {
                return(new BadRequestResult());
            }

            _productCategoryService.Delete(id);
            _unitOfWork.Commit();
            return(new OkObjectResult(id));
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> Delete([BindRequired] Guid id)
        {
            var result = await _productCategoryService.Delete(id);

            if (result.Message != ApiResultMessages.Ok)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Ejemplo n.º 28
0
        public HttpResponseMessage Delete(HttpRequestMessage request, int id)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var oldProduct = _productCategoryService.Delete(id);
                    _productCategoryService.SaveChanges();
                    var responseData = Mapper.Map <ProductCategory, ProductCategoryViewModel>(oldProduct);
                    response = request.CreateResponse(HttpStatusCode.OK, responseData);
                }

                return response;
            }));
        }
Ejemplo n.º 29
0
        public HttpResponseMessage Delete(HttpRequestMessage request, int productCategoryID)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var productCategory = _productCategoryService.Delete(productCategoryID);
                    _productCategoryService.Save();

                    //Sau khi luu xong chuyen doi lai wa du lieu cua view model de hien thi json
                    var responseData = Mapper.Map <ProductCategory, ProductCategoryViewModel>(productCategory);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }
                return response;
            }));
        }
 public bool DeleteEntity([FromQuery] string id)
 {
     try
     {
         var result = _IProductCategoryService.Delete(id);
         return(result);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, $"{0}:  public List<ProductCategory> ProductCategoriesList()", this.GetType().ToString());
     }
     return(false);
 }