public static CarPhoto ToCarPhoto(this CarPhotoCreateCommand command, string filename) { return(new CarPhoto { ModelId = command.ModelId, BodyTypeId = command.BodyTypeId, ColorId = command.ColorId, FileName = filename }); }
public async Task <int> AddPhotoAsync(CarPhotoCreateCommand createCommand) { await ValidatorFactory.GetValidator <CarPhotoCreateCommand>().ValidateAndThrowAsync(createCommand); try { await UnitOfWork.BeginTransactionAsync(); var fileName = await _fileManager.SaveAsync(createCommand.Photo, FileDestinations.CarPhoto); var item = createCommand.ToCarPhoto(fileName); await WriteRepository.AddAsync(item); await UnitOfWork.CommitAsync(); return(item.Id); } catch { _fileManager.RollBack(); await UnitOfWork.RollbackAsync(); throw; } }