public ActionResult postcomment() { var id = Session["userID"]; string comment = Request["comment"]; var a = Convert.ToInt32(Request.Cookies["id"].Value); var b = Convert.ToInt32(Request.Cookies["b_id"].Value); var name = Session["userName"].ToString(); string logo = Session["userLogo"].ToString(); POSTCOMMENT comm = new POSTCOMMENT(); comm.PC_COMMENTERID = (int)id; comm.PC_COMMENTER = name; comm.PC_PICTURE = logo; comm.PC_POSTID = a; comm.PC_BOARDID = (int)b; comm.PC_CONTENTS = comment; comm.PC_DATETIME = DateTime.Parse(DateTime.Now.ToString()); comm.PC_BAD = 0; comm.PC_GOOD = 0; conn.POSTCOMMENT.Add(comm); conn.SaveChanges(); return(Content("<script>history.go(-1)</script>")); }
public ActionResult notice(aWrite model) { string aName = Session["adminName"].ToString(); int aID = (int)Session["adminID"]; string ss; string pa = "~/unload/Notice/"; ss = "N" + System.DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + Path.GetExtension(Request.Files["file"].FileName); var pp = Path.GetExtension(Request.Files["file"].FileName); Request.Files["file"].SaveAs(System.Web.HttpContext.Current.Server.MapPath(pa) + ss); if (ModelState.IsValid) { NOTICE nt = new NOTICE(); nt.N_CLICK = 0; nt.N_CONTENTS = model.N_CONTENTS; nt.N_DATETIME = DateTime.Parse(DateTime.Now.ToString()); nt.N_PICTURE = pp == "" ? "" : ss; nt.N_POSTER = aName; nt.N_POSTERID = aID; nt.N_Title = model.N_Title; conn.NOTICE.Add(nt); conn.SaveChanges(); return(Content("<script>alert('公告发布成功'); history.go(-1)</script>")); } return(View()); }
public ActionResult userManage(string name, string id) { var model = conn.Users.OrderByDescending(x => x.RegisterDate).ToList(); if (!string.IsNullOrEmpty(name)) { model = model.Where(w => w.Accounts.Contains(name)).ToList(); } if (!string.IsNullOrEmpty(id)) { int uid = System.Convert.ToInt32(id); Users post = conn.Users.Find(uid); conn.Users.Remove(post); conn.SaveChanges(); } return(PartialView("~/Areas/Admin/Views/AccountManage/userManage.cshtml", model)); }
public ActionResult Index(RegisterModel model) { var id = Session["userAccounts"]; Users list = conn.Users.FirstOrDefault(a => a.Accounts == id); string ss; ss = "P" + System.DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + Path.GetExtension(Request.Files["file"].FileName); Users user = (from a in conn.Users where a.Accounts == id select a).Single(); user.Nickname = model.Nickname; user.UserLogo = img(ss); conn.Entry <Users>(user).State = System.Data.EntityState.Modified; conn.SaveChanges(); return(Content("<script>alert('修改成功');history.go(-1)</script>")); }
public ActionResult boardAdd([System.Web.Http.FromBody] boardManager model) { if (ModelState.IsValid) { BOARD bo = new BOARD(); bo.B_NAME = model.B_NAME; bo.B_CONTENTS = model.B_CONTENTS; conn.BOARD.Add(bo); conn.SaveChanges(); return(RedirectToAction("boardManager")); } return(View()); }
public ActionResult Register(RegisterModel model) { string ss; string pa = "~/unload/userLogo/"; ss = "U" + System.DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + Path.GetExtension(Request.Files["file"].FileName); var jp = Path.GetExtension(Request.Files["file"].FileName); Request.Files["file"].SaveAs(System.Web.HttpContext.Current.Server.MapPath(pa) + ss); if (ModelState.IsValid) { Users post1 = conn.Users.FirstOrDefault(a => a.Accounts == model.UserName); if (post1 == null) { // 尝试注册用户 Users user = new Users(); user.Accounts = model.UserName; user.Password = model.Password; user.E_mail = model.E_mail; user.Sex = model.Sex; user.Nickname = model.Nickname; user.UserLogo = jp == "" ? "old.jpg" : ss; user.RegisterDate = DateTime.Parse(DateTime.Now.ToString()); conn.Users.Add(user); conn.SaveChanges(); return(Content("<script>alert('你已注册成功');window.location.href='/Account/Account'</script>")); } else { return(Content("该账户已被注册")); } } // 如果我们进行到这一步时某个地方出错,则重新显示表单 return(View(model)); }
public ActionResult Post(int postId) { //var all=new Actio(); //var post = new newPost(); mpost mp = new mpost(); mp.P_ID = postId; conn.Configuration.AutoDetectChangesEnabled = false; //all.postInfo = post.GetListByPost(); var pro = conn.POST.FirstOrDefault(r => r.P_ID == postId); var proc = conn.POSTCOMMENT.Where(r => r.PC_POSTID == postId).OrderByDescending(r => r.PC_ID); //POSTCOMMENT post1 = conn.POSTCOMMENT.Find(postId); 也是一种查询 var list = new mpost() { P_ID = pro.P_ID, P_DATETIME = pro.P_DATETIME, P_BOARDID = (int)pro.P_BOARDID, P_BOARDNAME = pro.P_BOARDNAME, P_CLICK = (int)pro.P_CLICK, P_CONTENTS = pro.P_CONTENTS, p_EMOJI = pro.p_EMOJI, P_PICTURE = pro.P_PICTURE, P_POSTER = pro.P_POSTER, P_Title = pro.P_Title, }; POST p = new POST(); int click = (int)pro.P_CLICK + 1; #region 也是一种增加 //conn.Set(pro).Attach(POST); //p.P_CLICK = click; //p.P_ID = postId; //conn.Entry<POST>(p).State = System.Data.EntityState.Modified; //conn.SaveChanges(); #endregion ViewBag.post = list; //新增 由于被ef跟踪 using (var db = new Wang()) { var pidd = db.POST.Where(aa => aa.P_ID == postId).FirstOrDefault(); pidd.P_CLICK = click; db.SaveChanges(); } HttpCookie cook = new HttpCookie("b_id", pro.P_BOARDID.ToString()); HttpCookie cook1 = new HttpCookie("id", pro.P_ID.ToString()); Response.Cookies.Add(cook); Response.Cookies.Add(cook1); return(View(proc)); }