示例#1
0
 public IActionResult Create(MovieCreate model)
 {
     if (ModelState.IsValid)
     {
         User   userInDb       = dbContext.Users.FirstOrDefault(u => u.UserId == (int)HttpContext.Session.GetInt32("UserId"));
         string uniqueFileName = null;
         if (model.Image != null)
         {
             string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images");
             uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName;
             string filePath = Path.Combine(uploadsFolder, uniqueFileName);
             model.Image.CopyTo(new FileStream(filePath, FileMode.Create));
         }
         Movie newMovie = new Movie
         {
             Title       = model.Title,
             Year        = model.Year,
             Director    = model.Director,
             Rating      = model.Rating,
             Stars       = model.Stars,
             Description = model.Description,
             Creator     = userInDb,
             ImagePath   = uniqueFileName
         };
         dbContext.Add(newMovie);
         dbContext.SaveChanges();
         return(RedirectToAction("Browse"));
     }
     else
     {
         return(View("Add"));
     }
 }
示例#2
0
 public ActionResult Create(MovieCreate movieCreate)
 {
     if (ModelState.IsValid)
     {
         _db.MovieCreates.Add(movieCreate);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(movieCreate));
 }
示例#3
0
        public async Task EditMovie(int id, MovieCreate editModel)
        {
            var movie = await _dbContext.Movies.FindAsync(id);

            movie.Title       = editModel.Title;
            movie.Author      = editModel.Author;
            movie.ReleaseYear = editModel.ReleaseYear;

            _dbContext.Movies.Add(movie);

            await _dbContext.SaveChangesAsync();
        }
示例#4
0
        public ActionResult Create(MovieCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateMovieService();

            service.CreateMovie(model);

            return(RedirectToAction("Index"));
        }
示例#5
0
        public bool CreateMovie(MovieCreate model)
        {
            var entity = new Movie()
            {
                Title = model.Title
            };

            using (var ctx = new ClassesDbContext())
            {
                ctx.Movies.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public async Task <IActionResult> Post(MovieCreate movie)
        {
            if (ModelState.IsValid)
            {
                await _movieService.CreateAsync(movie);

                return(StatusCode(201));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
示例#7
0
        //setting up movie services for ctor injection
        //private readonly Guid _userId;

        //public MovieService(Guid userId)
        //{
        //    _userId = userId;
        //}

        public bool CreateMovie(MovieCreate movie)
        {
            //ready to map movie into a new Movie
            var entity = new Movie
            {
                // OwnerId = _userId,
                Title = movie.Title
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Movies.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#8
0
        public IHttpActionResult PostMovie(MovieCreate movie)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var service = CreateMovieService();

            if (!service.CreateMovie(movie))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public bool CreateMovie(MovieCreate model)
        {
            var entity =
                new Movie()
            {
                OwnerId     = _userId,
                Title       = model.Title,
                Description = model.Description,
                CreatedUtc  = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Movies.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#10
0
        public async Task <Movie> CreateMovie(MovieCreate createModel)
        {
            Movie movie = new Movie
            {
                Title         = createModel.Title,
                Author        = createModel.Author,
                ReleaseYear   = createModel.ReleaseYear,
                ImagePath     = await _posterData.GetMoviePoster(createModel.ReleaseYear, createModel.Title),
                AverageRating = 0
            };

            await _dbContext.Movies.AddAsync(movie);

            await _dbContext.SaveChangesAsync();

            return(movie);
        }
        //private readonly int _movieId;

        //public MovieService(int movieId)
        //{
        //    _movieId = movieId;
        //}

        public bool CreateMovie(MovieCreate model)
        {
            var entity = new Movie()
            {
                Title          = model.MovieTitle,
                Description    = model.MovieDescription,
                Genre          = model.MovieGenre,
                RunTime        = model.RunTime,
                MaturityRating = model.MovieMaturity
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Movies.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#12
0
        public ActionResult Create(MovieCreate model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Could not add movie, please make sure all fields are filled");
                return(View(model));
            }

            MovieService service = new MovieService();

            if (service.CreateMovie(model))
            {
                return(RedirectToAction("AllMovies"));
            }

            return(View(model));
        }
示例#13
0
        public ActionResult Create(MovieCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var service = CreateMovieService();

            if (service.CreateMovie(model))
            {
                TempData["SaveResult"] = "Your Moive was created";
                return(RedirectToAction("Index"));
            }
            ;
            ModelState.AddModelError("", "Movie could not be created");
            return(View(model));
        }
示例#14
0
        public bool CreateMovie(MovieCreate model)
        {
            var entity =
                new Movie()
            {
                Title       = model.Title,
                Description = model.Description,
                ReleaseDate = model.ReleaseDate,
                CreaterID   = _userId
            };

            using (var context = new ApplicationDbContext())
            {
                context.Movies.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }
示例#15
0
        public bool CreateMovie(MovieCreate model)
        {
            var entity =
                new Movie()
            {
                AuthorId       = _userId,
                Title          = model.Title,
                Description    = model.Description,
                RunTime        = model.RunTime,
                MaturityRating = model.MaturityRating
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Movie.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#16
0
        public async Task <IActionResult> CreateMovie([FromBody] MovieCreate createModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                Movie movie = await _movieData.CreateMovie(createModel);

                return(CreatedAtRoute("GetMovie", new { id = movie.Id }, movie));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public bool CreateMovie(MovieCreate model)
        {
            var entity =
                new Movie()
            {
                OwnerID    = _userId,
                MovieName  = model.MovieName,
                Genre      = model.Genre,
                Director   = model.Director,
                CreatedUtc = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.MovieReviews2.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#18
0
        public bool CreateMovie(MovieCreate model)
        {
            var entity =
                new Movie()
            {
                OwnerId     = _userId,
                Title       = model.Title,
                Description = model.Description,
                Genre       = model.Genre,
                Actors      = model.Actors
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Movies.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#19
0
        public ActionResult Create(MovieCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //var userId = Guid.Parse(User.Identity.GetUserId());
            var service = new MovieService();

            if (service.CreateMovie(model))
            {
                TempData["SaveResult"] = "Your Movie was Created";
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
示例#20
0
        //private readonly Guid _userId;

        //public MovieService(Guid userId)
        //{
        //    _userId = userId;
        //}

        //Create a movie and store it to the Database
        public bool CreateMovie(MovieCreate model)
        {
            var entity = new Movie()
            {
                MovieTitle       = model.MovieTitle,
                MovieDescription = model.MovieDescription,
                MovieRunTime     = model.MovieRunTime,
                Director         = model.Director,
                ReleaseYear      = model.ReleaseYear,
                MovieGenre       = model.MovieGenre,
                MovieRating      = model.MovieRating
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Movies.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#21
0
        public IHttpActionResult Post(MovieCreate movie)
        {
            if (movie is null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var Service      = CreateMovieService();
            var isSuccessful = Service.CreateMovie(movie);

            if (!isSuccessful)
            {
                return(InternalServerError());
            }
            return(Ok("Movie Created"));
        }
示例#22
0
        public bool CreateMovie(MovieCreate model)
        {
            Movie newMovie = new Movie()
            {
                PosterUrl         = model.PosterUrl,
                Title             = model.Title,
                Description       = model.Description,
                ReleaseDate       = model.ReleaseDate,
                Genre             = model.Genre,
                Franchise         = model.Franchise,
                AnticipationValue = model.AnticipationValue
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Movies.Add(newMovie);
                return(ctx.SaveChanges() == 1);
            }
        }
        public bool CreateMovie(MovieCreate model)
        {
            var entity =
                new Movie()
            {
                CustomerID  = _userId,
                MovieName   = model.MovieName,
                Description = model.Description,
                Rating      = model.Rating,
                Producer    = model.Producer,
                CreatedUtc  = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Movies.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#24
0
        public async Task CreateAsync(MovieCreate movieUi)
        {
            var actorIds = new List <Guid>();

            if (movieUi.GenreId == Guid.Empty)
            {
                throw new ArgumentException($"Genre can't be null");
            }

            if (movieUi.FirstActor == Guid.Empty)
            {
                throw new ArgumentException($"Movie should has at least one actor");
            }

            var existedActor = await _actorRepository.FindByAsync(e => e.Id == movieUi.FirstActor);

            if (existedActor == null)
            {
                throw new ArgumentException($"Can't create movie with not existed actor id : {movieUi.FirstActor}");
            }

            var movie = new Movie()
            {
                Genre   = movieUi.Genre,
                GenreId = movieUi.GenreId,
                Id      = Guid.NewGuid(),
                Title   = movieUi.Title,
                Year    = movieUi.Year,
            };

            await _movieRepository.AddAsync(movie);


            //Link movie to actors
            var actorMovie = new ActorMovie()
            {
                ActorId      = movieUi.FirstActor,
                MovieId      = movie.Id,
                ActorMovieId = Guid.NewGuid()
            };

            await _actorMovieRepository.AddAsync(actorMovie);
        }
示例#25
0
        public bool CreateMovie(MovieCreate model)
        {
            var entity =
                new Movie()
            {
                UserId       = _userId,
                Title        = model.Title,
                ReleaseDate  = model.ReleaseDate,
                Description  = model.Description,
                CoverPicture = model.CoverPicture,
                TrailerLink  = model.TrailerLink,
                GenreName    = model.GenreName
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Movies.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#26
0
        public bool CreateMovie(MovieCreate model)
        {
            var entity =
                new Movie()
            {
                OwnerId      = _userId,
                MovieName    = model.MovieName,
                DirectorName = model.DirectorName,
                Duration     = model.Duration,
                DateRelease  = model.DateRelease,
                GenreOfMovie = model.GenreOfMovie,
                CreatedUtc   = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Movies.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#27
0
        public bool CreateMovie(MovieCreate model)
        {
            var entity =
                new Movie()
            {
                OwnerID       = _userID,
                Title         = model.Title,
                MainCast      = model.MainCast,
                Description   = model.Description,
                YearReleased  = model.YearReleased,
                DateWatched   = model.DateWatched,
                IsRecommended = model.IsRecommended,
                CreatedUtc    = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Movies.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#28
0
        public bool CreateMovie(MovieCreate model)
        {
            var entity =
                new Movie()
            {
                CreatorId = _creatorId,
                Title     = model.Title,
                Year      = model.Year,
                Rated     = model.Rated,
                Runtime   = model.Runtime,
                Genre     = model.Genre,
                Director  = model.Director,
                Actors    = model.Actors,
                Plot      = model.Plot
            };

            using (var movie = new ApplicationDbContext())
            {
                movie.Movies.Add(entity);
                var changes = movie.SaveChanges();
                return(changes == 1);
            }
        }
示例#29
0
        public async Task <IActionResult> EditMovie(int id, [FromBody] MovieCreate editModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (!await _movieData.MovieExists(id))
            {
                return(NotFound());
            }

            try
            {
                await _movieData.EditMovie(id, editModel);

                return(NoContent());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
示例#30
0
        public bool CreateMovie(MovieCreate model)
        {
            var entity =
                new Movies()
            {
                MovieId   = model.MovieId,
                Title     = model.Title,
                WatchedIt = model.WatchedIt,
                Sequel    = model.Sequel,
                //WatchLater = model.WatchLater,
                WorthIt     = model.WorthIt,
                MovieLength = model.MovieLength,
                OwnerId     = _movieId,
                TimeTotal   = TimeTotal(model.MovieLength, model.Sequel),

                CreatedUtc = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Movies.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }