public ActionResult AddProduct(Product product, HttpPostedFileBase file, IEnumerable <HttpPostedFileBase> files) { ViewBag.CategoryId = new SelectList(dbContext.categories, "Id", "Name", product.Id); if (ModelState.IsValid) { if (file != null) { file.SaveAs(HttpContext.Server.MapPath("~/Image/") + file.FileName); product.ImageName = file.FileName; } if (files != null) { var gallary = new List <GallaryImage>(); foreach (var singleImage in files) { singleImage.SaveAs(HttpContext.Server.MapPath("~/Image/Gallery/" + singleImage.FileName)); var img = new GallaryImage { ProductId = product.Id }; img.ImageName = singleImage.FileName; gallary.Add(img); } product.GallaryImages = gallary; } service.AddProduct(product); TempData["sm"] = "Added Product Successfully"; return(RedirectToAction("AddProduct")); } else { return(View(product)); } }
public async Task <IActionResult> DeleteGallaryImage([Bind("Id")] GallaryImage gallaryImage) { return(View("EditPage")); }