Exemple #1
0
        public IActionResult Login(LoginUser user)
        {
            var test = dbContext.Users.ToList();

            if (ModelState.IsValid)
            {
                WeddingUser toLogin = dbContext.Users.FirstOrDefault(u => u.Email == user.EmailAttempt);
                if (toLogin == null)
                {
                    ModelState.AddModelError("EmailAttempt", "Invalid Email/Password");
                    return(View("Index"));
                }
                PasswordHasher <LoginUser> hasher = new PasswordHasher <LoginUser> ();
                var result = hasher.VerifyHashedPassword(user, toLogin.Password, user.PasswordAttempt);
                if (result == PasswordVerificationResult.Failed)
                {
                    ModelState.AddModelError("EmailAttempt", "Invalid Email/Password");
                    return(View("Index"));
                }
                // Log user into session
                HttpContext.Session.SetInt32("userId", toLogin.UserId);
                return(RedirectToAction("Index", "Wedding"));
            }
            return(View("Index"));
        }
Exemple #2
0
        public IActionResult LeaveWedding(int wId)
        {
            int?        id     = HttpContext.Session.GetInt32("UserId");
            int         uid    = Convert.ToInt32(id);
            WeddingUser mjoins = _context.WeddingGuest.SingleOrDefault(w => w.WeddingId == wId && w.UserId == uid);

            _context.WeddingGuest.Remove(mjoins);
            _context.SaveChanges();
            return(RedirectToAction("dashboard"));
        }
Exemple #3
0
        public IActionResult CancelRSVP(int weddingId)
        {
            User LoggedUser = ReturnLoggedUser();

            WeddingUser cancelRSVP = _context.rsvps.Where(r => r.weddingId == weddingId).Where(r => r.userId == LoggedUser.userId).SingleOrDefault();

            _context.Remove(cancelRSVP);
            _context.SaveChanges();

            ViewBag.LoggedUser = ReturnLoggedUser();

            return(RedirectToAction("WeddingIndex"));
        }
Exemple #4
0
        public IActionResult JoinWedding(int wId)
        {
            int?        id   = HttpContext.Session.GetInt32("UserId");
            int         uid  = Convert.ToInt32(id);
            WeddingUser join = new WeddingUser()
            {
                UserId    = uid,
                WeddingId = wId
            };

            _context.WeddingGuest.Add(join);
            _context.SaveChanges();
            return(RedirectToAction("dashboard"));
        }
Exemple #5
0
        public IActionResult RSVP(int weddingId)
        {
            User LoggedUser = ReturnLoggedUser();

            WeddingUser newRSVP = new WeddingUser
            {
                weddingId = weddingId,
                userId    = LoggedUser.userId
            };

            _context.Add(newRSVP);
            _context.SaveChanges();

            ViewBag.LoggedUser = ReturnLoggedUser();

            return(RedirectToAction("WeddingIndex"));
        }
Exemple #6
0
        public IActionResult Create(WeddingUser user)
        {
            if (ModelState.IsValid)
            {
                if (dbContext.Users.Any(o => o.Email == user.Email))
                {
                    ModelState.AddModelError("Email", "Email already in use");
                    return(View("Index"));
                }

                PasswordHasher <WeddingUser> hasher = new PasswordHasher <WeddingUser> ();
                user.Password = hasher.HashPassword(user, user.Password);

                var newUser = dbContext.Users.Add(user).Entity;
                dbContext.SaveChanges();

                HttpContext.Session.SetInt32("userId", newUser.UserId);

                return(RedirectToAction("Index", "Wedding"));
            }

            return(View("Index"));
        }