public async Task <IActionResult> CreateCategory(IshopCategory ishopCategory, IFormFile FeaturedImage, IFormFile CatImage2) { if (ishopCategory.ParentId == null) { ishopCategory.ParentId = 0; } if (ModelState.IsValid) { var findCatCount = _context.IshopCategory.Where(a => a.CatName == ishopCategory.CatName).Count(); if (findCatCount > 0) { ViewBag.messageError = "Category Aleady Exists!!!!!"; ViewBag.cateorylist = ListCategories(); return(View(ishopCategory)); } ishopCategory.CatFeatureImg = await HelperFtn.UploadImageCategory(FeaturedImage); ishopCategory.CatPic2 = await HelperFtn.UploadImageCategory(CatImage2); ishopCategory.AddedBy = HttpContext.Session.GetString("SessionUsername"); ishopCategory.AddedDate = DateTime.Now; _context.Add(ishopCategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(IndexCategory))); } ViewBag.cateorylist = ListCategories(); return(View(ishopCategory)); }
public async Task <IActionResult> DeleteConfirmedCategory(int id) { var ishopCategory = await _context.IshopCategory.FindAsync(id); _context.IshopCategory.Remove(ishopCategory); bool x = HelperFtn.DeleteCategoryPicFromFolder(ishopCategory.CatFeatureImg); bool y = HelperFtn.DeleteCategoryPicFromFolder(ishopCategory.CatPic2); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(IndexCategory))); }
public async Task <IActionResult> CreateProduct(IshopProduct ishopProduct, IFormFile FeaturedImage, IFormFile ProPic2, IFormFile[] ProdGallery) { if (ModelState.IsValid) { var findCatCount = _context.IshopProduct.Where(a => a.ProdName == ishopProduct.ProdName).Count(); if (findCatCount > 0) { ViewBag.messageError = "Product Aleady Exists!!!!!"; ViewBag.cateorylist = ListSubCategories(); return(View(ishopProduct)); } ishopProduct.ProdFeatureImg = await HelperFtn.UploadProductImage(FeaturedImage); ishopProduct.ProPic2 = await HelperFtn.UploadProductImage(ProPic2); var prodGallery = await HelperFtn.UploadGalleryProductImages(ProdGallery, HttpContext.Session.GetString("SessionUsername")); ishopProduct.AddedBy = HttpContext.Session.GetString("SessionUsername"); ishopProduct.AddedDate = DateTime.Now; _context.Add(ishopProduct); await _context.SaveChangesAsync(); if (prodGallery.Count() > 0) { foreach (var item in prodGallery) { item.ProdId = ishopProduct.Id; } _context.AddRange(prodGallery); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(IndexProduct))); } ViewBag.cateorylist = ListSubCategories(); return(View(ishopProduct)); }