public ActionResult DelById(int id, int Page = 1) { string str = ""; string adname = DNTRequest.GetString("adname"); hx_td_Ad pDel = new hx_td_Ad() { Adid = id }; ef.hx_td_Ad.Attach(pDel); ef.hx_td_Ad.Remove(pDel); int i = ef.SaveChanges(); if (i > 0) { str = StringAlert.Alert("广告删除成功!", "/admin/Ad/Index?page=" + Page.ToString() + "&adname=" + adname); CacheRemove.RemoveWebAdtype(); //请除广告位缓存 } else { str = StringAlert.Alert("广告删除失败!", "/admin/Ad/Index?page=" + Page.ToString() + "&adname=" + adname); } return(Content(str, "text/html")); }
public ActionResult AddAdpost(hx_td_Ad p) { p = (hx_td_Ad)Utils.ValidateModelClass(p); p.AdPath = p.AdPath.Replace("//", "/"); p.Adcreatetime = DateTime.Now; ef.hx_td_Ad.Add(p); ef.SaveChanges(); CacheRemove.RemoveWebAdtype(); //请除广告位缓存 return(RedirectToAction("index", "Ad")); }
public ActionResult EditAdpost(hx_td_Ad p) { string str = ""; string[] proNames; proNames = new string[] { "AdName", "AdTypeId", "AdPath", "AdLink", "AdState" }; p = (hx_td_Ad)Utils.ValidateModelClass(p); p.AdPath = p.AdPath.Replace("//", "/"); DbEntityEntry entry = ef.Entry <hx_td_Ad>(p); entry.State = EntityState.Unchanged; foreach (string ProName in proNames) { entry.Property(ProName).IsModified = true; } int i = ef.SaveChanges(); if (i > 0) { str = StringAlert.Alert("广告修改成功!", "/admin/Ad/Index"); } else { str = StringAlert.Alert("广告修改失败!", "/admin/Ad/EditAd/" + p.Adid + "/"); } CacheRemove.RemoveWebAdtype(); //请除广告位缓存 return(Content(str, "text/html")); }