public ActionResult Edit(Advertisement ad) { if (Session["UserId"] == null) { return Redirect("/admin/login"); } AdvertisementService advertisementService = new AdvertisementService(); if (ad != null && ad.Id > 0 && !string.IsNullOrEmpty(ad.Name)) { if (string.IsNullOrEmpty(ad.AdLink)) { ad.AdLink = string.Empty; } advertisementService.EditAdvertisement(ad); WitBird.Sex.Web.Cache.UpdateAdvertisements();//更新缓存 } return Redirect("/admin/advertisement/"); }
/// <summary> /// 更新广告列表 /// </summary> public string EditAdvertisement(Advertisement advertisement) { string result = "更新失败"; var conn = DBRepository.GetSqlConnection(); try { conn.Open(); if (advertisement != null) { if (advertisement.Id > 0 && !string.IsNullOrEmpty(advertisement.Name)) { if (DBRepository.Update<Advertisement>(advertisement, "Id", conn)) { result = "success"; } } } else { result = "friendlyLink对象为空"; LogService.Log("AdvertisementService.EditAdvertisement", "advertisement对象为空"); } } catch (Exception e) { result = "程序出现异常,详情见日志"; LogService.Log("更新广告列表", e.ToString()); } finally { conn.Close(); } return result; }
public static Advertisement GetAdvertisement(int id) { Advertisement ad = new Advertisement(); if (advertisements == null) { UpdateAdvertisements(); } if (advertisements != null && advertisements.Count > 0) { foreach (var item in advertisements) { if (item.Id == id) { ad = item; break; } } } return ad; }