Example #1
0
        public async Task <IActionResult> Post([FromBody] MovieOrderViewModel movieOrderVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var movieOrder = _mapper.Map <MovieOrderViewModel, MovieOrder>(movieOrderVM);


                    var loggedInUser = await _userManager.FindByNameAsync(User.Identity.Name);

                    movieOrder.User = loggedInUser;

                    _movieRepository.AddMovieOrder(movieOrder);
                    if (_movieRepository.Save())
                    {
                        return(Created($"/api/movieorders/{movieOrder.Id}", _mapper.Map <MovieOrder, MovieOrderViewModel>(movieOrder)));
                    }
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to save record: {ex}");
            }
            return(BadRequest("Failed to save record"));
        }
Example #2
0
        public ActionResult Index(string email)
        {
            var orders = _movieOrdersLogic.GetUserMovieOrders(email);

            var movieOrderViewModels = new List <MovieOrderViewModel>();

            foreach (var entry in orders)
            {
                var movieOrderModal = new MovieOrderViewModel()
                {
                    ID = entry.ID,
                    RentalStartTimeStamp = entry.RentalStartTimeStamp,
                    RentedMovieId        = entry.RentedMovieId,
                    Email = email
                };

                var movie          = _moviesLogic.GetMovie(entry.RentedMovieId);
                var movieViewModel = ModelMapper.MapFromMovieBLLModelToMovieViewModel(movie);

                movieOrderModal.RentedMovie = movieViewModel;
                movieOrderViewModels.Add(movieOrderModal);
            }

            return(View(movieOrderViewModels));
        }