public async Task Handle(UpdateCarBrandNotification notification, CancellationToken cancellationToken) { var carBrand = await carBrandRepository.FindAsync(notification.CarBrandId); if (carBrand == null) { // TODO: throw more concrete exception instead of System.ArgumentException throw new ArgumentException(); } var carBrandImage = carBrand.Image; if (!string.IsNullOrEmpty(notification.ImageFileName) && !notification.ImageFileBuffer.IsEmpty) { if (!string.IsNullOrEmpty(carBrand.Image)) { await mediator.Publish(new DeleteFileNotification { FileName = carBrand.Image }); } carBrandImage = await mediator.Send(new SaveFileRequest { FileName = notification.ImageFileName, Buffer = notification.ImageFileBuffer }); } mapper.Map(notification, carBrand); carBrand.Image = carBrandImage; var operationResult = await carBrandRepository.UpdateAsync(carBrand) .ConfigureAwait(false); if (operationResult.Status != OperationStatus.Successful) { throw new UpdateCarBrandException(operationResult); } }
public async Task <CarBrandModel> Handle(GetCarBrandByIdRequest request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException($"{nameof(request)} of type {nameof(GetCarBrandByIdRequest)} argument cannot be null."); } var carBrand = await carBrandRepository.FindAsync(request.CarBrandId); if (carBrand == null) { // TODO: throw more concrete exception instead of System.ArgumentException throw new ArgumentException(); } carBrand.Image = await mediator.Send(new GetFileUrlRequest { FileName = carBrand.Image }); return(mapper.Map <CarBrandModel>(carBrand)); }
public async Task Handle(DeleteCarBrandNotification notification, CancellationToken cancellationToken) { var carBrand = await carBrandRepository.FindAsync(notification.CarBrandId) .ConfigureAwait(false); if (carBrand == null) { // TODO: throw more concrete exception instead of System.ArgumentException throw new ArgumentException(); } if (!string.IsNullOrEmpty(carBrand.Image)) { await mediator.Publish(new DeleteFileNotification { FileName = carBrand.Image }); } var operationResult = await carBrandRepository.RemoveAsync(notification.CarBrandId) .ConfigureAwait(false); if (operationResult.Status != OperationStatus.Successful) { throw new DeleteCarBrandException(operationResult); } }