private async Task LogHistory(Booking booking) { var customer = await context.Customers.SingleOrDefaultAsync(o => o.UserId == booking.CustomerId); if (customer == null) { throw new NotFoundException(); } // log in booking history var customerBookingHistory = new CustomerBookingHistory(); customerBookingHistory.CustomerId = customer.CustomerId; customerBookingHistory.BookingStatusId = booking.BookingStatusId; customerBookingHistory.ReceiverCompleteName = booking.ContactName; customerBookingHistory.ReceiverCompleteAddress = booking.DropOffLocation; customerBookingHistory.EstimatedTime = booking.EstimatedTime; customerBookingHistory.ItemDetails = booking.Items; customerBookingHistory.TotalKilometers = booking.TotalKilometers; customerBookingHistory.Receipt = booking.ReferenceNumber; customerBookingHistory.BookingDate = booking.BookingDate; customerBookingHistory.TotalFare = booking.TotalFare.GetValueOrDefault(); context.CustomerBookingHistories.Add(customerBookingHistory); await context.SaveChangesAsync(); }
private async Task LogHistory(Booking entity) { // log in booking history var customerBookingHistory = new CustomerBookingHistory(); customerBookingHistory.CustomerId = entity.CustomerId; customerBookingHistory.BookingStatusId = entity.BookingStatusId; customerBookingHistory.ReceiverCompleteName = entity.ContactName; customerBookingHistory.ReceiverCompleteAddress = entity.DropOffLocation; customerBookingHistory.EstimatedTime = entity.EstimatedTime; customerBookingHistory.ItemDetails = entity.Items; customerBookingHistory.TotalKilometers = entity.TotalKilometers; customerBookingHistory.Receipt = string.Empty; customerBookingHistory.BookingDate = entity.BookingDate; customerBookingHistory.TotalFare = entity.TotalFare.GetValueOrDefault(); context.CustomerBookingHistories.Add(customerBookingHistory); await context.SaveChangesAsync(); }
public async Task <Unit> Handle(UpdateBookingCommand request, CancellationToken cancellationToken) { var entity = mapper.Map <Booking>(request.Dto); var booking = await context.Bookings.FindAsync(request.BookingId); if (booking == null) { throw new NotFoundException(); } // update booking properties booking.BookingStatusId = entity.BookingStatusId; booking.BookingDate = entity.BookingDate; booking.ContactName = entity.ContactName; booking.ContactNumber = entity.ContactNumber; booking.DropOffLocation = entity.DropOffLocation; booking.DropOffLatitude = entity.DropOffLatitude; booking.DropOffLongitude = entity.DropOffLongitude; booking.DropOffTime = entity.DropOffTime; booking.Items = entity.Items; booking.Notes = entity.Notes; booking.TotalEstimatedWeight = entity.TotalEstimatedWeight; booking.IsActive = entity.IsActive; booking.PickupLocation = entity.PickupLocation; booking.PickupLongitude = entity.PickupLongitude; booking.PickupLatitude = entity.PickupLatitude; booking.PickupTime = entity.PickupTime; booking.FareId = entity.FareId; booking.RiderId = entity.RiderId; booking.PhotoUrl = entity.PhotoUrl; context.Update(booking); context.SaveChanges(); // log in booking history var customerBookingHistory = new CustomerBookingHistory(); customerBookingHistory.CustomerId = booking.CustomerId; customerBookingHistory.BookingStatusId = booking.BookingStatusId; customerBookingHistory.ReceiverCompleteName = booking.ContactName; customerBookingHistory.ReceiverCompleteAddress = booking.DropOffLocation; customerBookingHistory.EstimatedTime = booking.EstimatedTime; customerBookingHistory.ItemDetails = booking.Items; customerBookingHistory.TotalKilometers = booking.TotalKilometers; customerBookingHistory.Receipt = booking.ReceiptNumber; customerBookingHistory.BookingDate = booking.BookingDate; var fare = await context.Fares.FindAsync(booking.FareId); if (fare != null) { if (!string.IsNullOrEmpty(entity.TotalKilometers)) { customerBookingHistory.TotalFare = FareHelper.Compute(fare.PricePerKilometer, fare.BaseFare, fare.Surcharge, GetKilometer(booking.TotalKilometers)); } } context.CustomerBookingHistories.Add(customerBookingHistory); await context.SaveChangesAsync(); return(await Task.FromResult(Unit.Value)); }