Example #1
0
        public void CalculateFree()
        {
            Bike bike = new Bike
            {
                RentalPriceFirstHour = 3,
                RentalPriceAddHour   = 5,
                Id = 1
            };


            Customer customer = new Customer
            {
                Id = 1
            };
            Rental r = new Rental
            {
                Begin      = new DateTime(2018, 02, 14, 8, 15, 0),
                End        = new DateTime(2018, 02, 14, 8, 25, 0),
                Id         = 1,
                Customer   = customer,
                CustomerID = customer.Id,
                Bike       = bike,
                BikeID     = bike.Id
            };

            r.TotalCosts = CostCalculation.CalculateTotalCost(r);
            Assert.Equal(0, r.TotalCosts, 1);
        }
Example #2
0
        private void checkoutButton_Click(object sender, RoutedEventArgs e)
        {
            if (customMiniMenuBlockList.Count != 0)
            {
                OrderAccounting orderAccounting = new OrderAccounting();

                CardLoyality card = new CardLoyality();

                using (SQLiteConnection con = new SQLiteConnection(App.databasePath))
                {
                    card = con.Table <CardLoyality>().Where(x => x.CardLoyalityID == App.currentUser.CardLoyality)
                           .FirstOrDefault();
                }

                double costWithDiscount = CostCalculation.GetCostWithDiscount(card.Score);

                orderAccounting.Cost        = costWithDiscount;
                orderAccounting.TableNumber = 99; // Need to fix
                orderAccounting.IsActive    = true;
                orderAccounting.Date        = DateTime.Now.ToString("dd/MM/yyyy");

                string temp    = String.Empty;
                string message = String.Empty;

                foreach (var dish in customMiniMenuBlockList)
                {
                    card.Score += dish.Count;
                    string buffer  = dish.Dish.Name + "_" + dish.Count;
                    string mbuffer = dish.Dish.Name + " кол-во " + dish.Count;

                    if (temp == String.Empty)
                    {
                        temp    = buffer;
                        message = mbuffer;
                    }
                    else
                    {
                        temp    += ", " + buffer;
                        message += "\n" + mbuffer;
                    }
                }

                orderAccounting.Dish = temp;

                message += "\n\n Цена cо скидкой: " + costWithDiscount + "руб.";

                var result = MessageBox.Show(message, "Заказ", MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.OK)
                {
                    using (SQLiteConnection con = new SQLiteConnection(App.databasePath))
                    {
                        ServiceHelper.Core.DataHandler.AddIncome(costWithDiscount);
                        con.Insert(orderAccounting, typeof(OrderAccounting));
                        con.Update(card, typeof(CardLoyality));
                    }
                }
            }
        }
Example #3
0
        public void TestCalculation()
        {
            CostCalculation _calc = new CostCalculation();
            var             price = _calc.CalculateCost(new DateTime(2019, 2, 14, 8, 15, 0), new DateTime(2019, 2, 14, 10, 30, 0), 3, 5);

            Assert.Equal(13, price);

            price = _calc.CalculateCost(new DateTime(2018, 2, 14, 8, 15, 0), new DateTime(2018, 2, 14, 8, 45, 0), 3, 100);
            Assert.Equal(3, price);

            price = _calc.CalculateCost(new DateTime(2018, 2, 14, 8, 15, 0), new DateTime(2018, 2, 14, 8, 25, 0), 20, 100);
            Assert.Equal(0, price);
        }
Example #4
0
        public void CalculateTotalCosts_MultiHours()
        {
            Bike b = new Bike {
                ID = 1, BikeCategory = Bike.BikeCategoryEnum.Mountain, Brand = "KTM", DateService = DateTime.Now, PurchaseDate = DateTime.Now, PriceAddHour = 5, PriceHour = 3
            };
            Customer c = new Customer {
                ID = 1, Birthday = DateTime.Now, FirstName = "Max", LastName = "Mustermann", Gender = Customer.GenderEnum.Male, HouseNumber = "10", Street = "Musterstraße", Town = "Musterstadt", ZIP = 1234
            };
            Rental r = new Rental {
                ID = 1, BikeID = 1, Bike = b, CustomerID = 1, Customer = c, PaidFlag = false, RentalBegin = DateTime.Parse("14/02/2018 08:15:00"), RentalEnd = DateTime.Parse("14/02/2018 10:30:00")
            };

            CostCalculation cc  = new CostCalculation();
            double          act = cc.CalculateTotalCosts(r);

            Assert.Equal(13, act);
        }
Example #5
0
        public async Task <ActionResult <Rental> > EndRental(int id)
        {
            var rental = await _context.Rentals.Where(r => r.ID == id).Include(r => r.Bike).FirstAsync();

            if (rental == null)
            {
                return(NotFound());
            }
            else if (rental.PaidFlag || !rental.RentalEnd.ToString().Equals("01/01/0001 00:00:00"))
            {
                return(BadRequest());
            }
            else
            {
                CostCalculation cc = new CostCalculation();
                rental.RentalEnd = DateTime.Now;
                rental.TotalCost = cc.CalculateTotalCosts(rental);
                _context.Update(rental);
                await _context.SaveChangesAsync();
            }

            return(rental);
        }
Example #6
0
        public async Task <ActionResult> EndRental([FromBody] Rental rental)
        {
            try
            {
                var startedRental = await Context.Rentals.FirstAsync(b => b.CustomerID == rental.CustomerID && b.BikeID == rental.BikeID && b.End == DateTime.MinValue);

                startedRental.End        = System.DateTime.Now;
                startedRental.TotalCosts = CostCalculation.CalculateTotalCost(startedRental);
                startedRental.Customer   = await Context.Customers.FindAsync(rental.CustomerID);

                startedRental.Bike = await Context.Bikes.FindAsync(rental.BikeID);

                Context.Rentals.Update(startedRental);
                //Context.Rentals.Add(startedRental);

                await Context.SaveChangesAsync();

                return(Ok(startedRental));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }