예제 #1
0
        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);
            }
        }
예제 #2
0
        public async Task <CarBrandModel> UpdateAsync(CarBrandModel model)
        {
            var entity = MapFromModel(model);
            var result = await _carBrandRepository.UpdateAsync(entity);

            return(MapToModel <CarBrandModel>(result));
        }