public IActionResult CreateMovie(NewMovie form)
        {
            int?UserID = HttpContext.Session.GetInt32("UserID");

            if (UserID is null)
            {
                return(RedirectToAction("Index", "User"));
            }

            if (ModelState.IsValid)
            {
                Movie newMovie = new Movie(form);
                dbContext.Add(newMovie);
                dbContext.SaveChanges();
                return(RedirectToAction("GetMovies"));
            }
            return(View());
        }
Example #2
0
        public IActionResult Registration(RegUser form)
        {
            if (ModelState.IsValid)
            {
                if (dbContext.Users.Any(u => u.Email == form.RegEmail))
                {
                    ModelState.AddModelError("Email", "This Email already exist");
                    return(View("Index"));
                }

                PasswordHasher <RegUser> Hasher = new PasswordHasher <RegUser>();
                form.RegPassword = Hasher.HashPassword(form, form.RegPassword);

                User newUser = new User(form);
                dbContext.Add(newUser);
                dbContext.SaveChanges();

                User UserInfo = dbContext.Users.SingleOrDefault(u => u.Email == form.RegEmail);
                HttpContext.Session.SetInt32("UserID", UserInfo.UserId);

                return(RedirectToAction("Success"));
            }
            return(View("Index"));
        }