Ejemplo n.º 1
0
        public async Task <Consignment> ExecuteAsync(GetConsignmentQuery command, Consignment previousResult)
        {
            if (command.WithTracking)
            {
                _consignmentRepository.LoadWith(item => item.TrackingRecords);
            }

            var consignment = await _consignmentRepository.Get(command.Id);

            return(_mapper.Map <Consignment>(consignment));
        }
        public async Task <Tracking> ExecuteAsync(AddTrackingCommand command, Tracking previousResult)
        {
            _consignmentRepository.LoadWith(item => item.TrackingRecords);
            var consignment = await _consignmentRepository.Get(command.Tracking.ConsignmentId);

            if (consignment.TrackingRecords?.Any(record => record.TrackingType == TrackingType.Delivered) ?? false)
            {
                throw new ConsignmentAlreadyDeliveredException(ConsignmentAlreadyDeliveredMessage);
            }

            var tracking = _mapper.Map <TrackingRecord>(command.Tracking);

            await AddTrackingToRepository(tracking, Guid.Parse(command.CreatedByUserId));

            return(_mapper.Map <Tracking>(tracking));
        }