/// <summary> /// To register that a customer has returned a car, looks up booking for car, /// returns Car object. /// </summary> /// <param name="carId">BookingId, id of booking for which a specific car is returned.</param> /// <returns>Car object.</returns> public Car DropOffCar(int bookingId) { var bookings = repos.DataSet <Booking>().ToList(); Booking booking = repos.DataSet <Booking>() .Where(book => book.Id == bookingId && book.StartTime <= DateTime.Today.Date && (book.CarInGarage == false)) .Include(book => book.Car) .SingleOrDefault(); if (null == booking) { InvalidOperationFault fault = new InvalidOperationFault(); fault.Message = "Error trying to return car in system."; fault.Description = "There is no active booking for the given booking id. If there is a car to return, please review input booking id " + " to find the car you wish to return."; throw new FaultException <InvalidOperationFault>(fault); } Car c = booking.Car; booking.CarInGarage = true; repos.Edit(booking); repos.SaveChanges(); return(c); }
/// <summary> /// Delete booking from db. /// </summary> /// <param name="bookingId">Id of booking to delete.</param> public void DeleteBooking(int bookingId) { Booking b = repos.FindBy <Booking>(book => book.Id == bookingId).FirstOrDefault(); if (null != b && b.CarInGarage) { try { repos.Remove(b); repos.SaveChanges(); } catch (DbUpdateException ex) { DbUpdateFault faulty = new DbUpdateFault(); faulty.Message = ex.Message; faulty.Description = "Something went wrong when trying to delete booking from db."; throw new FaultException <DbUpdateFault>(faulty); } } else { InvalidOperationFault fault = new InvalidOperationFault(); fault.Message = "Error when trying to delete booking."; fault.Description = "Booking with that id could not be deleted from database, please review input. Maybe" + "the booking was not found in system or the rented car has not been returned by customer."; throw new FaultException <InvalidOperationFault>(fault); } }
/// <summary> /// Register when reservation becomes an actual leasing (i.e customer gets reserved car from office). /// </summary> /// <param name="bookingId">Id of the booking for which the booked car is picked up from office.</param> /// <returns>The Car object to pick up for the booking in question.</returns> public Car PickUpCar(int bookingId) { var bookings = repos.DataSet <Booking>().ToList(); Booking booking = repos.DataSet <Booking>() .Where(b => b.Id == bookingId && b.StartTime <= DateTime.Today.Date && b.EndTime >= DateTime.Today.Date && b.CarInGarage) .Include(b => b.Car) .SingleOrDefault(); if (null == booking || booking.CarInGarage == false) { InvalidOperationFault fault = new InvalidOperationFault(); fault.Message = "Error, could not register pick up in system."; fault.Description = "Either there is no active booking for the given booking id " + "OR customer has already picked the car up for this booking."; throw new FaultException <InvalidOperationFault>(fault); } Car bookedCar = booking.Car; booking.CarInGarage = false; repos.Edit(booking); repos.SaveChanges(); return(bookedCar); }