Esempio n. 1
0
        public async Task <CarModificationModel> Handle(GetCarModificationByIdRequest request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException($"{nameof(request)} of type {nameof(GetCarModificationByIdRequest)} argument cannot be null.");
            }

            var carModification = await carModificationRepository.FindAsync(request.CarModificationId)
                                  .ConfigureAwait(false);

            if (carModification == null)
            {
                throw new NotFoundException();
            }

            return(mapper.Map <CarModificationModel>(carModification));
        }
        public async Task Handle(UpdateCarModificationNotification notification, CancellationToken cancellationToken)
        {
            var carModification = await carModificationRepository.FindAsync(notification.CarModificationId)
                                  .ConfigureAwait(false);

            if (carModification == null)
            {
                // TODO: throw more concrete exception instead of System.ArgumentException
                throw new ArgumentException();
            }

            mapper.Map(notification, carModification);

            var operationResult = await carModificationRepository.UpdateAsync(carModification)
                                  .ConfigureAwait(false);

            if (operationResult.Status != OperationStatus.Successful)
            {
                throw new UpdateCarModificationException(operationResult);
            }
        }