示例#1
0
        public Trip(Guid id, int userId, int driverId, Location from, Location to, PaymentMethod paymentMethod, string plate, string brand, string model) : base(id)
        {
            if (userId <= 0)
            {
                throw new TripDomainArgumentNullException(nameof(userId));
            }
            if (driverId <= 0)
            {
                throw new TripDomainArgumentNullException(nameof(driverId));
            }
            if (string.IsNullOrWhiteSpace(plate))
            {
                throw new TripDomainArgumentNullException(nameof(plate));
            }
            if (string.IsNullOrWhiteSpace(brand))
            {
                throw new TripDomainArgumentNullException(nameof(brand));
            }
            if (string.IsNullOrWhiteSpace(model))
            {
                throw new TripDomainArgumentNullException(nameof(model));
            }
            if (from == null)
            {
                throw new TripDomainArgumentNullException(nameof(from));
            }
            if (to == null)
            {
                throw new TripDomainArgumentNullException(nameof(to));
            }

            if (Equals(from, to))
            {
                throw new TripDomainInvalidOperationException("Destination and origin can't be the same.");
            }

            _paymentMethod      = paymentMethod ?? throw new TripDomainArgumentNullException(nameof(paymentMethod));
            _create             = DateTime.UtcNow;
            _status             = TripStatus.Created;
            _userId             = userId;
            _driverId           = driverId;
            _from               = from;
            _to                 = to;
            _vehicleInformation = new VehicleInformation(plate, brand, model);

            AddEvent(new TripCreatedDomainEvent
            {
                AggregateRootId    = Id,
                VehicleInformation = _vehicleInformation,
                UserTripId         = _userId,
                DriverId           = _driverId,
                From          = _from,
                To            = _to,
                PaymentMethod = _paymentMethod,
                TimeStamp     = _create,
                Status        = _status
            });
        }
示例#2
0
 // Applies events after load an object from event store. (kinda memento pattern)
 private void Apply(TripCreated @event)
 {
     Id                  = @event.AggregateRootId;
     _driverId           = @event.DriverId;
     _from               = @event.From;
     _to                 = @event.To;
     _userId             = @event.UserTripId;
     _vehicleInformation = @event.VehicleInformation;
 }
示例#3
0
 // Applies events after load an object from event store. (kinda memento pattern)
 private void Apply(TripCreatedDomainEvent @event)
 {
     Id                  = @event.AggregateRootId;
     _status             = @event.Status;
     _create             = @event.TimeStamp;
     _driverId           = @event.DriverId;
     _from               = @event.From;
     _to                 = @event.To;
     _userId             = @event.UserTripId;
     _vehicleInformation = @event.VehicleInformation;
     _paymentMethod      = @event.PaymentMethod;
 }
示例#4
0
        public Trip(Guid id, int userId, int driverId, Location from, Location to, string plate, string brand, string model) : base(id)
        {
            if (userId <= 0)
            {
                throw new TripDomainArgumentNullException(nameof(userId));
            }
            if (driverId <= 0)
            {
                throw new TripDomainArgumentNullException(nameof(driverId));
            }
            if (string.IsNullOrWhiteSpace(plate))
            {
                throw new TripDomainArgumentNullException(nameof(plate));
            }
            if (string.IsNullOrWhiteSpace(brand))
            {
                throw new TripDomainArgumentNullException(nameof(brand));
            }
            if (string.IsNullOrWhiteSpace(model))
            {
                throw new TripDomainArgumentNullException(nameof(model));
            }

            if (Equals(from, to))
            {
                throw new TripDomainInvalidOperationException("Destination and origin can't be the same.");
            }

            _userId             = userId;
            _driverId           = driverId;
            _from               = from ?? throw new TripDomainArgumentNullException(nameof(from));
            _to                 = to ?? throw new TripDomainArgumentNullException(nameof(to));
            _vehicleInformation = new VehicleInformation(plate, brand, model);

            AddEvent(new TripCreated
            {
                AggregateRootId    = Id,
                VehicleInformation = _vehicleInformation,
                UserTripId         = _userId,
                DriverId           = _driverId,
                From = _from,
                To   = _to
            });
        }