public void Delete(int id) { var proj = _rGameDbContext.Categories.FirstOrDefault(x => x.Id == id); _rGameDbContext.Entry(proj).State = EntityState.Deleted; _rGameDbContext.SaveChanges(); }
public ActionResult Yes(int id) { GameService service = new GameService(db); var game = service.GetById(id); db.Entry(game).State = EntityState.Modified; game.Confirm = Confirm.Correct.ToString(); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult EditUser(User user, HttpPostedFileBase UserPhoto) { if (UserPhoto != null) { if (UserPhoto.ContentLength > 1048576) { Session["FileSize"] = "File size is a big"; RedirectToAction("Edit", "Project", new { id = user.Id }); } if (UserPhoto.ContentType != "image/jpeg" && UserPhoto.ContentType != "image/jpg" && UserPhoto.ContentType != "image/gif" && UserPhoto.ContentType != "image/png") { Session["FileSize"] = "Incorrect type"; RedirectToAction("Edit", "Project", new { id = user.Id }); } string date = DateTime.Now.ToString("yyMMddHHmmss"); string fileName = date + UserPhoto.FileName; string path = Path.Combine(Server.MapPath("~/Uploads/UserImage"), fileName); UserPhoto.SaveAs(path); user.UserPhoto = fileName; User proj = db.Users.Find(user.Id); if (proj.UserPhoto != "UserPhoto.png") { System.IO.File.Delete(Path.Combine(Server.MapPath("~/Uploads/UserImage"), proj.UserPhoto)); } db.Entry(proj).State = EntityState.Detached; } if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; var userP = Session["User"] as User; if (UserPhoto == null) { //db.Entry(user).Property(p => p.UserPhoto).IsModified = false; user.UserPhoto = userP.UserPhoto; } if (user.Password != null) { string hashed = Crypto.HashPassword(user.Password); user.Password = hashed; } user.Role = Role.User.ToString(); user.Password = userP.Password; db.SaveChanges(); Session["User"] = user; return(RedirectToAction("EditUser")); } return(View(user)); }
public ActionResult Create([Bind(Include = "Id,Name")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public void Add(User proj) { _rGameDbContext.Users.Add(proj); _rGameDbContext.SaveChanges(); }