public void ValidateFlightTicketCosts(IFlightReservation reservation) { var ticketCost = reservation.PricePerTicket; if (ticketCost < 0) { throw new TicketCostException(); } }
public void ValidateFlightDestination(IFlightReservation reservation) { var destination = reservation.Destination; if (string.IsNullOrWhiteSpace(destination)) { throw new InvalidDestinatinationException(); } }
public void ValidateFlightOriginAndDestination(IFlightReservation reservation) { var destination = reservation.Destination; var origin = reservation.Origin; if ((!string.IsNullOrWhiteSpace(destination) || !string.IsNullOrWhiteSpace(origin)) && (string.Compare(origin, destination, StringComparison.OrdinalIgnoreCase) == 0)) { throw new InvalidFlightOriginAndDestinationException(); } }
public decimal CalculateTotalReservationFees(IFlightReservation reservation) { decimal?totalFees = 0; if (reservation.FeesPerTicket.HasValue) { totalFees = reservation.FeesPerTicket.Value * reservation.Passengers.Count; } return((decimal)totalFees); }
public void ValidateFlightReservation(IFlightReservation reservation) { var departureDate = reservation.DepartureDate; var returnDate = reservation.ReturnDate; if (returnDate.HasValue) { if (departureDate > returnDate.Value) { throw new DateRangeException(); } } }
public decimal CalculateTotalReservationCost(IFlightReservation reservation) { decimal?totalPrice = 0; decimal?totalFees = 0; _validation.ValidateFlightReservation(reservation); _validation.ValidateFlightTicketCosts(reservation); _validation.ValidateFlightOriginAndDestination(reservation); _validation.ValidateFlightDestination(reservation); if (reservation.FeesPerTicket.HasValue) { totalFees = reservation.FeesPerTicket.Value * reservation.Passengers.Count; } totalPrice = reservation.PricePerTicket * reservation.Passengers.Count + totalFees; return((decimal)totalPrice); }