/// <summary> /// 【个人信息展示】 /// </summary> /// <returns></returns> public ActionResult ShowMyInfo() { if (Session["UserName"] != null) { string username = Session["UserName"].ToString(); try { DBContext = new WebManagementDBEntities(); var user = DBContext.UserInfo.Where(u => u.Email == username && u.DelFlag == 0).FirstOrDefault(); if (user == null) { return(RedirectToAction("_404")); } else { ViewBag.UserInfo = user; return(View()); } } catch { return(RedirectToAction("_404")); } } else { return(RedirectToAction("../Home/Login", new { referenUrl = "/User/ShowMyInfo" })); } }
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")); } }
// GET: /Home/ public ActionResult Index() { //创建数据上下文 var DBContext = new WebManagementDBEntities(); //获取数据 var list = DBContext.HealthInfo.Where(u => u.DelFlag == 0 && u.IsHot == 0).OrderBy(u => u.SubDate).Take(3); ViewBag.News = list; return(View()); }
}//结束 /// <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")); } }
// // GET: /Forum/ public ActionResult Index() { //创建数据上下文 DBContext = new WebManagementDBEntities(); var forumInfo = DBContext.ForumInfo.Where(f => f.DelFlag == 0).OrderByDescending(f => f.ViewNumber).Take(10); ViewBag.ForumInfo = forumInfo; return(View()); }
/// <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")); } }
/// <summary> /// 【默认展示的页面】 /// </summary> /// <returns></returns> public ActionResult Index() { //创建数据上下文 DBContext = new WebManagementDBEntities(); var hotNews = DBContext.HealthInfo.Where(u => u.IsHot == 1 && u.DelFlag == 0).Take(3); if (hotNews != null) { ViewBag.HotNews = hotNews; } var newsInfo = DBContext.HealthInfo.Where(u => u.DelFlag == 0 && u.IsHot == 0).Take(10); if (newsInfo != null) { ViewBag.NewsInfo = newsInfo; } return(View()); }
/// <summary> /// 【根据咨询的Id获取完整的信息】 /// </summary> /// <param name="Id">Id</param> /// <returns></returns> public ActionResult ShowDetail(string Id) { if (!string.IsNullOrEmpty(Id)) { try { int newsId = int.Parse(Id); //创建数据上下文,根据Id查找相关记录 DBContext = new WebManagementDBEntities(); var newsInfo = DBContext.HealthInfo.Where(u => u.Id == newsId && u.DelFlag == 0).FirstOrDefault(); if (newsInfo != null) { ////封装成json格式 //var info = new //{ // Total = 1, // Title = newsInfo.Title, // Content = newsInfo.Content, // Remark = newsInfo.Remark //}; ////发送json格式数据 //return Json(info, JsonRequestBehavior.DenyGet); ViewBag.Info = newsInfo; return(View()); } else { return(RedirectToAction("../User/_404")); } } catch { return(RedirectToAction("../User/_404")); } } else { return(RedirectToAction("../User/_404")); } }
/// <summary> /// 【分页加载资讯信息】 /// </summary> /// <returns></returns> public ActionResult LoadNewsInfo() { //创建数据上下文 DBContext = new WebManagementDBEntities(); //获取页码和每页条数 int pageIndex = Request["pageIndex"] == null ? 1 : int.Parse(Request["pageIndex"]); int pageSize = Request["pageSize"] == null ? 10 : int.Parse(Request["pageSize"]); //获取相关数据的总数 int total = DBContext.HealthInfo.Where(u => u.DelFlag == 0 && u.IsHot == 0).Count(); //获取数据 var list = DBContext.HealthInfo.Where(u => u.DelFlag == 0 && u.IsHot == 0).OrderBy(u => u.SubDate).Skip(pageSize * (pageIndex - 1)).Take(pageSize); //要来做数据处理的新数组 ArrayList s = new ArrayList(); foreach (var row in list) { var hel = new { Id = row.Id, Title = row.Title, Remark = row.Remark }; s.Add(hel); } //分页导航的Html代码 string pageHtml = Page.ShowNewsPageNavigate(pageIndex, pageSize, total); //把返回条数,数据行,分页的html代码封装成Json格式 var data = new { Total = s.Count, Row = s.ToArray(), PageHtml = pageHtml }; return(Json(data, JsonRequestBehavior.DenyGet)); }
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> /// <returns></returns> public ActionResult Show() { //ViewData["ForumType"] = forumType; //return View(); //获取每页的条数和页码 int pageSize = Request["pageSize"] == null ? 10 : int.Parse(Request["pageSize"]); int pageIndex = Request["pageIndex"] == null ? 1 : int.Parse(Request["pageIndex"]); int forumType = Request["forumType"] == null ? 1 : int.Parse(Request["forumType"]); DBContext = new WebManagementDBEntities(); string type; #region 字符串转义 if (forumType == 1)//营养美食 { type = "YYMS"; } else if (forumType == 2)//塑身美体 { type = "SSMT"; } else if (forumType == 3)//健康宝典 { type = "JKBD"; } else if (forumType == 4)//育儿宝典 { type = "YEBD"; } else if (forumType == 5)//娱乐杂评 { type = "YLZP"; } else//男人女人 { type = "NRNR"; } #endregion //List<UserInfo> users = new List<UserInfo>(); //for (int i = 0; i < 20; i++) //{ // UserInfo u = new UserInfo(); // u.TrueName = "Tom" +i; // u.Email = "*****@*****.**"; // users.Add(u); //} //计算相关数据的总条数 int total = DBContext.ForumInfo.Where(f => f.ForumType == type).Count(); //获取相关分页数据 var forumInfo = DBContext.ForumInfo.Where(f => f.ForumType == type && f.DelFlag == 0).OrderBy(f => f.SubDate).Skip(pageSize * (pageIndex - 1)).Take(pageSize); //要来处理数据的新数组 ArrayList list = new ArrayList(); foreach (var row in forumInfo) { var f = new { Id = row.Id, Title = row.Title, SubName = row.SubName, FloorCount = row.FloorCount, SubDate = row.SubDate.ToString() }; list.Add(f); } var data = new { Total = list.Count, Row = list.ToArray(), PageNumber = Page.ShowPageNavigate(pageIndex, pageSize, list.Count, forumType)//这个方法为分页导航条的字符串 }; //ViewData["pageSize"] = pageSize; //ViewData["pageIndex"] = pageIndex; //ViewData["total"] = list.Count; return(Json(data, JsonRequestBehavior.AllowGet));//返回数据 }
/// <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")); } }