Пример #1
0
        public IActionResult CreateMovie(MovieViewModel model)
        {
            decimal discountCalc    = model.DiscountPercent / 100;
            decimal discountedPrice = model.Price - (discountCalc * model.Price);

            ImageUpload imageUpload = new(_webHostEnvironment);

            string uniqueFilename = imageUpload.UploadedFile(model.Picture);

            //string uniqueFileName =

            Premiere premiere = new();

            premiere.Discount     = discountedPrice;
            premiere.PremiereDate = model.ReleaseDate;
            premiere.EndDate      = model.ReleaseDate.AddDays(model.DaysPremiere);

            _sqlPremiereService.CreatePremiere(premiere);

            Movie movie = new();

            movie.Picture     = uniqueFilename;
            movie.Name        = model.Name;
            movie.Price       = model.Price;
            movie.ReleaseDate = model.ReleaseDate;
            movie.MovieRating = model.MovieRating;
            movie.Category    = model.Category;
            movie.PremiereId  = premiere.Id;

            _sqlMovieService.CreateMovie(movie);

            return(RedirectToAction(nameof(Index)));
        }
Пример #2
0
        public void CreatePremiere_ShouldPersist()
        {
            //Arrange
            Premiere premiere = new()
            {
                Discount     = 20M,
                Movie        = new Movie(),
                EndDate      = DateTime.Now,
                PremiereDate = DateTime.Now
            };

            //Act
            _sqlPremiereService.CreatePremiere(premiere);

            //Assert
            List <Premiere> premieres = _dbContext.Premiere.ToList();

            Assert.AreEqual(1, premieres.Count);
            Assert.AreEqual(premiere.Id, premieres[0].Id);
            Assert.AreEqual(premiere.Discount, premieres[0].Discount);
        }
    }