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 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 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 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("修改失败")); } } }