Example #1
0
        public IActionResult OnPost(int itemId)
        {
            var item = itemData.Delete(itemId);

            itemData.Commit();

            if (item == null)
            {
                return(RedirectToPage("./NotFound"));
            }

            TempData["Message"] = $"{item.Name} deleted";
            return(RedirectToPage("./List"));
        }
        public ActionResult DeleteData(int ItemId, int id)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var categoryId   = _db.Items.Where(x => x.ItemId == ItemId).Select(x => x.ItemCategoryId).SingleOrDefault();
                    var itemName     = _db.Items.Where(x => x.ItemId == ItemId).Select(x => x.ItemName).SingleOrDefault();
                    var completepath = _hostingEnvironment.WebRootPath + "\\itemImages\\" + categoryId + "\\" + id + "\\" + itemName + "\\";
                    if (System.IO.File.Exists(completepath))
                    {
                        System.IO.File.Delete(completepath);
                    }

                    _itemData.Delete(ItemId);
                    return(RedirectToAction("Index", "Shop", new { id = id }));
                }
                catch
                {
                    throw;
                }
            }
            return(View());
        }