Exemple #1
0
        public async Task MakeRent()
        {
            var user = _user.GetUser();

            if (CalculatedCost > user.Balance)
            {
                MessageBox.Show("Nie masz wystarczających środków na koncie.");
            }
            else
            {
                var rental = new VideoRental
                {
                    DateCreated = DateTime.UtcNow,
                    DateStart   = SelectedDateFrom,
                    DateEnd     = SelectedDateTo,
                    Price       = CalculatedCost,
                    VideoId     = Movie.Id,
                    AccountId   = user.Id
                };

                var addRentalResult = await _rentalRepo.AddRental(rental);

                var rechargeBalanceResult = await _accountRepo.RechargeBalance(user.Id, CalculatedCost, false);

                string message = addRentalResult && rechargeBalanceResult ? "Pomyślnie dodano wypożyczenie." : "Wystąpił błąd.\nSpróbuj ponownie";
                MessageBox.Show(message);
            }
        }
Exemple #2
0
        private void rent_Click(object sender, EventArgs e)
        {
            foreach (var video in Rentals)
            {
                var rental = new VideoRental();
                var v      = _unitOfWork.Video.Get(rental.Video.ID);
                if (v.InStock > 0)
                {
                    rental.Customer = Customer;
                    rental.Video    = video;
                    rental.RentDate = DateTime.Now;
                    rental.DueDate  = DateTime.Now.AddDays(DaysRental);
                    rental.Status   = RentalStatus.Rented;
                    _unitOfWork.Rental.Add(rental);

                    //change video stock here
                    v.InStock--;
                    _unitOfWork.Video.Update(v);
                }
            }

            _unitOfWork.Complete();

            rentalList.DataSource = Rentals = new BindingList <Video>();
            this.Close();
        }
Exemple #3
0
        public CustomerDashbordViewModel InsertRental(string VideoID, string CustomerName, string CustomerPhone, string Title)
        {
            VideoRentalAdd            Reposi    = new VideoRentalAdd();
            CustomerDashbordViewModel viewModel = new CustomerDashbordViewModel();
            VideoRental model = new VideoRental();

            model = Reposi.AddRentalVideo(VideoID, CustomerName, CustomerPhone, Title);
            viewModel.videoRentalInsert = model;
            return(viewModel);
        }
        public async Task <bool> AddRental(VideoRental rental)
        {
            bool output = false;

            try
            {
                _context.VideoRentals.Add(rental);
                await _context.SaveChangesAsync();

                output = true;
            }
            catch (Exception) { }

            return(output);
        }
        public void DefaultRentalPriceIsThreeNinetyFive()
        {
            var videoRental = new VideoRental("blah");

            Assert.AreEqual(3.95, videoRental.CalculatePrice());
        }
        public void VideoRatedLessThanFourOnImdbIsDollarOff()
        {
            var videoRental = new VideoRental("tt4458206");

            Assert.AreEqual(2.95, videoRental.CalculatePrice());
        }
        public void VideoRatedEightOrMoreOnImdbIsAnExtraDollar()
        {
            var videoRental = new VideoRental("tt0111161");

            Assert.AreEqual(4.95, videoRental.CalculatePrice());
        }