Esempio n. 1
0
        public IActionResult GetMovie(OrderDetailsVM getMovie)
        {
            var movie = MovieDatabase.Movies.FirstOrDefault(m => m.Id == getMovie.IdOfMovie);

            if (movie == null)
            {
                return(RedirectToAction("GetMovie", new { error = "There is no movie like that try again" }));
            }

            var user = new User()
            {
                Id        = MovieDatabase.Users.Count + 1,
                FirstName = getMovie.FirstName,
                LastName  = getMovie.LastName,
                Email     = getMovie.Email,
                Phone     = getMovie.Phone
            };

            if (MovieDatabase.Users.SingleOrDefault(u => u.Email.ToLower().Trim() == user.Email.ToLower().Trim()) == null)
            {
                MovieDatabase.Users.Add(user);
            }


            var stats = new OrderMovieStatsHistory()
            {
                Id      = MovieDatabase.Orders.Count + 1,
                MovieId = movie.Id,
                UserId  = user.Id
            };

            MovieDatabase.Orders.Add(stats);

            return(View("BuyingComplete"));
        }
 public static OrderMovieStatsDto MapOrderToOrderMovieStatsDtoModel(OrderMovieStatsHistory order, Movie movie, User user)
 {
     return(new OrderMovieStatsDto()
     {
         OrderId = order.Id,
         Movie = MapMovieToMovieDtoModel(movie),
         User = MapUserToUserDtoModel(user)
     });
 }
Esempio n. 3
0
        public ResultsWrapperHelper MovieById(OrderDetailsVM orderDetails)
        {
            var movie  = _movieRepository.GetById(orderDetails.IdOfMovie);
            var helper = new ResultsWrapperHelper();

            helper.OrderDetailsVM = orderDetails;

            if (movie == null)
            {
                helper.Message = "There is no movie like that, try again";
                return(helper);
            }

            var user = MapperHelper.MapOrderDetailsVmToUserModel(orderDetails);

            if (string.IsNullOrEmpty(user.Email))
            {
                helper.Message = "You must have valid email";
                return(helper);
            }

            if (_userRepository.GetAll()
                .SingleOrDefault(u => u.Email.ToLower().Trim() == user.Email.ToLower().Trim()) == null)
            {
                _userRepository.AddEntity(user);
            }
            var stats = new OrderMovieStatsHistory()
            {
                MovieId = movie.Id,
                UserId  = user.Id
            };

            _orderRepository.AddEntity(stats);

            return(helper);
        }