public IActionResult ProcessRegister(UserRegister model) { if (ModelState.IsValid) { List <User> emails = _dBContext.Users.Where(u => u.Email == model.Email).ToList(); if (emails.Count > 0) { ModelState.AddModelError("Email", "Email already exits"); return(View("Register", model)); } else { //Hash password PasswordHasher <UserRegister> hasher = new PasswordHasher <UserRegister>(); string hashedPassword = hasher.HashPassword(model, model.Password); User newUser = new User { Email = model.Email, Password = hashedPassword, }; _dBContext.Add(newUser); _dBContext.SaveChanges(); HttpContext.Session.SetInt32("loggedUser", newUser.ID); return(RedirectToAction("Index", "Home")); } } return(View("Register", model)); }
public IActionResult CreateLobby(Lobby model, List <string> allTags) { if (LoggedUser() == null) { return(RedirectToAction("Index", "User")); } else { if (ModelState.IsValid) { //Only allow user to create one lobby List <Lobby> userLobbies = _dBContext.Lobbies .Where(lobby => lobby.UserID == LoggedUser()) .ToList(); if (userLobbies.Count > 0) { ModelState.AddModelError("Game Title", "Remove current lobby before creating a new one"); return(View("Index", model)); } else { //Format list all tags into one string string tags = string.Join(" ", allTags); Lobby newLobby = new Lobby { UserID = (int)LoggedUser(), GameTitle = model.GameTitle, Console = model.Console, Gamertag = model.Gamertag, NumPlayers = model.NumPlayers, Description = model.Description, Tags = tags, }; _dBContext.Add(newLobby); _dBContext.SaveChanges(); return(RedirectToAction("Index", "Listing")); } } return(View("Index", model)); } }