コード例 #1
0
 public void AddTrip(CustomerTrip customerTrip)
 {
     if (customerTrip == null)
     {
         throw new DomainException(DomainErrorCodes.ArgumentNullOrEmpty, null, "Trip cannot be null!");
     }
     if (customerTrip.Customer == null || customerTrip.Trip == null)
     {
         throw new DomainException(DomainErrorCodes.ArgumentNullOrEmpty, null, "Customer or Trip in customer trip is null");
     }
     if (_customerTrips.Any(x => x.Id == customerTrip.Id))
     {
         throw new DomainException(DomainErrorCodes.CustomerAlreadyAssignedToThisTrip, null,
                                   "Customer already is on this trip");
     }
     customerTrip.Trip.CheckForOverlappingTripsOrFail(this);
     _customerTrips.Add(customerTrip);
 }
コード例 #2
0
        public void AddCustomer(Customer customer)
        {
            if (StartDateUTC < _dateTimeOffsetProvider.UtcNow)
            {
                throw new DomainException(DomainErrorCodes.TripAlreadyStarted, null,
                                          "Cannot add customer to trip, trip already started!");
            }

            if (_customerTrips.Any(x =>
                                   x.CustomerId == customer.Id && x.TripId == Id || x.Id == customer.Id))
            {
                throw new DomainException(DomainErrorCodes.CustomerAlreadyAssignedToThisTrip, null,
                                          "Customer is already assigned to this trip!");
            }

            this.CheckForOverlappingTripsOrFail(customer);

            var customerTrip = new CustomerTrip(Guid.NewGuid(), customer, this);

            _customerTrips.Add(customerTrip);
            customer.AddTrip(customerTrip);
        }
コード例 #3
0
 public static void CheckForDuplicatedIdsOrFail(this IEnumerable <CustomerTrip> customerTrips, CustomerTrip customerTrip)
 {
     if (customerTrips.Any(x => x.Id == customerTrip.Id))
     {
         throw new DomainException(DomainErrorCodes.CustomerAlreadyAssignedToThisTrip, null,
                                   "Customer already assigned to this trip!");
     }
 }