public ActionResult Index() { newsRepository repository = new newsRepository(); //Get the 10 latest entries from the database var blogEntries = repository.getLatestBlogs(); //and return the view. return(View(blogEntries)); }
protected void Page_Load(object sender, EventArgs e) { Response.Cache.SetCacheability(HttpCacheability.NoCache); int nid = Convert.ToInt32(Request["nid"]); newsRepository nr = new newsRepository(db); var n1 = nr.get(nid); if (n1 != null) { n1.ding += 1; if (User.Identity.IsAuthenticated) { dings ding = new dings(); try { ding.id = db.dings.Max(d => d.id) + 1; } catch { ding.id = 1; } ding.nid = n1.id; ding.uid = Convert.ToInt32(User.Identity.Name); db.dings.InsertOnSubmit(ding); } db.SubmitChanges(); Response.Write(n1.ding); tool.WriteCookie("ip" + n1.id, tool.GetIP() + "|" + n1.id, 24); } }
public ActionResult Edit(int?id) { if (id != null) { newsRepository repository = new newsRepository(); var model = repository.get_blog_by_id(id); //Get the entry by it's ID //And return the view. return(View(model)); } return(null); }
public ActionResult Create(FormCollection formData) //Try to add a entry, if any of it's forms is empty { //then catch the exception and return a CreateFail view. try { Blog b = new Blog(); UpdateModel(b); newsRepository repository = new newsRepository(); repository.add_blog(b); return(RedirectToAction("Index")); } catch (SqlException) { return(View("CreateFail")); } }
public ActionResult Edit(int id, FormCollection formData) { newsRepository repository = new newsRepository(); Blog b = repository.get_blog_by_id(id); //Get the entry by it's ID if (b != null) //Check if it exists, if it does { //try to edit it, if a form is empty try //then return a view which includes a error message. { UpdateModel(b); repository.edit_blog(b); return(RedirectToAction("Index")); } catch (SqlException) { return(View("EditFail")); } } else //If the entry does not exist, then return a NotFound view { return(View("NotFound")); } }
protected void Page_Load(object sender, EventArgs e) { tou = db.news.OrderByDescending(d => d.ndate).First(); tuij = db.news.OrderByDescending(d => d.id).Skip(1).Take(5).ToList(); zuix = db.news.OrderByDescending(d => d.ndate).Skip(0).Take(10).ToList(); tags = db.tag.ToList(); pings = db.ping.Take(10).ToList(); hots = (from d in db.news where Convert.ToDateTime(d.ndate).AddDays(7) > DateTime.Now select d).Take(10).ToList(); int curpage = 1; if (!tool.StrIsNullOrEmpty(Request.QueryString["page"])) { curpage = Convert.ToInt32(Request.QueryString["page"]); } cid = 0; newsRepository nr = new newsRepository(db); var list = nr.List().AsQueryable(); if (!tool.StrIsNullOrEmpty(Request.QueryString["id"])) { cid = Convert.ToInt32(Request.QueryString["id"]); var c1 = db.cls.First(d => d.id == cid); var s = db.she.First(); HtmlMeta key = new HtmlMeta(); key.Name = "Keywords"; key.Content = s.Keywords + "|" + s.Keywords; Header.Controls.Add(key); HtmlMeta desc = new HtmlMeta(); desc.Name = "Description"; desc.Content = c1.description + "|" + s.Description; Header.Controls.Add(desc); Header.Title = c1.name + "|" + s.title; list = list.Where(d => d.cls.jb.Contains(c1.jb)); clss = from d in db.cls where d.jb.Substring(0, c1.jb.Length) == c1.jb && d.jb != c1.jb select d; var cls_s = c1.jb.Split('|'); dh = new List <cls>(); foreach (var i in cls_s) { try { var d1 = db.cls.First(d => d.id == Convert.ToInt32(i)); dh.Add(d1); } catch { } } } int pagesize = 10; int day = 0; if (!tool.StrIsNullOrEmpty(Request.QueryString["viewday"])) { day = Convert.ToInt32(Request.QueryString["viewday"]); } if (day != 0) { list = list.Where(d => DateTime.Now.AddDays(-day) <= Convert.ToDateTime(d.ndate)); } art = list.OrderByDescending(d => d.ndate).Skip((curpage - 1)).Take(pagesize); int pagecount = list.Count() % pagesize == 0 ? list.Count() / pagesize : list.Count() / pagesize + 1; pagestr = tool.GetPageNumbers(curpage, pagecount, Request.RawUrl.ToString(), 5, ""); }
protected void Button1_Click(object sender, EventArgs e) { if (this.IsValid) { caiji cj = new caiji(); string str = cj.GetHtmlSource(listurl.Text); ArrayList urllist = new ArrayList(); str = cj.webCode(str, split(listlink.Text)[0], split(listlink.Text)[1]); urllist = cj.webCodeReturnList(str, split(linkurl.Text)[0], split(linkurl.Text)[1]); foreach (string item in urllist) { string strcont = cj.GetHtmlSource(item); newsRepository nr = new newsRepository(db); news n = new news(); try { n.id = db.news.Max(d => d.id) + 1; } catch { n.id = 1; } n.title = tool.RemoveHtml(cj.webCode(strcont, split(t_title.Text)[0], split(t_title.Text)[1])); if (!tool.StrIsNullOrEmpty(n.title)) { if (tool.StrIsNullOrEmpty(t_author.Text)) { n.author = ""; } else { n.author = cj.webCode(strcont, split(t_author.Text)[0], split(t_author.Text)[1]); } if (tool.StrIsNullOrEmpty(t_laiy.Text)) { n.laiy = ""; } else { n.laiy = tool.RemoveHtml(cj.webCode(strcont, split(t_laiy.Text)[0], split(t_laiy.Text)[1])); } if (tool.StrIsNullOrEmpty(t_cont.Text)) { n.cont = ""; } else { n.cont = tool.GetTextFromHTML(cj.webCode(strcont, split(t_cont.Text)[0], split(t_cont.Text)[1])); } if (!tool.StrIsNullOrEmpty(n.cont)) { n.pic = ""; n.hit = 0; n.ding = 0; n.ping = 0; n.tags = ""; n.uid = Convert.ToInt32(User.Identity.Name); n.cid = Convert.ToInt32(drop2.SelectedValue); n.ndate = DateTime.Now; db.news.InsertOnSubmit(n); db.SubmitChanges(); } } } tj.Text = "采集成功"; } }
protected void Page_Load(object sender, EventArgs e) { var s = db.she.First(); HtmlMeta key = new HtmlMeta(); key.Name = "Keywords"; key.Content = s.Keywords; Header.Controls.Add(key); HtmlMeta desc = new HtmlMeta(); desc.Name = "Description"; desc.Content = s.Description; Header.Controls.Add(desc); Header.Title = s.title; newsRepository nr = new newsRepository(db); Session["code"] = Session.SessionID; tou = nr.get().First(); tuij = nr.List().OrderByDescending(d => d.hit).Skip(1).Take(5).ToList(); zuix = nr.get().Skip(0).Take(10).ToList(); tagRepository tr = new tagRepository(db); tags = tr.get(); pingRepository pr = new pingRepository(db); pings = pr.get().Take(10); hots = nr.get().Where(d => Convert.ToDateTime(d.ndate).AddDays(7) > DateTime.Now).Take(10); userRepository ur = new userRepository(db); users = ur.get().Take(12); int curpage = 1; if (!tool.StrIsNullOrEmpty(Request.QueryString["page"])) { curpage = Convert.ToInt32(Request.QueryString["page"]); } int pagesize = 10; var list = nr.List().AsQueryable(); if (!tool.StrIsNullOrEmpty(Request.QueryString["tag"])) { list = list.Where(d => d.tags.Contains(Request.QueryString["tag"].ToString())); } int day = 0; if (!tool.StrIsNullOrEmpty(Request.QueryString["viewday"])) { day = Convert.ToInt32(Request.QueryString["viewday"]); } if (day != 0) { list = list.Where(d => DateTime.Now.AddDays(-day) <= Convert.ToDateTime(d.ndate)); } art = list.OrderByDescending(d => d.ndate).Skip((curpage - 1) * pagesize).Take(pagesize); int pagecount = list.Count() % pagesize == 0 ? list.Count() / pagesize : list.Count() / pagesize + 1; pagestr = tool.GetPageNumbers(curpage, pagecount, Request.RawUrl.ToString(), 5, ""); if (!tool.StrIsNullOrEmpty(Request["verifyhash1"]) && !tool.StrIsNullOrEmpty(Request["username"]) && Session["code1"] != null) { if (Request["verifyhash1"].ToString() == Session["code1"].ToString()) { var u1 = db.user.Where(d => d.name == Convert.ToString(Request["username"].Trim()) && d.pwd == Convert.ToString(Request["password"].Trim())); if (u1.Count() > 0) { var u = u1.First(); if (Convert.ToInt32(Request["persistent"]) == 1) { System.Web.Security.FormsAuthentication.RedirectFromLoginPage(u.id.ToString(), true); } else { System.Web.Security.FormsAuthentication.RedirectFromLoginPage(u.id.ToString(), false); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "dd", "alert('密码错误或用户名错误')", true); } } } Session["code1"] = Session.SessionID; // 图片幻灯 var hd = (from d in db.news where d.pic != null && d.pic.Trim() != "" orderby d.ndate descending select d).Take(4); hd_img = ""; hd_link = ""; hd_title = ""; foreach (var item in hd) { hd_img += item.pic + "|"; hd_link += "show.aspx?id=" + item.id + "|"; hd_title += item.title + "|"; } hd_img = tool.sub(hd_img, hd_img.Length - 1); hd_link = tool.sub(hd_link, hd_link.Length - 1); hd_title = tool.sub(hd_title, hd_title.Length - 1); }