public ScannedRecieptPage() { InitializeComponent(); BindingContext = viewModel = new RecieptVM(); MessagingCenter.Subscribe <ScanQRPage, Reciept>(this, "RecieptScanned", async(obj, reciept) => { this.viewModel.ScannedReciepts.Add(reciept); }); }
public RecieptVM CreateReciept(int id) { var order = context.Orders.First(o => o.BookingNr == id); var car = context.Cars.First(c => c.Id == order.CarId); var customer = context.Customers.First(k => k.CustomerId == order.CustomerId); int baseDayRental = 400; int kmPrice = 5; double totalPrice = 0; int drivenMiles = order.DrivenMiles; double totalDays = (order.ReturnDate.Date - order.PickUpDate.Date).TotalDays; string carType = car.CarType; customer.TimesRented += 1; customer.MilesDriven += order.DrivenMiles; context.SaveChanges(); if (customer.Vipstatus != 3) { UpdateVipStatus(customer); } int vipLevel = CheckVipStatus(customer); if (vipLevel > 0) { baseDayRental /= 2; } if (vipLevel > 1 && totalDays == 3) { totalDays = 2; } if (vipLevel > 1 && totalDays >= 4) { totalDays -= 2; } if (vipLevel > 2 && drivenMiles > 20) { drivenMiles -= 20; } switch (carType) { case "Small Car": totalPrice = totalDays * baseDayRental; break; case "Minibus": totalPrice = totalDays * (baseDayRental * 1.2) + (order.DrivenMiles * kmPrice); break; case "Van": totalPrice = totalDays * (baseDayRental * 1.7) + (order.DrivenMiles * kmPrice * 1.5); break; default: break; } RecieptVM reciept = new RecieptVM { BookingNr = order.BookingNr, CarType = car.CarType, RegNr = car.RegNr, PickUpDate = (DateTime)order.PickUpDate, ReturnDate = order.ReturnDate, MileageOnPickup = order.CurrentMileage, MileageOnReturn = order.MileageOnReturn, DrivenMiles = order.DrivenMiles, DaysRented = totalDays, TotalPrice = totalPrice, CustomerId = customer.CustomerId, Ssn = customer.Ssn, FirstName = customer.FirstName, LastName = customer.LastName }; return(reciept); }
public RecieptsPage() { InitializeComponent(); BindingContext = viewModel = new RecieptVM(); }