public ActionResult CreateProductType(ProductType createdProductType, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null && file.ContentLength > 0) { string path = Path.Combine(HttpContext.Server.MapPath("~/imageUploads/TypeImg"), file.FileName); file.SaveAs(path); createdProductType.Image = file.FileName; bool successfullyCreatedProductType = DAL.CreateProductType(createdProductType); if (successfullyCreatedProductType) { return(RedirectToAction("FilterProductTypeByCategory", new { id = createdProductType.CategoryID })); } else { return(View(createdProductType)); } } else { ViewBag.Message = "You have not specified a file yet ..."; } } ViewBag.CategoryID = new SelectList(context.Category, "ID", "CategoryName"); return(View(createdProductType)); }
public ActionResult CreateProductType(ProductType createdProductType, IFormFile file) { if (ModelState.IsValid) { if (file != null && file.Length > 0) { string path = Path.Combine(env.WebRootPath + "\\imageUploads\\TypeImg", file.FileName); file.CopyTo(new FileStream(path, FileMode.Create)); createdProductType.Image = file.FileName; bool successfullyCreatedProductType = DAL.CreateProductType(createdProductType); if (successfullyCreatedProductType) { return(RedirectToAction("FilterProductTypeByCategory", new { id = createdProductType.CategoryID })); } else { return(View(createdProductType)); } } else { ViewBag.Message = "You have not specified a file yet ..."; } } ViewBag.CategoryID = new SelectList(context.Category, "ID", "CategoryName"); return(View(createdProductType)); }