public IActionResult NewLike(int UserId, int PostId) { int?userId = HttpContext.Session.GetInt32("UserId"); if (userId.HasValue) { Like exists = _context2.likes.SingleOrDefault(like => like.UserId == UserId && like.PostId == PostId); if (exists == null) { Like newLike = new Like() { PostId = PostId, UserId = UserId }; _context2.Add(newLike); _context2.SaveChanges(); } return(Redirect($"/bright_ideas")); } else { return(Redirect("/main")); } }
public IActionResult InviteUser(int UserID) { Invitation NewInvitation = new Invitation(); NewInvitation.InviterID = (int)HttpContext.Session.GetInt32("UserID"); NewInvitation.UserID = UserID; _context.Invitations.Add(NewInvitation); _context.SaveChanges(); return(RedirectToAction("Users", "Network")); }
public IActionResult Registration(UserViewModel model, User newUser) { if (ModelState.IsValid) { User exists = _context.users.SingleOrDefault(user => user.Email == newUser.Email); if (exists == null) { PasswordHasher <User> Hasher = new PasswordHasher <User>(); newUser.Password = Hasher.HashPassword(exists, model.Password); _context.users.Add(newUser); _context.SaveChanges(); HttpContext.Session.SetInt32("UserId", newUser.UserId); // TempData.name = $"{newUser.FirstName} {newUser.LastName}"; return(Redirect("/bright_ideas")); } else { ViewBag.error_exists = "This email already exists in the database. Try Logging in."; return(View("Index")); } } else { return(View("Index")); } }
public IActionResult Register(UserViewModel model) { User CheckUser = _context.Users.SingleOrDefault(user => user.Email == model.Email); if (CheckUser != null) { ViewBag.err = "Email is already in use."; } else if (ModelState.IsValid) { User NewUser = new User(); NewUser.Name = model.Name; NewUser.Email = model.Email; NewUser.Password = model.Password; NewUser.Description = model.Description; _context.Users.Add(NewUser); _context.SaveChanges(); User LoggedUser = _context.Users.SingleOrDefault(user => user.Email == model.Email); HttpContext.Session.SetInt32("UserID", LoggedUser.UserID); return(RedirectToAction("Dashboard", "Network")); } return(View("Index")); }