public ActionResult Product_GroupAddOrEdit(int id = 0) { if (id == 0) { HotProduct_Group Product_Group = new HotProduct_Group(); return(View(Product_Group)); } else { MasterContext dbContext = new MasterContext(); var Product_Group = dbContext.Product_Gruop.First(q => q.Id == id); return(View(Product_Group)); } }
public ActionResult Product_GroupAddOrEdit(HotProduct_Group model) { try { //if (model.ImageFile.ContentLength > 0) //{ // string _filename = Path.GetFileName(model.ImageFile.FileName); // string _path = Path.Combine(Server.MapPath("/assets/Uploads/"), _filename); // model.ImageFile.SaveAs(_path); // model.Image = _filename; //} if (model.Id == 0) { MasterContext Product_GroupAdd = new MasterContext(); HotProduct_Group hotProduct_group = new HotProduct_Group() { Code = model.Code, Name = model.Name, Info = model.Info, }; Product_GroupAdd.Product_Gruop.Add(hotProduct_group); Product_GroupAdd.SaveChanges(); ViewBag.message = "Yeni Haber Eklendi"; ModelState.Clear(); return(Redirect("/Product/Product_Group_List")); } else { MasterContext Product_Group = new MasterContext(); Product_Group.Entry(model).State = System.Data.Entity.EntityState.Modified; Product_Group.SaveChanges(); return(Redirect("/Product/Product_Group_List")); } } catch (Exception) { throw; } }