public ActionResult Register(RegisterUser model) { if (ModelState.IsValid) { string sessionValidCode = Session["validatecode"] == null ? string.Empty : Session["validatecode"].ToString(); if (!model.Code.Equals(sessionValidCode)) { return(Content("验证码不对")); } var user = new User(); user.AddTime = DateTime.Now; user.Name = model.Name; user.Pwd = Tool.GetMD5(model.Pwd);//经过md5的加密 user.Status = true; int res = 0; using (LegendaryBlog.App_Code.BlogDbContext dbContext = new App_Code.BlogDbContext()) { dbContext.Users.Add(user); res = dbContext.SaveChanges();//才是真正保存到数据库 } if (res > 0) { return(Redirect("/")); } else { return(Content("注册失败")); } } else { return(Content("验证失败")); } }
public ActionResult CatalogAdd(CatalogAdd model) { if (ModelState.IsValid) { var catalog = new Catalog(); catalog.AddTime = DateTime.Now; catalog.Name = model.Name; catalog.Status = true; int res = 0; using (LegendaryBlog.App_Code.BlogDbContext dbContext = new App_Code.BlogDbContext()) { dbContext.Catalogs.Add(catalog); res = dbContext.SaveChanges();//才是真正保存到数据库 } if (res > 0) { return(Content("添加成功")); } else { return(Content("添加失败")); } } else { return(Content("验证失败")); } }
public ActionResult BlogAdd(BlogAdd model) { if (ModelState.IsValid) { var b = new Blog(); b.AddTime = DateTime.Now; b.Title = model.Title; b.catalogId = model.catalogId; b.Content = model.Content; b.Status = true; int res = 0; using (LegendaryBlog.App_Code.BlogDbContext dbContext = new App_Code.BlogDbContext()) { dbContext.Blogs.Add(b); res = dbContext.SaveChanges(); //才是真正保存到数据库 } if (res > 0) { return(Content("添加成功")); } else { return(Content("添加失败")); } } else { return(Content("验证不通过")); } }
public ActionResult Blog(int id) { using (LegendaryBlog.App_Code.BlogDbContext dbContext = new App_Code.BlogDbContext()) { var model = dbContext.Blogs.FirstOrDefault(m => m.Id == id); return(View(model)); } }
public JsonResult LoadCatalog() { using (LegendaryBlog.App_Code.BlogDbContext dbContext = new App_Code.BlogDbContext()) { var list = dbContext.Catalogs.ToList().Select(m => new { Id = m.Id, Name = m.Name, AddTime = m.AddTime }).ToList(); return(Json(list)); } }
public ActionResult CatalogModify(int id) { using (LegendaryBlog.App_Code.BlogDbContext dbContext = new App_Code.BlogDbContext()) { var model = dbContext.Catalogs.FirstOrDefault(m => m.Id == id); CatalogModify cm = new ViewsModels.CatalogModify(); cm.Id = model.Id; cm.Name = model.Name; return(View(cm)); } }
public ActionResult BlogAdd() { using (LegendaryBlog.App_Code.BlogDbContext dbContext = new App_Code.BlogDbContext()) { List <SelectListItem> listCatalog = dbContext.Catalogs.ToList().Select(c => new SelectListItem() { Text = c.Name, Value = c.Id.ToString() }).ToList(); ViewBag.catalogList = listCatalog; return(View()); } }
public ActionResult CatalogDel(int id) { using (LegendaryBlog.App_Code.BlogDbContext dbContext = new App_Code.BlogDbContext()) { var odlModel = dbContext.Catalogs.FirstOrDefault(m => m.Id == id); DbEntityEntry entry = dbContext.Entry(odlModel); entry.State = EntityState.Deleted; int res = dbContext.SaveChanges(); if (res > 0) { return(Redirect("~/Manage/CatalogManage")); } else { return(Content("删除失败")); } } }
public ActionResult CatalogModify(CatalogModify model) { using (LegendaryBlog.App_Code.BlogDbContext dbContext = new App_Code.BlogDbContext()) { var odlModel = dbContext.Catalogs.FirstOrDefault(m => m.Id == model.Id); odlModel.Name = model.Name; DbEntityEntry entry = dbContext.Entry(odlModel); entry.State = EntityState.Modified; int res = dbContext.SaveChanges(); if (res > 0) { return(Content("修改成功")); } else { return(Content("修改失败")); } } }
public ActionResult Login(LoginUser model) { var user = model; if (ModelState.IsValid) { string sessionValidCode = Session["validatecode"] == null ? string.Empty : Session["validatecode"].ToString(); if (!model.Code.Equals(sessionValidCode)) { return(Content("验证码不对")); } //根据用户名查找实体 using (LegendaryBlog.App_Code.BlogDbContext dbContext = new App_Code.BlogDbContext()) { var nameUser = dbContext.Users.FirstOrDefault(m => m.Name == model.Name); if (nameUser == null) { return(Content("账号或者密码不对"));//这里不要提示太明显 } else { if (Tool.GetMD5(model.Pwd).Equals(nameUser.Pwd))//让用户输入的密码加密后和查找的实体的密码比较 { Session["loginuser"] = nameUser; return(Redirect("/")); } else { return(Content("账号或者密码不对")); } } } } else { return(Content("验证失败")); } }