Exemplo n.º 1
0
        //[HttpGet]
        //public ActionResult AddToFavorite()
        //{
        //    return this.RedirectToAction("My");
        //}


        public ActionResult AddToFavorite(int id, MovieInputModel model)
        {
            var currentuserid = this.User.Identity.GetUserId();

            var movieToFavorite = this.LoadMovieToComment(id);

            if (movieToFavorite == null) //if cannot load movie
            {
                this.AddNotification("Cannot favorite movie #" + id, NotificationType.ERROR);
                return(this.RedirectToAction("My"));
            }

            if (movieToFavorite.FavoriteMovie != null)
            {
                movieToFavorite.FavoriteMovie = movieToFavorite.FavoriteMovie + currentuserid; //append new user id to existing

                this.db.SaveChanges();
                this.AddNotification("Movie added to favorite.", NotificationType.INFO);
                return(this.RedirectToAction("My"));
            }
            else
            {
                movieToFavorite.FavoriteMovie = currentuserid;
                this.db.SaveChanges();
                this.AddNotification("Movie added to favorite.", NotificationType.INFO);
                return(this.RedirectToAction("My"));
            }
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id, MovieInputModel model)
        {
            var movieToEdit = this.LoadMovie(id);

            if (movieToEdit == null)
            {
                this.AddNotification("Cannot edit movie #" + id, NotificationType.ERROR);
                return(this.RedirectToAction("My"));
            }

            if (model != null && this.ModelState.IsValid)
            {
                movieToEdit.Title         = model.Title;
                movieToEdit.StartDateTime = model.StartDateTime;
                movieToEdit.Duration      = model.Duration;
                movieToEdit.Description   = model.Description;
                movieToEdit.Location      = model.Location;
                movieToEdit.IsPublic      = model.IsPublic;

                this.db.SaveChanges();
                this.AddNotification("Movie edited.", NotificationType.INFO);
                return(this.RedirectToAction("My"));
            }

            return(this.View(model));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Update(string releaseYear, string title,
                                                 [FromBody] MovieInputModel inputModel)
        {
            if (inputModel == null ||
                releaseYear != inputModel.ReleaseYear.ToString() ||
                title != inputModel.Title)
            {
                return(BadRequest());
            }

            if (!await service.MovieExists(releaseYear, title))
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(new UnprocessableObjectResult(ModelState));
            }

            var model = ToDomainModel(inputModel);
            await service.UpdateMovie(model);

            return(NoContent());
        }
Exemplo n.º 4
0
        public ActionResult Create(MovieInputModel model, HttpPostedFileBase file) //създаване на филм и добавяне на снимка
        {
            if (file.ContentLength > 0)
            {
                string fileName = Path.GetFileName(file.FileName);
                string filePath = Path.Combine(Server.MapPath("~/Images"), fileName);
                //първо записвам в папката
                file.SaveAs(filePath);
                //път за записване в колона Image
                string imagePath = "~/Images/" + fileName;
                //  Console.WriteLine(imagePath);


                if (model != null && this.ModelState.IsValid)
                {
                    var e = new Movie()
                    {
                        AuthorId      = this.User.Identity.GetUserId(),
                        Title         = model.Title,
                        StartDateTime = model.StartDateTime,
                        Duration      = model.Duration,
                        Description   = model.Description,
                        Location      = model.Location,
                        IsPublic      = model.IsPublic,
                        Image         = imagePath
                    };

                    this.db.Movies.Add(e);
                    this.db.SaveChanges();
                    this.AddNotification("Movie created.", NotificationType.INFO);
                    return(this.RedirectToAction("My"));
                }
            } //zatwarqm gorniq if
            return(this.View(model));
        }
Exemplo n.º 5
0
        public async Task UpdateMovie(MovieInputModel movie)
        {
            var movieToUpdate = AutoMapperConfig.MapperInstance.Map <Movie>(movie);

            this.movieRepository.Update(movieToUpdate);
            await this.movieRepository.SaveChangesAsync();
        }
Exemplo n.º 6
0
        public async Task <int> CreateMovie(MovieInputModel inputModel)
        {
            // var movieAutoMapped = AutoMapperConfig.MapperInstance.Map<Movie>(inputModel);
            var movie = new Movie
            {
                Title       = inputModel.Title,
                Actors      = inputModel.Actors,
                Description = inputModel.Description,
                Country     = inputModel.Country,
                Director    = inputModel.Director,
                Language    = inputModel.Language,
                Poster      = inputModel.Poster,
                Genre       = inputModel.Genre,
                Rating      = inputModel.Rating,
                Score       = inputModel.Score,
                Trailer     = inputModel.Trailer,
                Duration    = inputModel.Duration,
                ReleaseDate = inputModel.ReleaseDate,
            };

            await this.movieRepository.AddAsync(movie);

            await this.movieRepository.SaveChangesAsync();

            return(movie.Id);
        }
Exemplo n.º 7
0
        public IActionResult Edit(MovieInputModel movie)
        {
            var model = new EditMovieModel("Edit Movie");

            if (movie.Action == FormOptions.Delete)
            {
                model.ErrorMessage = "Can't delete such a great movie";
                model.Id           = movie.Id;
                model.Name         = movie.Name;
            }
            else if (movie.Action == FormOptions.Save)
            {
                model.SuccessMessage = "Movie saved successfully";
                model.Id             = movie.Id;
                model.Name           = movie.Name;
            }
            else if (movie.Action == FormOptions.Add)
            {
                return(RedirectToAction("Index", "Movies", new { success = "Movie added successfully!" }));
            }
            else if (movie.Action == FormOptions.None)
            {
                if (movie.Id == 111)
                {
                    HttpContext.Response.StatusCode = 500;
                    return(Content("Can't save this item"));
                }
                return(Json(new { message = "Added successfully" }));
            }

            return(RedirectToAction("EditResult", model));
        }
Exemplo n.º 8
0
        public async Task CreateMovieWithValidInputData()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MoviesDbTest").Options;

            var dbContext = new ApplicationDbContext(options);

            var repository = new EfRepository <Movie>(dbContext);
            var service    = new MovieService(repository);

            var inputModel = new MovieInputModel
            {
                Title       = "Titanic",
                Actors      = "Test actor, test actor, test actor",
                Country     = MegaCinema.Data.Models.Enums.Country.USA,
                Description = "test description test description",
                Director    = "John West",
                Duration    = new System.TimeSpan(1, 35, 33),
                Genre       = GenreType.Adventure,
                Language    = MegaCinema.Data.Models.Enums.Language.English,
                Poster      = "http://testposter.com",
                Rating      = MPAARating.G,
                ReleaseDate = new System.DateTime(2020, 2, 15),
                Score       = 4.5,
                Trailer     = "sometext",
            };
            var id = await service.CreateMovie(inputModel);

            var movie = repository.All().FirstOrDefault(x => x.Id == id);

            Assert.True(movie.Title == "Titanic");
            Assert.True(movie.Director == "John West");
            Assert.True(movie.Score == 4.5);
        }
Exemplo n.º 9
0
        public IActionResult Create(
            [FromBody] MovieInputModel inputModel,
            [FromHeader(Name = "Accept")] string acceptHeader)
        {
            if (inputModel == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(Unprocessable(ModelState));
            }

            var model = ToDomainModel(inputModel);

            service.AddMovie(model);

            if (string.Equals(acceptHeader, "application/vnd.fiver.hateoas+json"))
            {
                var outputModel = ToOutputModel_Links(model);
                return(CreatedAtRoute("GetMovie", new { id = outputModel.Value.Id }, outputModel));
            }
            else
            {
                var outputModel = ToOutputModel_Default(model);
                return(CreatedAtRoute("GetMovie", new { id = outputModel.Id }, outputModel));
            }
        }
Exemplo n.º 10
0
 public ActionResult AddWithModel(MovieInputModel model)
 {
     return(this.Content(string.Format("Title: {0}, Review: {1}, Length: {2}, Release: {3}",
                                       model.Title,
                                       model.Review,
                                       model.LengthInMinutes,
                                       model.ReleaseDate)));
 }
Exemplo n.º 11
0
        public IActionResult Create()
        {
            var inputModel = new MovieInputModel
            {
                ReleaseDate = DateTime.UtcNow,
            };

            return(this.View(inputModel));
        }
 private Movie ToDomainModel(MovieInputModel inputModel)
 {
     return(new Movie
     {
         Id = inputModel.Id,
         Title = inputModel.Title,
         ReleaseYear = inputModel.ReleaseYear,
         Summary = inputModel.Summary
     });
 }
Exemplo n.º 13
0
        public void ConvertFromAddInputModel(MovieInputModel m)
        {
            Rating   = m.Rating;
            Director = m.Director;
            Stars    = m.Stars;
            Writers  = m.Writers;

            Titel        = m.Titel;
            Omschrijving = m.Omschrijving;
            Highlight    = m.Highlight;
        }
Exemplo n.º 14
0
        private Movie ToDomainModel(MovieInputModel inputModel)
        {
            return(new Movie
            {
                PartitionKey = inputModel.ReleaseYear.ToString(),
                RowKey = inputModel.Title,

                Title = inputModel.Title,
                ReleaseYear = inputModel.ReleaseYear,
                Summary = inputModel.Summary
            });
        }
Exemplo n.º 15
0
 public ActionResult AddMovie(MovieInputModel m, string afbLink, string afbLinkOverview)
 {
     if (ModelState.IsValid)
     {
         Movie mov = new Movie();
         mov.ConvertFromAddInputModel(m); //Maak een Movie van de input
         mov.ItemAfbeelding     = new Afbeelding(mov.ItemID, null, null, afbLink, "filmbanner");
         mov.OverviewAfbeelding = new Afbeelding(mov.ItemID, null, null, afbLinkOverview, "filmoverview");
         db.AddMovie(mov);
         return(RedirectToAction("ManagementWindow"));
     }
     return(View(m));
 }
Exemplo n.º 16
0
        private static async Task Put()
        {
            var model = new MovieInputModel
            {
                Id          = 4,
                Title       = "again",
                ReleaseYear = 1990,
                Summary     = "well"
            };

            var requestUrl = $"{baseUrl}";
            var response   = await HttpRequestFactory.Put(requestUrl, model);
        }
        public async Task <IActionResult> Create(MovieInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            // await moviesService.CreateMovieAsync(inputModel);

            // TempData["CreatedAd"] = SuccessfullyCreatedAdMessage;

            // return RedirectToAction("WaitingForApproval");
            return(this.RedirectToAction("WaitingForApproval"));
        }
Exemplo n.º 18
0
 public ActionResult EditMovie(MovieInputModel movie)
 {
     if (ModelState.IsValid) //Alles goed ingevuld
     {
         Movie movToEdit = db.GetMovie(movie.ItemID);
         movToEdit.ConvertFromMovieInputModel(movie); //Maken van Movie van input model
         db.UpdateMovie(movToEdit);
     }
     else
     {
         ModelState.AddModelError("Edit-error", "The Movie you tried to edit had some incorrectly filled fields.");
     }
     return(View(movie));
 }
        public async Task CreateMovieAsync(MovieInputModel inputModel)
        {
            var movie = this.mapper.Map <Movie>(inputModel);

            // movie.ActorsMovies = Actors
            //    .Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
            //    .ToList();
            // movie.DirectorsMovies = Directors
            //    .Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
            //    .ToList();
            Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry <Movie> entityEntry = await this.context.Movies.AddAsync(movie);

            await this.context.SaveChangesAsync();
        }
Exemplo n.º 20
0
        public void ConvertFromMovieInputModel(MovieInputModel m)
        {
            Rating   = m.Rating;
            Director = m.Director;
            Stars    = m.Stars;
            Writers  = m.Writers;

            Titel                   = m.Titel;
            Omschrijving            = m.Omschrijving;
            Highlight               = m.Highlight;
            ItemID                  = m.ItemID;
            ItemAfbeelding.Link     = m.ItemAfbeelding.Link;
            OverviewAfbeelding.Link = m.OverviewAfbeelding.Link;
        }
Exemplo n.º 21
0
        public ActionResult Edit(int id)
        {
            var movieToEdit = this.LoadMovie(id);

            if (movieToEdit == null)
            {
                this.AddNotification("Cannot edit movie #" + id, NotificationType.ERROR);
                return(this.RedirectToAction("My"));
            }

            var model = MovieInputModel.CreateFromMovie(movieToEdit);

            return(this.View(model));
        }
        public async Task Create_with_invalid_input_model_returns_Unprocessable()
        {
            // Arrange
            var inputModel = new MovieInputModel {
            };
            var content    = new StringContent(JsonConvert.SerializeObject(inputModel),
                                               Encoding.UTF8, "application/json");

            // Act
            var response = await this.Client.PostAsync("api/movies", content);

            // Assert
            Assert.Equal(expected: 422, actual: (int)response.StatusCode);
        }
Exemplo n.º 23
0
        private static async Task Post()
        {
            var model = new MovieInputModel
            {
                Id          = 4,
                Title       = "DD",
                ReleaseYear = 1989,
                Summary     = "GOOD"
            };

            var requestUrl = $"{baseUrl}";
            var response   = await HttpRequestFactory.Post(requestUrl, model);

            var outputModel = response.ContentAsType <MovieOutputModel>();
        }
Exemplo n.º 24
0
        public ActionResult Delete(int id, MovieInputModel model)
        {
            var movieToDelete = this.LoadMovie(id);

            if (movieToDelete == null)
            {
                this.AddNotification("Cannot delete movie #" + id, NotificationType.ERROR);
                return(this.RedirectToAction("My"));
            }

            this.db.Movies.Remove(movieToDelete);
            this.db.SaveChanges();
            this.AddNotification("Movie deleted.", NotificationType.INFO);
            return(this.RedirectToAction("My"));
        }
Exemplo n.º 25
0
 public ActionResult EditMovie(int?id)
 {
     //Get Movie
     if (id != null)
     {
         Movie movie = db.GetMovie(id.Value);
         if (movie != null)
         {
             MovieInputModel mov = new MovieInputModel();
             mov.ConvertToMovieInputModel(movie);
             return(View(mov));
         }
     }
     return(RedirectToAction("ManagementWindow"));
 }
Exemplo n.º 26
0
        private static async Task Put()
        {
            var model = new MovieInputModel
            {
                Id          = 4,
                Title       = "Thunderball-Put",
                ReleaseYear = 1965,
                Summary     =
                    "James Bond heads to The Bahamas to recover two nuclear warheads stolen by SPECTRE agent Emilio Largo in an international extortion scheme."
            };

            var requestUri = $"{baseUri}/4";
            var response   = await HttpRequestFactory.Put(requestUri, model);

            Console.WriteLine($"Status: {response.StatusCode}");
        }
Exemplo n.º 27
0
        public IActionResult Create([FromBody] MovieInputModel inputModel)
        {
            if (inputModel == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(Unprocessable(ModelState));
            }
            var model = ToDomainModel(inputModel);

            _service.AddMovie(model);
            var outputModel = ToOutputModel(model);

            return(CreatedAtRoute("GetMovie", new { id = outputModel.Id }, outputModel));
        }
Exemplo n.º 28
0
        public async Task <IActionResult> Create(MovieInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            if (this.moviesService.MovieTitleExists(inputModel.Title))
            {
                this.ModelState.AddModelError("Title", MovieTitleExists);
                return(this.View(inputModel));
            }

            var movieId = await this.moviesService.CreateMovie(inputModel);

            return(this.RedirectToAction(nameof(this.Details), new { id = movieId }));
        }
Exemplo n.º 29
0
        public IActionResult OnGet(int id)
        {
            var model = this.service.GetMovie(id);

            if (model == null)
            {
                return(RedirectToPage("./Index"));
            }

            this.Movie = new MovieInputModel
            {
                Id          = model.Id,
                Title       = model.Title,
                ReleaseYear = model.ReleaseYear,
                Summary     = model.Summary
            };
            return(Page());
        }
        public async Task Create_with_valid_model_returns_CreatedAtRoute()
        {
            // Arrange
            var inputModel = new MovieInputModel {
                Title = "Spider Man", ReleaseYear = 2017, Summary = "Ok movie"
            };
            var content = new StringContent(JsonConvert.SerializeObject(inputModel),
                                            Encoding.UTF8, "application/json");

            // Act
            var response = await this.Client.PostAsync("api/movies", content);

            // Assert
            Assert.Equal(expected: HttpStatusCode.Created, actual: response.StatusCode);

            var outputModel = response.ContentAsType <MovieOutputModel>();

            Assert.Equal(expected: "Spider Man", actual: outputModel.Title);
        }