public IActionResult Create(RegisterViewModel RegisterUser) { if (ModelState.IsValid) { PasswordHasher <Users> Hasher = new PasswordHasher <Users>(); Users NewUser = new Users(); NewUser.Password = Hasher.HashPassword(NewUser, RegisterUser.Password); NewUser.FirstName = RegisterUser.FirstName; NewUser.LastName = RegisterUser.LastName; NewUser.Email = RegisterUser.Email; NewUser.Description = RegisterUser.Description; NewUser.CreatedAt = DateTime.Now; NewUser.UpdatedAt = DateTime.Now; _context.Add(NewUser); _context.SaveChanges(); //taking the last user that was put into the database and setting into a session int CurrentUser = _context.Users.Last().idUser; HttpContext.Session.SetInt32("CurrentUser", CurrentUser); return(Redirect("Dashboard")); } else { return(View("Index", RegisterUser)); } }
public IActionResult Invite(int id) { if (HttpContext.Session.GetString("CurrentUser") == null) { return(RedirectToAction("loginpage")); } else { int?CurrentUser = HttpContext.Session.GetInt32("CurrentUser"); Invite newInvite = new Invite { AccepterId = id, RequesterId = (int)CurrentUser, }; _context.Add(newInvite); _context.SaveChanges(); return(RedirectToAction("Network")); } }