public IActionResult OnPost(ShopItem shopItem) { if (ModelState.IsValid) { if (Photo != null) { if (ShopItem.PhotoPath != null) { string filePath = Path.Combine(webHostEnvironment.WebRootPath, "images", shopItem.PhotoPath); System.IO.File.Delete(filePath); } shopItem.PhotoPath = UploadingFilePhoto(); } if (ShopItem.Id == 0) { ShopItem = shopdata.Create(shopItem); TempData["TempMessage"] = "You just created Shopping Product!"; } else { ShopItem = shopdata.Update(shopItem); TempData["TempMessage"] = "You just updated Shopping Product!"; } shopdata.Commit(); return(RedirectToPage("./Index", new { id = shopItem.Id })); } ShopItemType = htmlHelper.GetEnumSelectList <ShopItemType>(); return(Page()); }
public IActionResult OnPost(int?id) { if (id.Value == 0) { return(RedirectToPage("NotFound")); } ShopItem = shopItemData.GetShopItemById(id.Value); if (ShopItem != null) { shopItemData.Delete(ShopItem.Id); } else { return(RedirectToPage("NotFound")); } shopItemData.Commit(); return(RedirectToPage("./Index")); }