public ActionResult Create(TblManufactures tblmanu, FormCollection collection, int[] MutilMenu) { tblmanu.Tag = StringClass.NameToTag(tblmanu.Name); db.TblManufactures.Add(tblmanu); db.SaveChanges(); var ListManu = db.TblManufactures.OrderByDescending(p => p.Id).Take(1).ToList(); int idManu = int.Parse(ListManu[0].Id.ToString()); if (MutilMenu != null) { foreach (var idCate in MutilMenu) { TblConnectManuProduct TblManufactures = new TblConnectManuProduct(); TblManufactures.IdCate = idCate; TblManufactures.IdManu = idManu; db.TblConnectManuProduct.Add(TblManufactures); db.SaveChanges(); } } var ListManufac = db.TblManufactures.OrderByDescending(p => p.Id).Take(1).ToList(); clsSitemap.CreateSitemap("hang-san-xuat/" + ListManufac[0].Tag, ListManufac[0].Id.ToString(), "Manufactures"); if (collection["btnSave"] != null) { Session["Thongbao"] = "<div class=\"alert alert-info alert1\">Bạn đã thêm thành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>"; return(Redirect("/Manufacturesad/Index")); } if (collection["btnSaveCreate"] != null) { Session["Thongbao"] = "<div class=\"alert alert-info\">Bạn đã thêm thành công, mời bạn thêm mới !<button class=\"close\" data-dismiss=\"alert\">×</button></div>"; return(Redirect("/Manufacturesad/Create")); } return(Redirect("Index")); }
public ActionResult Edit(TblManufactures TblManufacture, int id, FormCollection collection, int[] MutilMenu) { if (ModelState.IsValid) { TblManufacture.Tag = StringClass.NameToTag(TblManufacture.Name); db.Entry(TblManufacture).State = EntityState.Modified; db.SaveChanges(); var ListManu = db.TblConnectManuProduct.Where(p => p.IdManu == id).ToList(); for (int i = 0; i < ListManu.Count; i++) { db.TblConnectManuProduct.Remove(ListManu[i]); db.SaveChanges(); } if (MutilMenu != null) { foreach (var idCates in MutilMenu) { TblConnectManuProduct TblManufactures = new TblConnectManuProduct(); TblManufactures.IdCate = idCates; TblManufactures.IdManu = id; db.TblConnectManuProduct.Add(TblManufactures); db.SaveChanges(); } } clsSitemap.UpdateSitemap("hang-san-xuat/" + TblManufacture.Tag, id.ToString(), "Manufactures"); #region [Updatehistory] #endregion if (collection["btnSave"] != null) { Session["Thongbao"] = "<div class=\"alert alert-info alert1\">Bạn đã sửa thành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>"; return(Redirect("/Manufacturesad/Index")); } if (collection["btnSaveCreate"] != null) { Session["Thongbao"] = "<div class=\"alert alert-info\">Bạn đã thêm thành công, mời bạn thêm mới !<button class=\"close\" data-dismiss=\"alert\">×</button></div>"; return(Redirect("/Manufacturesad/Create")); } } return(View(TblManufacture)); }