internal async Task TryRegisterCarAsync(AddCarVM newCar) { context.Add(new AvailableCars { CarType = newCar.CarType, CarLicenseNumber = newCar.CarLicenseNumber, CurrentMileage = newCar.CurrentMileage, }); await context.SaveChangesAsync(); }
public async Task TryRegisterBookingAsync(RegisterBookingVM viewModel) { var client = GetClient(viewModel.ClientSSN); if (client == null) { context.Add(new Clients { ClientSsn = viewModel.ClientSSN, FirstName = viewModel.FirstName, LastName = viewModel.LastName }); await context.SaveChangesAsync(); } context.Add(new Booking { BookingNumber = viewModel.BookingNumber, ClientSsn = viewModel.ClientSSN, CarType = viewModel.CarType, CarLicenseNumber = viewModel.CarLicenseNumber, TimeOfBooking = viewModel.TimeOfBooking, CurrentMileage = viewModel.CurrentMileage }); var car = GetCar(viewModel.CarLicenseNumber); var clientData = GetClient(viewModel.ClientSSN); context.Add(new ClientEvents { ClientId = clientData.Id, CarId = car.Id, EventDescription = $"{clientData.FirstName} {clientData.LastName} picked up car {car.CarLicenseNumber}.", TimeOfEvent = DateTime.Now, TypeOfEvent = "Pickup", }); await context.SaveChangesAsync(); await SetIsNotAvailable(viewModel.CarLicenseNumber); }