private void PayDeposit() { int id; var valid = int.TryParse(DamageDepositId, out id); if (!valid) { return; } _context.DamageDeposits_tbl.First(r => r.Id == id).Paid = true; _context.SaveChanges(); }
private void CreateCompany() { var newCompany = new InsuranceCompany() { Name = NewCompanyName, ContactNumber = NewCompanyNumber }; _context.InsuranceCompanies_tbl.Add(newCompany); _context.SaveChanges(); InsuranceCompanies = new ObservableCollection <InsuranceCompany>(_context.InsuranceCompanies_tbl.ToList()); NewCompanyName = ""; NewCompanyNumber = ""; }
private void AddStock() { // do checks int newStock; var newStockValid = int.TryParse(StockToAdd, out newStock); if (!newStockValid) { return; } if (SelectedEquipmentId == -1) { return; } // get equipment _context.Equipment_tbl.First(r => r.Id == SelectedEquipmentId).Stock += newStock; StockToAdd = ""; _context.SaveChanges(); }
private void CreateCustomer() { var newCustomer = new Customer() { FirstName = InputFirstName, Surname = InputSurname, AddressLine1 = InputAddress1, AddressLine2 = InputAddress2, ContactNumber = InputContactNumber, Postcode = InputPostcode }; _context.Customers_tbl.Add(newCustomer); _context.SaveChanges(); }
private void Book() { // Validate id int id; var idValid = int.TryParse(CustomerId, out id); if (!idValid) { return; } // Validate type id if (SelectedType <= 0) { return; } // Check dates in order if (ToDate.Ticks < FromDate.Ticks) { return; } // Check availability int vehicleId; var vehicleAvailable = _vehicleAvailability.FindAvailableVehicle(FromDate, ToDate, SelectedType, out vehicleId); if (!vehicleAvailable) { return; } // checks done, send it var newDamageDeposit = new DamageDeposit() { Paid = false, Refunded = false, Price = 140 }; _context.DamageDeposits_tbl.Add(newDamageDeposit); _context.SaveChanges(); // Get price var price = _priceCalculator.CalculatePrice(FromDate, ToDate, vehicleId); var newBooking = new Booking() { CustomerId = id, AmountPaid = 0, StartDate = FromDate, EndDate = ToDate, DamageDepositId = newDamageDeposit.Id, VehicleId = vehicleId, Price = price }; _context.Bookings_tbl.Add(newBooking); _context.SaveChanges(); CustomerId = ""; }
private void MakeSale() { // Validate user id int id; var idValid = int.TryParse(CustomerId, out id); if (!idValid) { return; } // Check user exists var userExists = _context.Customers_tbl.Any(r => r.Id == id); if (!userExists) { return; } // Validate the quantity int quantity; var quantityValid = int.TryParse(Quantity, out quantity); if (!quantityValid) { return; } // Validate the equipment if (SelectedEquipment <= 0) { return; } // Check equipment exists var equipmentExists = _context.Equipment_tbl.Any(r => r.Id == id); if (!equipmentExists) { return; } // Check theres enough in stock var enoughStock = _context.Equipment_tbl.First(r => r.Id == SelectedEquipment).Stock >= quantity; if (!enoughStock) { return; } // All valid, make the sale var newSale = new Sale() { CustomerId = id, Quantity = quantity, EquipmentId = SelectedEquipment, DateOfSale = DateTime.Now }; _context.Sales_tbl.Add(newSale); _context.Equipment_tbl.First(r => r.Id == SelectedEquipment).Stock -= quantity; _context.SaveChanges(); Quantity = ""; UpdateStockRemaining(); }