public ActionResult Index(int page = 1, int pageSize = 10) { var dao = new AdDao(); var model = dao.ListAd(page, pageSize); return(View(model)); }
public JsonResult ChangeStatus(int id) { var result = new AdDao().ChangeStatus(id); return(Json(new { status = result })); }
// GET: Home public ActionResult Index() { var MovieDao = new MovieDao(); ViewBag.ListMovieNew = MovieDao.ListMovieNew(12); ViewBag.ListMovieTop = MovieDao.ListMovieTop(12); ViewBag.ListMoviePo = MovieDao.ListMoviePo(6); ViewBag.Slides = new SlideDao().ListAllSlide(5); var model = new AdDao().GetContentAd(); return(View(model)); }
private static void DoAdjson(List <Ad> listAD, JObject jObjectData) { if (jObjectData.ContainsKey("ad")) //处理ad { JArray jObjectAd = (JArray)jObjectData["ad"]; foreach (JToken jToken in jObjectAd.Children()) { Ad ad = new Ad(); ad.advertisement_id = long.Parse(jToken["advertisement_id"].ToString()); ad.advertiser_name = jToken["advertiser_name"].ToString(); ad.date_modified = DateTime.Parse(jToken["date_modified"].ToString()); ad.display_time = int.Parse(jToken["display_time"].ToString()); ad.image_url = jToken["image_url"].ToString(); ad.sub_image_url = jToken["sub_image_url"].ToString(); ad.Title = jToken["title"].ToString(); ad.puton_time = DateTime.Parse(jToken["puton_time"].ToString()); ad.putoff_time = DateTime.Parse(jToken["putoff_time"].ToString()); ad.show_type = int.Parse(jToken["show_type"].ToString()); ad.img_path = Config.adImgRoot + "\\" + Ad.GetImgName(ad.image_url); DateTime dt = DateTime.Now; if (ad.puton_time <= dt && dt <= ad.putoff_time) //在上线时间范围内 { Ad oldad = AdDao.GetAdById(ad.advertisement_id); if (oldad == null) //数据库中不存在 { bool url1 = true, url2 = true; url1 = HttpUtil.DownloadImg(ad.image_url, ad.img_path); if ((ad.show_type == 2 || ad.show_type == 3) && String.IsNullOrEmpty(ad.sub_image_url) == false) { ad.sub_img_path = Config.adImgRoot + "\\" + Ad.GetImgName(ad.sub_image_url); url2 = HttpUtil.DownloadImg(ad.sub_image_url, ad.sub_img_path); } else { ad.sub_img_path = ""; } if (url1 && url2) { AdDao.InsertAd(ad); listAD.Add(ad); } } else //数据库中存在 { if (oldad.date_modified != ad.date_modified)//需要更新 { FileInfo fileInfo = new FileInfo(ad.img_path); //if (fileInfo.Directory.Exists == false) { // fileInfo.Directory.Create(); //} bool url1 = true, url2 = true; if (fileInfo.Exists == false || fileInfo.Length <= 0) { url1 = HttpUtil.DownloadImg(ad.image_url, ad.img_path); } if ((ad.show_type == 2 || ad.show_type == 3) && String.IsNullOrEmpty(ad.sub_image_url) == false) { ad.sub_img_path = Config.adImgRoot + "\\" + Ad.GetImgName(ad.sub_image_url); url2 = HttpUtil.DownloadImg(ad.sub_image_url, ad.sub_img_path); } else { ad.sub_img_path = ""; } if (url1 && url2) { ad.id = oldad.id; //ad.sub_image_url = oldad.sub_image_url; AdDao.UpdateAd(ad); listAD.Add(ad); } } } } } MainWindow.listAd = AdDao.GetAds(); } }