public async Task <Unit> Handle(AddParcelToLockerCommand request, CancellationToken cancellationToken)
        {
            var parcelLocker = await _parcelLockersRepository.GetParcelLockerAsync(request.ParcelLockerId);

            if (parcelLocker is null)
            {
                throw new ApplicationException($"Parcel locker with id '{request.ParcelLockerId}' does not exist");
            }

            // TODO: Validate if parcels with given ids exists.
            foreach (var parcel in request.ParcelsIds)
            {
                parcelLocker.AddParcel(Parcel.Create(parcel));
            }

            await _parcelLockersRepository.UpdateParcelLockerAsync(parcelLocker);

            return(Unit.Value);
        }
示例#2
0
        public async Task <ParcelLockerDto> Handle(GetParcelLockerQuery request, CancellationToken cancellationToken)
        {
            var parcelLocker = await _parcelLockersRepository.GetParcelLockerAsync(request.Id);

            if (!(parcelLocker is null))
            {
                return(new ParcelLockerDto
                {
                    Id = parcelLocker.Id,
                    Localization = new ParcelLockerLocalizationDto
                    {
                        Latitude = parcelLocker.Localization.Latitude,
                        Longtitude = parcelLocker.Localization.Longtitude,
                        AdditionalInfo = parcelLocker.Localization.AdditionalInfo,
                        City = parcelLocker.Localization.City,
                        PostalCode = parcelLocker.Localization.PostalCode
                    },
                    CreateDate = parcelLocker.CreateDate
                });
            }

            return(null);
        }