Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,Type,MovieId")] Genre genre, string movies = null)
        {
            if (HttpContext.Session.GetString("Type") == null || HttpContext.Session.GetString("Type") != "Admin")
            {
                ViewBag.error = 401;
                return(View("ClientError"));
            }
            if (_context.Genre.Any(g => g.Type == genre.Type))
            {
                ViewBag.error = 400;
                return(View("ClientError"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(genre);
                await _context.SaveChangesAsync();

                if (movies != null)               // If any movie is added/removed
                {
                    EditMovies(movies, genre.Id); // Add or remove the selected Movie
                }
                return(RedirectToAction("Dashboard", "Users"));
            }
            return(View(genre));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,Headline,Content,Rating,Published")] Review review, int movieid)
        {
            if (HttpContext.Session.GetString("Type") == null)    // User not logged
            {
                ViewBag.error = 401;
                return(View("ClientError"));
            }
            if (ModelState.IsValid)
            {
                review.Published = DateTime.Now;
                review.Movie     = _context.Movie.FirstOrDefault(m => m.Id == movieid);
                if (review.Movie == null)
                {
                    ViewBag.error = 400;
                    return(View("ClientError"));
                }
                if (HttpContext.Session.GetString("UserId") == null)     // Check if any user is connected
                {
                    ViewBag.error = 400;
                    return(View("ClientError"));
                }
                int userid = int.Parse(HttpContext.Session.GetString("UserId"));    // get the id of Connected user
                review.Author = _context.User.FirstOrDefault(u => u.Id == userid);
                if (review.Author == null)
                {
                    ViewBag.error = 400;
                    return(View("ClientError"));
                }
                _context.Add(review);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Movies", new { id = movieid }));
            }
            return(View(review));
        }
Esempio n. 3
0
        public async Task <IActionResult> Register(string username, string password, string Email, string FirstName = null, string LastName = null, string Address = null, string type = "Customer")
        {
            User account = new User()
            {
                UserName = username, Password = password, FirstName = FirstName, LastName = LastName, Address = Address, Email = Email
            };

            if (type == "Customer")
            {
                account.Type = UserType.Customer;
            }
            else
            {
                account.Type = UserType.Admin;
            }
            var user = _context.User.FirstOrDefault(u => u.UserName == username);

            if (user == null)   // If username doesn't exist
            {
                _context.Add(account);
                await _context.SaveChangesAsync();

                SignIn(account);
                return(RedirectToAction("HomePage", "Movies"));
            }
            ViewBag.error = 400; // Username exist
            return(View("ClientError"));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("MovieId,ActorId")] MovieActor movieActor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movieActor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData ["ActorId"] = new SelectList(_context.Actor, "Id", "Id", movieActor.ActorId);
            ViewData ["MovieId"] = new SelectList(_context.Movie, "Id", "Name", movieActor.MovieId);
            return(View(movieActor));
        }
        public async Task <IActionResult> Create([Bind("UserId,GenreId,Weight")] UserGenre userGenre)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userGenre);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GenreId"] = new SelectList(_context.Genre, "Id", "Type", userGenre.GenreId);
            ViewData["UserId"]  = new SelectList(_context.User, "Id", "Address", userGenre.UserId);
            return(View(userGenre));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("Id,Name,ReleaseDate,Duration,Director,Poster,Trailer,Storyline,AverageRating,imdbID")] Movie movie, string genres = null, string actors = null)
        {
            if (HttpContext.Session.GetString("Type") == null || HttpContext.Session.GetString("Type") != "Admin")       // User not logged or it's not Admin
            {
                ViewBag.error = 401;
                return(View("ClientError"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                if (genres != null)               // If any genre is added/removed
                {
                    EditGenres(genres, movie.Id); // Add or remove the selected Genres
                }
                if (actors != null)               // If any actor is added/removed
                {
                    EditActors(actors, movie.Id); // Add or remove the selected Genres
                }
                return(RedirectToAction("Dashboard", "Users"));
            }
            return(View(movie));
        }