public OperationResponse <ProductMediaInsertCommandOutputDTO> Execute(ProductMediaInsertCommandInputDTO input) { var result = new OperationResponse <ProductMediaInsertCommandOutputDTO>(); using (var dbContextScope = this.DbContextScopeFactory.Create()) { using (var transaction = new TransactionScope()) { var createFileArgs = this.CreateFileArgs(input); var fileInsertResult = this.FileInsertCommand.Execute <DefaultFileArgs, UploadedFile>(createFileArgs); result.AddResponse(fileInsertResult); if (result.IsSucceed) { var entity = new DomainModel.Product.ProductMedia { ProductId = input.ProductId, FileRepositoryId = fileInsertResult.Bag.Id }; try { var insertResult = this.Repository.Insert(entity); dbContextScope.SaveChanges(); } catch (Exception ex) { result.AddException("Error saving product media", ex); } if (result.IsSucceed) { var getByIdResult = this.Repository.GetById(entity.Id); if (result.IsSucceed) { result.Bag = new ProductMediaInsertCommandOutputDTO { Id = getByIdResult.Bag.Id }; } } } transaction.Complete(); } } return(result); }
public IActionResult Post([FromBody] ProductMediaInsertCommandInputDTO model) { try { var appResult = this.InsertCommand.Execute(model); if (appResult.IsSucceed) { var signalArgs = new SignalREventArgs(SignalREvents.DATA_CHANGED.Identifier, nameof(SignalREvents.DATA_CHANGED.ActionEnum.ADDED_ITEM), nameof(ProductMedia), appResult.Bag); this.SignalRHubContext.Clients.All.DataChanged(signalArgs); } return(appResult.IsSucceed ? (IActionResult)this.Ok(appResult) : (IActionResult)this.BadRequest(appResult)); } catch (Exception ex) { this.Logger.Error("Error adding ProductMedia", ex); throw; } }
private DefaultFileArgs CreateFileArgs(ProductMediaInsertCommandInputDTO input) { var result = new DefaultFileArgs(FileAreaEnum.Enum.PRODUCT, nameof(FileAreaEnum.ProductArea.Enum.Media), input); return(result); }