public IActionResult Delete(int WeddingId) { Wedding deleteTarget = _context.Weddings.SingleOrDefault( w => w.UserId == (int)HttpContext.Session.GetInt32("UserId") && w.WeddingID == WeddingId); if (deleteTarget != null) { _context.Weddings.Remove(deleteTarget); _context.SaveChanges(); } return(RedirectToAction("Show", "Login")); }
public IActionResult addUser(RegisterViewModel newUser) { if (ModelState.IsValid) { User ThisUser = _context.RSVPS.SingleOrDefault(user => user.Email == newUser.Email); if (ThisUser != null) { ViewBag.Message = "A user with this email already exists. Try another."; return(View("login")); } User userAdded = new User { UserFirstName = newUser.FirstName, UserLastName = newUser.LastName, Email = newUser.Email, Password = newUser.Password, CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow }; _context.Add(userAdded); _context.SaveChanges(); userAdded = _context.RSVPS.SingleOrDefault(user => user.Email == userAdded.Email); HttpContext.Session.SetInt32("UserId", userAdded.UserId); ViewBag.UserId = userAdded.UserId; return(RedirectToAction("Show")); } else { return(View("/")); } }