示例#1
0
        public ActionResult DeleteCategory(int id)
        {
            try
            {
                var category = _categoryServices.GetCategoryById(id);

                if (category != null)
                {
                    if (category.Products.Count > 0)
                    {
                        return(BadRequest($"Para eliminar esta Categoría no deben de haber Productos en ella y esta categoría tiene {category.Products.Count} Producto(s)."));
                    }

                    var result = _categoryServices.DeleteCategory(category);

                    if (result)
                    {
                        return(Json("Categoría eliminado con exito!"));
                    }

                    return(StatusCode(StatusCodes.Status500InternalServerError, "Algo salio mal, contacta el Administrador"));
                }

                return(BadRequest("La Categoría que tratas de eliminar no existe"));
            }
            catch (Exception ex)
            {
                //TODO: Log the exception
                return(StatusCode(StatusCodes.Status500InternalServerError, "Algo salio mal, contacta el Administrador"));
            }
        }
示例#2
0
        public IActionResult DeleteCategory([FromBody] DeleteCategoryRequest request)
        {
            try
            {
                if (request == null)
                {
                    return(BadRequest(new ErrorViewModel
                    {
                        ErrorCode = "400",
                        ErrorMessage = "Please provide input information correctly."
                    }));
                }

                if (request.CategoryId <= 0)
                {
                    return(BadRequest(new ErrorViewModel
                    {
                        ErrorCode = "400",
                        ErrorMessage = "Category not found"
                    }));
                }

                var category = _categoryRepository.FindById(request.CategoryId);
                if (category == null)
                {
                    return(BadRequest(new ErrorViewModel
                    {
                        ErrorCode = "400",
                        ErrorMessage = "Category not found"
                    }));
                }
                if (!category.Editable)
                {
                    return(BadRequest(new ErrorViewModel
                    {
                        ErrorCode = "400",
                        ErrorMessage = "Can not change this category"
                    }));
                }

                var response = _categoryServices.DeleteCategory(category);
                if (response != "OK")
                {
                    return(BadRequest(new ErrorViewModel
                    {
                        ErrorCode = "400",
                        ErrorMessage = "Can not execute. Plz contact admin"
                    }));
                }
                return(Ok(response));
            }
            catch (Exception e)
            {
                return(BadRequest(new ErrorViewModel
                {
                    ErrorCode = "400",
                    ErrorMessage = $"Server Error: {e.Message}"
                }));
            }
        }
        public async Task <IActionResult> DeleteConfirmed(int id,
                                                          [FromServices] IPostCategoryServices postCategoryServices)
        {
            var category = await categoryServices.GetCategory(id);

            await categoryServices.DeleteCategory(category);

            return(RedirectToAction("Index"));
        }
示例#4
0
 public async Task <IActionResult> Delete(int?id)
 {
     HttpContext.Session.GetString("fullname");
     if (await _categoryServices.DeleteCategory(id))
     {
         TempData["succcessMessage"] = _resourcesServices.GetLocalizedHtmlString("msg_DeleteCategorySuccess").ToString();
         return(RedirectToAction("Index"));
     }
     ViewData["errorMessage"] = _resourcesServices.GetLocalizedHtmlString("msg_EditCategoryError");
     return(View("Index"));
 }
 public IActionResult DeleteRole(int id)
 {
     try
     {
         _categoryServices.DeleteCategory(id);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(new { message = ex.Message }));
     }
 }
示例#6
0
        public async Task <JsonResult> DeleteCategory([FromBody] CategoryEntity category)
        {
            try
            {
                await categoryServices.DeleteCategory(category);

                var result = 0;
                return(Json(result));
            }
            catch (Exception ex)
            {
                await errorServices.ErrorNotification(ex, HttpContext.User.Identity.Name, "", "");

                return(Json(ex));
            }
        }
 public HttpResponseMessage DeleteCategory(int Category_Id, int StoreId, int LoggedInUserId)
 {
     try
     {
         var result = _categoryServices.DeleteCategory(Category_Id, StoreId, LoggedInUserId);
         if (result > 0)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, result));
         }
         return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Something wrong! Please try again later."));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public async Task <IActionResult> DeleteCategory(int id)
        {
            try
            {
                var categoryToUpdate = await _categoryServices.DeleteCategory(id);

                if (categoryToUpdate != null)
                {
                    return(Ok("Xóa thành công"));
                }
                return(BadRequest("Failed to delete category"));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(new { Message = ex.Message.ToString() }));
            }
        }
示例#9
0
 public ActionResult Delete(string categoryId)
 {
     _categoryService.DeleteCategory(categoryId);
     return(RedirectToAction("Index"));
 }
示例#10
0
        public async Task <BaseResponse <bool> > deleteCategory(int id)
        {
            bool result = await _categoryServices.DeleteCategory(id);

            return(new BaseResponse <bool>(result));
        }
示例#11
0
 public IActionResult DeleteCategory(Category category)
 {
     _categorysServices.DeleteCategory(category);
     return(Ok());
 }