public ActionResult ProductMaster(HttpPostedFileBase ProductImage, Int64 ProductID = 0, string ProductName = null, string ProductDetail = null) { string userid = User.Identity.GetUserId(); string Status = ""; string productimg = null; productimg = "ProductMaster/" + ProductImage.FileName; Models.ProductMaster pm = new Models.ProductMaster(); var Exist = db.ProductMaster.Where(s => s.ProductID == ProductID).FirstOrDefault(); if (Exist == null) { pm.CreatedBy = userid; pm.CreatedDate = DateTime.Now; pm.ProductImage = productimg; pm.ProductName = ProductName; pm.ProductDetail = ProductDetail; db.ProductMaster.Add(pm); int i = db.SaveChanges(); Status = "Succeeded"; string path = Server.MapPath("~/ProductMaster/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } ProductImage.SaveAs(path + ProductImage.FileName); } else { Exist.CreatedBy = userid; Exist.CreatedDate = DateTime.Now; Exist.ProductImage = productimg; Exist.ProductName = ProductName; Exist.ProductDetail = ProductDetail; db.SaveChanges(); Status = "Succeeded"; string path = Server.MapPath("~/ProductMaster/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } ProductImage.SaveAs(path + ProductImage.FileName); } TempData["Example"] = Status; return(RedirectToAction("ProductMaster", "Admin", new { area = "Admin" })); }
public ActionResult ProductMaster(Int64 ProductID = 0) { Models.ProductMaster pm = new Models.ProductMaster(); if (ProductID > 0) { var exist = db.ProductMaster.Where(s => s.ProductID == ProductID).FirstOrDefault(); pm.ProductName = exist.ProductName; pm.ProductID = ProductID; pm.ProductImage = exist.ProductImage; ViewBag.ProductID = ProductID; } ViewData["Product"] = db.ProductMaster.ToList(); return(View(pm)); }