public IActionResult Registration(RegisterViews ruser) { if (ModelState.IsValid) { List <User> isuser = _context.users.Where(useri => useri.Email == ruser.Email).ToList(); if (isuser.Count() > 0) { string message = "There is already another user with this email!Please use other email!"; ViewBag.message = message; return(View("Register")); } List <User> allusers = _context.users.ToList(); User neWuser = new User() { FirstName = ruser.FirstName, LastName = ruser.LastName, Email = ruser.Email, Password = ruser.Password, }; if (allusers.Count() == 0) { neWuser.Status = "Admin"; } _context.users.Add(neWuser); _context.SaveChanges(); } List <User> users = _context.users.ToList(); HttpContext.Session.SetInt32("Session", users[users.Count() - 1].UserId); return(RedirectToAction("ManageUsers", "Home")); }
public IActionResult Register(RegisterViews ruser) { if (ModelState.IsValid) { List <User> isuser = _context.users.Where(useri => useri.Email == ruser.Email).ToList(); if (isuser.Count() > 0) { string message = "There is already another user with this email!Please use other email!"; ViewBag.message = message; return(View("Index")); } User NewUser = new User { FirstName = ruser.FirstName, LastName = ruser.LastName, Email = ruser.Email, Password = ruser.Password }; _context.users.Add(NewUser); _context.SaveChanges(); List <User> user = _context.users.ToList(); int id = user[user.Count() - 1].UserId; HttpContext.Session.SetInt32("session_user", id); return(RedirectToAction("AddRecord", new { uid = id })); } return(View("Index")); }
public async Task <IActionResult> Edit(string id, [Bind("Id,FirstName,LastName,Age,Email")] RegisterViews registerViews) { if (id != registerViews.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(registerViews); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RegisterViewsExists(registerViews.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(registerViews)); }
public IActionResult SaveInfo(RegisterViews reg, int id) { User user = _context.users.SingleOrDefault(u => u.UserId == id); user.FirstName = reg.FirstName; user.LastName = reg.LastName; user.Email = reg.Email; user.Status = reg.Status; _context.SaveChanges(); return(RedirectToAction("EditById")); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Age,Email")] RegisterViews registerViews) { if (ModelState.IsValid) { _context.Add(registerViews); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(registerViews)); }
public IActionResult SaveInfo(RegisterViews reg) { Console.WriteLine("%%%%%%%%%%%%%%%%%%" + reg); int id = Convert.ToInt32(HttpContext.Session.GetInt32("Session")); User user = _context.users.SingleOrDefault(u => u.UserId == id); user.FirstName = reg.FirstName; user.LastName = reg.LastName; user.Email = reg.Email; _context.SaveChanges(); return(RedirectToAction("Edit")); }
public IActionResult SavePassword(RegisterViews reg, int id) { User user = _context.users.SingleOrDefault(u => u.UserId == id); if (reg.Password != reg.PasswordConfirmation) { ViewBag.error = "Password and password confirmation do not match!"; ViewBag.user = user; return(View("EditById")); } else { user.Password = reg.Password; _context.SaveChanges(); } return(RedirectToAction("EditById")); }
public IActionResult SavePassword(RegisterViews reg) { int id = Convert.ToInt32(HttpContext.Session.GetInt32("Session")); User user = _context.users.SingleOrDefault(u => u.UserId == id); if (reg.Password != reg.PasswordConfirmation) { ViewBag.error = "Password and password confirmation do not match!"; ViewBag.user = user; return(View("Edit")); } else { user.Password = reg.Password; _context.SaveChanges(); } return(RedirectToAction("Edit")); }
public IActionResult AddUser(RegisterViews ruser) { if (ModelState.IsValid) { List <User> isuser = _context.users.Where(useri => useri.Email == ruser.Email).ToList(); if (isuser.Count() > 0) { string message = "There is already another user with this email!Please use other email!"; ViewBag.message = message; return(View("New")); } User neWuser = new User() { FirstName = ruser.FirstName, LastName = ruser.LastName, Email = ruser.Email, Password = ruser.Password, }; _context.users.Add(neWuser); _context.SaveChanges(); return(RedirectToAction("ManageUsers", "Home")); } return(View("New")); }