public ActionResult Count(string type, string countType, string id) { try { //创建数据上下文 DBContext = new WebManagementDBEntities(); int Id = int.Parse(id); if (type == "1") //论坛信息 { //获取当前信息的对象 var forumInfo = DBContext.ForumInfo.Where(f => f.Id == Id).FirstOrDefault(); if (countType == "1")//对我有用统计 { forumInfo.UsefulCount += 1; } else if (countType == "2")//丢个板砖统计 { forumInfo.UselessCount += 1; } DBContext.ForumInfo.Attach(forumInfo); DBContext.Entry(forumInfo).State = System.Data.EntityState.Modified; DBContext.SaveChanges(); return(Content("success")); } else if (type == "2")//论坛回复信息 { //创建一个回复信息的对象 var answerInfo = DBContext.AnswerInfo.Where(a => a.Id == Id).FirstOrDefault(); if (countType == "1")//对我有用统计 { answerInfo.UsefulCount += 1; } else if (countType == "2")//丢个板砖统计 { answerInfo.UselessCount += 1; } DBContext.AnswerInfo.Attach(answerInfo); DBContext.Entry(answerInfo).State = System.Data.EntityState.Modified; DBContext.SaveChanges(); return(Content("success")); } return(Content("error")); } catch { return(RedirectToAction("../User/_404")); } }
}//结束 /// <summary> /// 【修改个人信息】 /// </summary> /// <returns></returns> public ActionResult UpdateUserInfo() { string trueName = Request["TrueName"]; string gender = Request["Gender"]; string deviceId = Request["DeviceId"]; string phone = Request["Phone"]; string code = Request["Code"]; if (!string.IsNullOrEmpty(trueName) && !string.IsNullOrEmpty(gender) && !string.IsNullOrEmpty(deviceId) && !string.IsNullOrEmpty(phone) && !string.IsNullOrEmpty(code)) { if (code == Session["UpdateInfo_Code"].ToString()) { string username = Session["UserName"].ToString(); try { //执行更新操作 DBContext = new WebManagementDBEntities(); var user = DBContext.UserInfo.Where(u => u.Email == username).FirstOrDefault(); if (user == null) { return(Content("error1")); } else { user.TrueName = trueName; user.DeviceId = deviceId; if (gender == "man") { user.Gender = "男"; } else if (gender == "woman") { user.Gender = "女"; } user.Phone = phone; DBContext.UserInfo.Attach(user); DBContext.Entry(user).State = System.Data.EntityState.Modified; DBContext.SaveChanges(); return(Content("success")); } } catch { return(RedirectToAction("_404")); } } else { return(Content("error2")); } } else { return(Content("error3")); } }
/// <summary> /// 【检查并更新密码】 /// </summary> /// <returns></returns> public ActionResult CheckUpdatePwd() { //修改密码前,需要先验证是否登陆 if (Session["UserName"] != null) { string pwd1 = Request["UpdatePwd1"]; string pwd2 = Request["UpdatePwd2"]; if (pwd1.Length <= 20 && pwd2.Length <= 20) { if (pwd1 == pwd2) { //执行数据库更新 //string sql = "update UserInfo set " try { string username = Session["UserName"].ToString(); DBContext = new WebManagementDBEntities(); var user = DBContext.UserInfo.Where(u => u.Email == username && u.DelFlag == 0).FirstOrDefault(); if (user == null) { return(Content("error")); } else { user.UserPwd = pwd1; DBContext.UserInfo.Attach(user); DBContext.Entry(user).State = System.Data.EntityState.Modified; DBContext.SaveChanges(); Session.Remove("UserName"); Session.Remove("NickName"); return(Content("success")); } } catch { return(RedirectToAction("_404")); } } else { return(Content("error")); } } else { return(Content("error")); } } else { return(RedirectToAction("../Home/Login", new { referenUrl = "/User/ShowMyInfo" })); } }//结束
/// <summary> ///【展示论坛文章细节】 /// </summary> /// <returns></returns> public ActionResult Showdetail(string Id) { if (!string.IsNullOrEmpty(Id)) { try { int forumId = int.Parse(Id); //创建数据上下文 DBContext = new WebManagementDBEntities(); //根据论坛信息的Id去读取论坛详细信息 var forumInfo = DBContext.ForumInfo.Where(f => f.Id == forumId && f.DelFlag == 0).FirstOrDefault(); if (forumInfo != null) { //读取其他人的回复信息 var answerInfo = DBContext.AnswerInfo.Where(a => a.ForumInfoId == forumId).OrderBy(a => a.FloorNumber); if (answerInfo != null) { ViewBag.ForumInfo = forumInfo; ViewBag.AnswerInfo = answerInfo; ViewData["reply_id"] = Id; //更新一下查看次数 forumInfo.ViewNumber += 1; DBContext.ForumInfo.Attach(forumInfo); DBContext.Entry(forumInfo).State = System.Data.EntityState.Modified; DBContext.SaveChanges(); return(View()); } else { return(RedirectToAction("../User/_404")); } } else { return(RedirectToAction("../User/_404")); } } catch (Exception e) { throw e; } } else { return(RedirectToAction("../User/_404")); } }
public ActionResult SubPostForum(string code, string forumType, string title, string content) { if (Session["UserName"] != null) { if (!string.IsNullOrEmpty(code) && Session["PostForumCode"].ToString() == code) { if (!string.IsNullOrEmpty(forumType) && !string.IsNullOrEmpty(title) && !string.IsNullOrEmpty(content)) { if (title.Length <= 250) { try{ string forumType2 = ""; string forumName = ""; #region 论坛类型转换 if (forumType == "1") { forumType2 = "YYMS"; forumName = "营养美食"; } else if (forumType == "2") { forumType2 = "SSMT"; forumName = "塑身美体"; } else if (forumType == "3") { forumType2 = "JKBD"; forumName = "健康宝典"; } else if (forumType == "4") { forumType2 = "YEBD"; forumName = "育儿宝典"; } else if (forumType == "5") { forumType2 = "YLZP"; forumName = "娱乐杂评"; } else if (forumType == "6") { forumType2 = "NRNR"; forumName = "男人女人"; } else { return(Content("error2")); } #endregion //创建上下文和论坛信息对象 DBContext = new WebManagementDBEntities(); ForumInfo f1 = new ForumInfo(); //填充一个论坛信息对象 f1.Title = title; //标题 f1.ForumType = forumType2; //论坛类型编号 f1.ForumName = forumName; //论坛类型名字 f1.Content = content; //内容 f1.FloorCount = 0; //楼层数 f1.ViewNumber = 0; //查看数目 f1.SubDate = DateTime.Now; //提交时间 f1.SubNum = Session["UserName"].ToString(); //提交人编号 f1.SubName = Session["NickName"].ToString(); //提交人昵称 f1.UsefulCount = 0; //觉得有用的数目 f1.UselessCount = 0; //觉得没用的数目 f1.DelFlag = 0; //删除标识 //附加并保存 DBContext.ForumInfo.Attach(f1); DBContext.Entry(f1).State = System.Data.EntityState.Added; DBContext.SaveChanges(); return(Content("success")); } catch { return(RedirectToAction("../User/_404")); } } else { return(Content("error2"));//标题长度过长 } } else { return(RedirectToAction("../User/_404")); } } else { return(Content("error1"));//验证码错误 } } else { return(RedirectToAction("../Home/Login", new { referenUrl = "/Forum/PostForum" })); } }
public ActionResult SubReplContent(string code, string replyContent, string id) { //判断是否登陆 if (Session["UserName"] != null) { if (!string.IsNullOrEmpty(code) && Session["ReplyCode"].ToString() == code) { //对数据合法性进行判断 if (!string.IsNullOrEmpty(replyContent) && !string.IsNullOrEmpty(id)) { try { //新建一个数据上下文 DBContext = new WebManagementDBEntities(); int id2 = Convert.ToInt32(id); //获取论坛楼主层信息 var f1 = DBContext.ForumInfo.Where(f => f.Id == id2 && f.DelFlag == 0).FirstOrDefault(); //新建一个回复内容对象 AnswerInfo a1 = new AnswerInfo(); a1.ForumInfoId = id2; a1.Content = replyContent; a1.FromNum = Session["UserName"].ToString(); a1.FromName = Session["NickName"].ToString(); a1.FloorNumber = f1.FloorCount + 1; a1.SubDate = DateTime.Now; a1.DelFlag = 0; a1.UsefulCount = 0; a1.UselessCount = 0; //附加新建回复内容对象a1 DBContext.AnswerInfo.Attach(a1); DBContext.Entry(a1).State = System.Data.EntityState.Added; //修改楼主层的信息 f1.FloorCount += 1; DBContext.ForumInfo.Attach(f1); DBContext.Entry(f1).State = System.Data.EntityState.Modified; //执行保存 DBContext.SaveChanges(); return(Content("success")); } catch { return(RedirectToAction("../User/_404")); } } else { return(RedirectToAction("../User/_404")); } } else { return(Content("error1")); } } else { return(RedirectToAction("../Home/Login", new { referenUrl = "/Forum/Showdetail?id=" + id })); } }
/// <summary> /// 检查用户登录 /// </summary> /// <param name="name">用户名</param> /// <param name="pwd">密码</param> /// <returns>检查结果</returns> public ActionResult CheckLogin(string username, string password) { #region 注释 // string sql = "select * from UserInfo where LoginId = '"+"Admin"+ "'and Pwd = '"+"123"+"'"; //string sql = "select * from UserInfo where (LoginId = @LoginId or Email = @LoginId) and Pwd = @Pwd"; //Session.Add("username", "Admin"); //return 1; //try //{ // using (SqlConnection con = new SqlConnection(connStr)) // { // con.Open(); // using (SqlCommand cmd = con.CreateCommand()) // { // cmd.CommandText = sql; // cmd.Parameters.Add(new SqlParameter("@LoginId", name)); // cmd.Parameters.Add(new SqlParameter("@Pwd", pwd)); // using (SqlDataReader reader = cmd.ExecuteReader()) // { // if (reader.Read()) // { // return 1; // } // else // { // return 0; // } // } // //return cmd.ExecuteNonQuery(); // } // } //} //catch (Exception e) //{ // throw e; //} #endregion if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { return(Content("error1")); } try { //创建上下文 DBContext = new WebManagementDBEntities(); var user = DBContext.UserInfo.Where(u => u.Email == username && u.UserPwd == password && u.DelFlag == 0).FirstOrDefault(); if (user == null) { return(Content("error2")); } else { if (user.State == "正常") { //保存相关Session Session["UserName"] = username; Session["NickName"] = user.NickName; //执行更新 user.LastLoginTime = DateTime.Now; user.LastIP = Request.UserHostAddress; DBContext.UserInfo.Attach(user); DBContext.Entry(user).State = System.Data.EntityState.Modified; DBContext.SaveChanges(); //返回结果 return(Content("success")); } else { return(Content("error3")); } } } catch { return(RedirectToAction("_404")); } }