コード例 #1
0
        public ActionResult delete(int id)
        {
            try
            {
                string folder = Server.MapPath("~/assets/uploads/products/") + id;

                string  objectValue = "";
                Product product     = productService.GetByPrimaryKey(id);
                if (product != null)
                {
                    objectValue = product.ProductName;
                    // xóa tất cả ảnh trong folder
                    ImageService.DeleteFolder(folder);

                    imageService.DeleteByProductID(id);

                    variantService.DeleteByProductID(id);

                    optionService.DeleteByProductID(id);

                    collectionProductService.DeleteByProductID(id);

                    if (productService.DeleteByPrimary(id))
                    {
                        LogService.WriteLog2DB(accountService.GetUserId(User.Identity.GetUserName()), (int)Common.ActionID.Delete, id, SDateTime.GetYYYYMMddHmmSSNow(), General.GetIPAddress(), TableNameID, product.ProductName);
                        return(RedirectToAction("", "products", new { strMessage = "delete1" }));
                    }
                }
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
            }
            return(RedirectToAction("detail", "products", new { id = id, strMessage = "delete0" }));
        }