public ActionResult Edit() { var Id = Request["Id"].ToInt(); using (var db = new ClubEntities()) { var level = db.Level.FirstOrDefault(a => a.Id == Id); //var levels = db.Level.ToList(); //foreach (var level in levels) //{ // var selectItem = new SelectListItem(); // selectItem.Text = level.Name; // selectItem.Value = level.Id.ToString(); // if (user != null && (user.LevelId == level.Id)) // { // selectItem.Selected = true; // } // selectItems.Add(selectItem); //} //ViewBag.SeletItems = selectItems; if (level == null) { level = new Level(); } return(View(level)); } }
public ActionResult Delete() { var idStr = Request["Id"]; var id = idStr.ToInt(); if (id == 0) { TempData["Msg"] = "数据不正确!"; return(RedirectToAction("Index")); } using (var db = new ClubEntities()) { var user = db.PraiseRecord.FirstOrDefault(a => a.Id == id); if (user != null) { user.IsAbort = true; //db.User.Remove(user); db.SaveChanges(); } } TempData["Msg"] = "删除成功!"; return(RedirectToAction("Index")); }
public ActionResult Login(UserLoginParams userLoginParams) { if (string.IsNullOrEmpty(userLoginParams.Account) || string.IsNullOrEmpty(userLoginParams.PassWord)) { ShowMsg("账号密码不能为空"); return(RedirectToAction("Login")); } using (var db = new ClubEntities()) { var pw = userLoginParams.PassWord.MD5Encoding(userLoginParams.Account); var user = db.User.FirstOrDefault(a => a.Account == userLoginParams.Account && a.PassWord == pw); if (user == null) { ShowMsg("用户不存在"); return(RedirectToAction("Login")); } //设置用户登陆状态 Session["loginUser"] = user; return(Redirect("/")); } }
public ActionResult Edit() { var Id = Request["Id"].ToInt(); using (var db = new ClubEntities()) { var user = db.User.Include(a => a.Level).FirstOrDefault(a => a.Id == Id); var selectItems = new List <SelectListItem>(); var levels = db.Level.ToList(); foreach (var level in levels) { var selectItem = new SelectListItem(); selectItem.Text = level.Name; selectItem.Value = level.Id.ToString(); if (user != null && (user.LevelId == level.Id)) { selectItem.Selected = true; } selectItems.Add(selectItem); } ViewBag.SeletItems = selectItems; if (user == null) { user = new User(); } return(View(user)); } }
public ActionResult Login() { var account = Request["account"]; var password = Request["password"]; if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password)) { ShowMsg("账号密码不能为空"); return(RedirectToAction("Index")); } using (var db = new ClubEntities()) { var pw = password.MD5Encoding(account); var user = db.User.FirstOrDefault(a => a.Account == account && a.PassWord == pw); if (user == null) { ShowMsg("用户不存在"); return(RedirectToAction("Index")); } //设置用户登陆状态 Session["AdminUser"] = user; return(Redirect("/admin/home")); } }
public ActionResult Save() { var id = Request["id"].ToInt(); var name = Request["name"]; if (string.IsNullOrEmpty(name)) { ShowMsg("分类名称不能为空!"); return(RedirectToAction("Edit")); } using (var db = new ClubEntities()) { var category = db.Category.FirstOrDefault(a => a.Id == id); if (category == null) { category = new Category(); category.IsAbort = false; db.Category.Add(category); } category.Name = name; db.SaveChanges(); ShowMsg("操作成功"); } return(RedirectToAction("Index")); }
public ActionResult Save() { var id = Request["id"].ToInt(); var name = Request["name"]; var account = Request["account"]; var levelId = Request["levelId"].ToInt(); var integral = Request["integral"].ToInt(); var image = Request["image"]; using (var db = new ClubEntities()) { var user = db.User.FirstOrDefault(a => a.Id == id); if (user == null) { user = new User(); user.Account = account; user.IsAdmin = false; user.PassWord = "******"; db.User.Add(user); } user.Name = name; user.LevelId = levelId; user.integral = integral; user.Image = image; db.SaveChanges(); ShowMsg("操作成功"); } return(RedirectToAction("Index")); }
public ActionResult user() { var Id = Request["Id"].ToInt(); using (var db = new ClubEntities()) { var loginUser = (User)Session["loginUser"]; ViewBag.LoginUser = loginUser; var postList = new List <ListPostModel>(); var list = db.Post.ToList(); foreach (var item in list) { var postModel = new ListPostModel(); postModel.Id = item.Id; postModel.Title = item.Title; postModel.UserName = item.User.Name; postModel.CreateTime = item.CreateTime; postModel.ViewCount = item.ViewCount; postModel.Status = item.Status.ToString(); postModel.UserImage = item.User.Image; postList.Add(postModel); } return(View(postList)); } }
/// <summary> /// 分类管理 /// </summary> /// <returns></returns> public ActionResult Delete() { var idStr = Request["Id"]; var id = idStr.ToInt(); if (id == 0) { ShowMsg("数据不正确!"); return(RedirectToAction("Index")); } using (var db = new ClubEntities()) { var category = db.Category.FirstOrDefault(a => a.Id == id); if (category != null) { category.IsAbort = true; //db.User.Remove(user); db.SaveChanges(); } } ShowMsg("删除成功!"); return(RedirectToAction("Index")); }
// GET: Admin/PraiseRecord public ActionResult Index() { int pageSize = 10; var pageIndex = Request["pageIndex"].ToInt(1); var kw = Request["kw"]; //if (string.IsNullOrEmpty(indexStr)) //{ // indexStr = "1"; //} //var pageIndex = int.Parse(indexStr); IPagedList <PraiseRecord> items; using (var db = new ClubEntities()) { var list = db.PraiseRecord.Where(a => a.IsAbort == false).Include(a => a.User).Include(a => a.Post); if (!string.IsNullOrEmpty(kw)) { list = list.Where(a => a.User.Name.Contains(kw) || a.Post.Title.Contains(kw)); ViewBag.KW = kw; } items = list.OrderByDescending(a => a.Id).ToPagedList(pageIndex: pageIndex, pageSize: pageSize); } return(View(items)); }
public ActionResult NewPost() { using (var db = new ClubEntities()) { var categorys = db.Category.ToList(); ViewBag.Categorys = categorys; } return(View()); }
public ActionResult Details() { using (ClubEntities dbObj = new ClubEntities()) { var uname = Session["UserName"]; var coach = dbObj.Coachs.Where(x => x.UserName == uname).FirstOrDefault(); return(View(coach)); } }
// GET: Coach /* public ActionResult Index() * { * return View(); * }*/ // GET: Coach/Details/5 public ActionResult Coach() { using (ClubEntities dbObj = new ClubEntities()) { var uname = Session["UserName"]; Session["Notifications"] = dbObj.Notifications.Where(x => x.UserName == uname).Count(); var coach = dbObj.Coachs.Where(x => x.UserName == uname).FirstOrDefault(); return(View(coach)); } }
public ActionResult HistoryCreate(History history) { if (ModelState.IsValid) { ClubEntities dbObj = new ClubEntities(); history.Coach = Session["UserName"].ToString(); dbObj.Histories.Add(history); dbObj.SaveChanges(); return(RedirectToAction("HistoryList")); } return(View(history)); }
public ActionResult Save() { var id = Request["id"].ToInt(); int isfeaturedid = Request["isfeaturedid"].ToInt(); int categoryId = Request["categoryId"].ToInt(); using (var club = new ClubEntities()) { var post = club.Post.FirstOrDefault(a => a.Id == id); post.CategoryId = categoryId; post.IsFeatured = isfeaturedid.ToBit(); club.SaveChanges(); } ShowMsg("操作成功"); return(RedirectToAction("Index")); }
public ActionResult Edit() { var Id = Request["Id"].ToInt(); using (var db = new ClubEntities()) { var category = db.Category.FirstOrDefault(a => a.Id == Id); var levels = db.Level.ToList(); if (category == null) { category = new Category(); } return(View(category)); } }
public ActionResult Contents() { var Id = Request["Id"].ToInt(); using (var db = new ClubEntities()) { var post = db.Post.Include(a => a.User).FirstOrDefault(a => a.Id == Id); var user = db.User.OrderByDescending(a => a.Id).Include(a => a.Level).ToList(); ViewBag.User = user; //查询赞帖子的用户 var praiserecord = db.PraiseRecord.OrderByDescending(a => a.Id).Include(a => a.User).ToList(); ViewBag.praiserecord = praiserecord; var listpraiserecord = new List <PraiseModel>(); foreach (var item in praiserecord) { var praiserecordmodel = new PraiseModel(); praiserecordmodel.postid = item.Post.Id; praiserecordmodel.userid = item.User.Id; praiserecordmodel.username = item.User.Name; praiserecordmodel.userimage = item.User.Image; praiserecordmodel.time = item.CreateTime; listpraiserecord.Add(praiserecordmodel); } ViewData["praiserecord"] = listpraiserecord; //查询收藏帖子的用户 var collection = db.Collection.OrderByDescending(a => a.Id).Include(a => a.User).ToList(); ViewBag.collection = collection; //查询帖子回复的信息 var reply = db.AllReply.OrderByDescending(a => a.Id).Include(a => a.User).Where(a => a.Id == Id).ToList(); var listreply = new List <ReplyModel>(); foreach (var item in reply) { var replyModel = new ReplyModel(); replyModel.postid = item.Post.Id; replyModel.userid = item.User.Id; replyModel.username = item.User.Name; replyModel.userlevel = item.User.Level.Name; replyModel.userimage = item.User.Image; replyModel.contents = item.Contents; replyModel.responseTime = item.ResponseTime; listreply.Add(replyModel); } ViewData["reply"] = listreply; return(View(post)); } }
public List <UserModel> List() { var list = new List <UserModel>(); using (var db = new ClubEntities()) { var user = db.User; foreach (var item in user) { var usermodel = new UserModel(); usermodel.Id = item.id; usermodel.name = item.Name; usermodel.account = item.Account; list.Add(usermodel); } } return(list); }
public ActionResult Edit() { var Id = Request["Id"].ToInt(); using (var db = new ClubEntities()) { var post = db.Post.Include(a => a.User).Include(a => a.Category).FirstOrDefault(a => a.Id == Id); var selectItems = new List <SelectListItem>(); var selectlistis = new List <SelectListItem>(); var categorys = db.Category.ToList(); //帖子类型 foreach (var category in categorys) { var selectItem = new SelectListItem(); selectItem.Text = category.Name; selectItem.Value = category.Id.ToString(); if (post != null && (post.CategoryId == category.Id)) { selectItem.Selected = true; } selectItems.Add(selectItem); } ViewBag.SeletItems = selectItems; //是否审核下拉 string[,] isfeatured = { { "0", "未审核" }, { "1", "已审核" } }; for (int i = 0; i < 2; i++) { var selectitem = new SelectListItem(); selectitem.Text = isfeatured[i, 1]; selectitem.Value = isfeatured[i, 0]; if (post.IsFeatured == i.ToBit()) { selectitem.Selected = true; } selectlistis.Add(selectitem); } ViewBag.isfeatured = selectlistis; return(View(post)); } }
public ActionResult IndexReply() { //最新回复 var loginUser = (User)Session["loginUser"]; ViewBag.LoginUser = loginUser; int pageSize = 5; var pageIndex = Request["pageIndex"].ToInt(1); var kw = Request["kw"]; IPagedList <Club.Models.ReplyModel> pt; var cookies = new HttpCookie("User"); using (var db = new ClubEntities()) { var replyList = new List <ReplyModel>(); var list = db.AllReply.OrderByDescending(a => a.Id).Include(a => a.User).Include(a => a.Post).ToList(); var category = db.Category.Where(a => a.IsAbort == false).ToList(); ViewBag.category = category; foreach (var item in list) { var replyModel = new ReplyModel(); replyModel.postid = item.Post.Id; replyModel.Title = item.Post.Title; replyModel.UserName = item.User.Name; replyModel.CreateTime = item.Post.CreateTime; replyModel.ViewCount = item.Post.ViewCount; replyModel.Reply = item.Post.ReplyCount; if (item.Post.Status == 1) { replyModel.Status = "【精】"; } else { replyModel.Status = ""; } replyModel.UserImage = item.User.Image; replyList.Add(replyModel); } pt = replyList.OrderByDescending(a => a.responseTime).ToPagedList(pageIndex: pageIndex, pageSize: pageSize); return(View(pt)); } }
// GET: Admin/Level public ActionResult Index() { int pageSize = 10; var pageIndex = Request["pageIndex"].ToInt(1); //if (string.IsNullOrEmpty(indexStr)) //{ // indexStr = "1"; //} //var pageIndex = int.Parse(indexStr); var list = new List <Level>(); using (var db = new ClubEntities()) { list = db.Level.Where(a => a.IsAbort == false).OrderByDescending(a => a.Id).ToPagedList(pageIndex: pageIndex, pageSize: pageSize); } return(View(list)); }
public ActionResult Category4() { var loginUser = (User)Session["loginUser"]; ViewBag.LoginUser = loginUser; int pageSize = 5; var pageIndex = Request["pageIndex"].ToInt(1); var kw = Request["kw"]; IPagedList <Club.Models.ListPostModel> pt; var cookies = new HttpCookie("User"); using (var db = new ClubEntities()) { var postList = new List <ListPostModel>(); var list = db.Post.OrderByDescending(a => a.Id).Include(a => a.User).Include(a => a.Category).Where(a => a.CategoryId == 4).ToList(); var category = db.Category.Where(a => a.IsAbort == false).ToList(); ViewBag.category = category; foreach (var item in list) { var postModel = new ListPostModel(); postModel.Id = item.Id; postModel.Title = item.Title; postModel.UserName = item.User.Name; postModel.CreateTime = item.CreateTime; postModel.ViewCount = item.ViewCount; postModel.PostReply = item.ReplyCount; if (item.Status == 1) { postModel.Status = "【精】"; } else { postModel.Status = ""; } postModel.UserImage = item.User.Image; postList.Add(postModel); } pt = postList.OrderByDescending(a => a.CreateTime).ToPagedList(pageIndex: pageIndex, pageSize: pageSize); return(View(pt)); } }
public ActionResult Save() { var categoryId = Request["categoryId"].ToInt(); var title = Request["title"]; var content = Request["content"]; var loginUser = (User)Session["loginUser"]; if (categoryId == 0) { ShowMsg("帖子分类不能为空"); return(RedirectToAction("New")); } if (string.IsNullOrEmpty(title)) { ShowMsg("帖子标题不能为空"); return(RedirectToAction("New")); } if (string.IsNullOrEmpty(content)) { ShowMsg("帖子内容不能为空"); return(RedirectToAction("New")); } using (var db = new ClubEntities()) { var post = new Post(); post.CategoryId = categoryId; post.Title = title; post.Details = content; post.CreateTime = DateTime.Now; post.UserId = loginUser.Id; post.IsFeatured = true; db.Post.Add(post); db.SaveChanges(); ShowMsg("发布成功"); return(Redirect("/")); } }
public ActionResult Save() { var id = Request["id"].ToInt(); var name = Request["name"]; using (var db = new ClubEntities()) { var level = db.Level.FirstOrDefault(a => a.Id == id); if (level == null) { level = new Level(); level.IsAbort = false; db.Level.Add(level); } level.Name = name; db.SaveChanges(); ShowMsg("操作成功"); } return(RedirectToAction("Index")); }
public ActionResult Register(UserRegisterParams userRegisterParams) { using (var db = new ClubEntities()) { var user = db.User.FirstOrDefault(a => a.Account == userRegisterParams.Account); if (user != null) { ShowMsg("该用户已存在"); return(View()); } user = new User(); user.Account = userRegisterParams.Account; user.PassWord = userRegisterParams.PassWord.MD5Encoding(user.Account); user.Name = userRegisterParams.Name; user.CreateTime = DateTime.Now; user.LevelId = 1; db.User.Add(user); db.SaveChanges(); ShowMsg("用户注册成功,请登录"); } return(View()); }
public ActionResult CoachList() { ClubEntities dbObj = new ClubEntities(); return(View(dbObj.Coachs.ToList())); }
public ActionResult Index() { #region 数据库的增删改查 //using (var db = new ClubEntities()) //{ // var level = new Level(); // level.Name = "级别1"; // db.Level.Add(level); // db.SaveChanges(); //} //using (var db = new ClubEntities()) //{ // for (int i = 0; i < 100; i++) // { // var user = new User(); // user.LevelId = 1; // user.Name = "张" + i; // user.Account = "张" + i; // user.PassWord = "******"; // db.User.Add(user); // db.SaveChanges(); // } //} //using (var db= new ClubEntities()) //{ // var user = db.User.FirstOrDefault(a => a.Id == 2); // if (user != null) // { // db.User.Remove(user); // db.SaveChanges(); // } //} //using (var db=new ClubEntities()) //{ // var user = db.User.FirstOrDefault(a => a.Id == 3); // if (user != null) // { // user.Name = "软件153的用户"; // } // db.SaveChanges(); //} //using (var db=new ClubEntities()) //{ // var users = db.User.Where(t => t.Id < 10).ToList(); // var sb=new StringBuilder(); // foreach (var item in users) // { // sb.AppendLine("用户名:" + item.Name+"用户级别:"+item.Level.Name); // } // return Content(sb.ToString()); //} //密码加密 //using (var db = new ClubEntities()) //{ // var users = db.User.ToList(); // foreach (var user in users) // { // //var pw = EncryptHelper.MD5Encoding(user.PassWord, user.Account); // user.PassWord = user.PassWord.MD5Encoding(user.Account); // } // db.SaveChanges(); //} // var pw = EncryptHelper.MD5Encoding("000000","zhangchi"); //return Content("ok"); #endregion //最新发表 var loginUser = (User)Session["loginUser"]; ViewBag.LoginUser = loginUser; int pageSize = 5; var pageIndex = Request["pageIndex"].ToInt(1); var kw = Request["kw"]; IPagedList <Club.Models.ListPostModel> pt; var cookies = new HttpCookie("User"); using (var db = new ClubEntities()) { var postList = new List <ListPostModel>(); var list = db.Post.OrderByDescending(a => a.Id).Include(a => a.User).Include(a => a.Category).Where(a => a.IsFeatured == true).ToList(); var category = db.Category.Where(a => a.IsAbort == false).ToList(); ViewBag.category = category; foreach (var item in list) { var postModel = new ListPostModel(); postModel.Id = item.Id; postModel.Title = item.Title; postModel.UserName = item.User.Name; postModel.CreateTime = item.CreateTime; postModel.ViewCount = item.ViewCount; postModel.PostReply = item.ReplyCount; if (item.Status == 1) { postModel.Status = "【精】"; } else { postModel.Status = ""; } postModel.UserImage = item.User.Image; postList.Add(postModel); } pt = postList.OrderByDescending(a => a.CreateTime).ToPagedList(pageIndex: pageIndex, pageSize: pageSize); return(View(pt)); } }
public ActionResult HistoryList() { ClubEntities dbObj = new ClubEntities(); return(View(dbObj.Histories)); }