public async Task <Unit> Handle(DeleteParcelCommand request, CancellationToken cancellationToken)
        {
            var parcel = await _parcelsRepository.GetParcelAsync(request.Id);

            if (parcel is null)
            {
                throw new ArgumentException($"Parcel with id: {request.Id} does not exist");
            }

            await _parcelsRepository.DeleteParcelAsync(parcel);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(UpdateParcelCommand request, CancellationToken cancellationToken)
        {
            var parcel = await _parcelRepository.GetParcelAsync(request.Id);

            if (parcel is null)
            {
                throw new ApplicationException($"Parcel with id: '{request.Id}' does not exist");
            }

            parcel.SetStatus((ParcelStatus)request.Status);

            await _parcelRepository.UpdateParcelAsync(parcel);

            return(Unit.Value);
        }
Esempio n. 3
0
        public async Task <ParcelDto> Handle(GetParcelQuery request, CancellationToken cancellationToken)
        {
            var parcel = await _parcelRepository.GetParcelAsync(request.Id);

            if (!(parcel is null))
            {
                return(new ParcelDto
                {
                    Size = (int)parcel.Size,
                    Status = (int)parcel.Status,
                    Weight = parcel.Weight,
                    Description = parcel.Description,
                    CreateDate = parcel.CreateDate
                });
            }

            return(null);
        }