public BuyMoviePage(int movieId)
 {
     InitializeComponent();
     BindingContext = _viewModel = new BuyMovieViewModel();
     _viewModel.Nav = Navigation;
     _viewModel.Init(movieId);
 }
        private async Task <BuyMovieViewModel> GetPaymentModel(Guid id)
        {
            MovieServiceModel movieModel = await this.movieService.FindMovie(id);

            User user = await userManager.GetUserAsync(HttpContext.User);

            IList <string> roles = await userManager.GetRolesAsync(user);

            string role = roles.SingleOrDefault();

            movieModel.Price = movieModel.Prices.SingleOrDefault(x => x.Role.Name == role).MoviePrice;

            UserBalanceServiceModel userBalanceModel = new UserBalanceServiceModel();

            userBalanceModel = this.userBalanceService.GetUserBalance(user.Id);

            BuyMovieViewModel buyMovieViewModel = new BuyMovieViewModel();

            buyMovieViewModel.Balance   = userBalanceModel.Balance;
            buyMovieViewModel.MovieId   = id;
            buyMovieViewModel.Price     = movieModel.Price;
            buyMovieViewModel.MovieName = movieModel.Name;

            return(buyMovieViewModel);
        }
        public IActionResult BuyMovie(Guid id)
        {
            BuyMovieViewModel buyMovieViewModel = new BuyMovieViewModel();

            buyMovieViewModel.MovieId = id;

            return(View(buyMovieViewModel));
        }
        public async Task <IActionResult> PayFromBalance(BuyMovieViewModel buyMovieViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(buyMovieViewModel));
            }

            User user = await userManager.GetUserAsync(HttpContext.User);

            UserBalanceServiceModel userBalance = this.userBalanceService.GetUserBalance(user.Id);

            if (userBalance.Balance < buyMovieViewModel.Price || userBalance.Balance == 0)
            {
                TempData.AddErrorMessage("You don't have enough money in your account !");

                return(RedirectToAction(nameof(PayFromBalance), new { id = buyMovieViewModel.MovieId }));
            }

            await this.movieService.BuyMovie(user.Id, buyMovieViewModel.MovieId, buyMovieViewModel.Price);

            TempData.AddSuccessMessage($"Your purchase was successful!");

            return(RedirectToAction(nameof(MovieDetails), new { id = buyMovieViewModel.MovieId }));
        }
        public async Task <IActionResult> PayFromBalance(Guid id)
        {
            BuyMovieViewModel buyMovieViewModel = await GetPaymentModel(id);

            return(View(buyMovieViewModel));
        }