public IActionResult CreateNewWedding(Wedding new_wedding)
        {
            User userinsesh = db.Users.FirstOrDefault(user => user.UserId == HttpContext.Session.GetInt32("UserId"));

            if (!isLoggedIn)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (ModelState.IsValid)
            {
                new_wedding.Creator = userinsesh;
                db.Add(new_wedding);
                db.SaveChanges();
                return(RedirectToAction("Dashboard", new_wedding));
            }
            return(View("NewWedding"));
        }
Esempio n. 2
0
 public IActionResult CreateNewWedding(Wedding new_wedding)
 {
     if (!isLoggedIn)
     {
         return(RedirectToAction("Index", "Home"));
     }
     if (ModelState.IsValid)
     {
         db.Add(new_wedding);
         db.SaveChanges();
         return(RedirectToAction("Dashboard", new_wedding));
     }
     return(View("NewWedding"));
 }
        public IActionResult Register(User newUser)
        {
            if (ModelState.IsValid)
            {
                if (db.Users.Any(user => user.Email == newUser.Email))
                {
                    ModelState.AddModelError("Email", "Email is already in use");
                    return(View("Index")); //to display error messages
                }
                // hash pw
                PasswordHasher <User> hasher = new PasswordHasher <User>();
                newUser.Password = hasher.HashPassword(newUser, newUser.Password);

                db.Add(newUser);
                db.SaveChanges();

                HttpContext.Session.SetInt32("UserId", newUser.UserId);
                return(RedirectToAction("Dashboard", "Wedding", new { userId = newUser.UserId }));
            }
            else
            {
                return(View("Index")); //to display error messages
            }
        }