//************************************************************************************************************************ public void Delete(User user) { var validated = this.context.Users.Where(x => x.Username == user.Username).SingleOrDefault(); this.context.Users.Remove(validated); this.context.SaveChanges(); }
public ActionResult Register(User user) { bool exists = this.userService.Exists(user.Username); if (exists) { this.ModelState.AddModelError("", "Username already exists"); return View(); } if (user.Username == null || user.Password == null || user.Email == null) { this.ModelState.AddModelError("", "Missing user input"); return View(); } try { this.userService.Register(user); } catch (Exception ex) { this.ModelState.AddModelError("", "An error has occured"); return View(); } return RedirectToAction("Index", "Home"); }
//*************************************************************************************************************************** public void ToAdmin(User user) { user.Admin = true; this.context.Users.Remove(user); this.context.SaveChanges(); this.context.Users.Add(user); this.context.SaveChanges(); }