public async Task <StockTransactionVM> CreateAsync(CreateOrUpdateStockTransactionVM createOrUpdateStockTransactionVM) { var stock = await _mediator.Send(new GetSingleRequest <Stock>(createOrUpdateStockTransactionVM.StockId)); var stock_transaction = new StockTransaction() { Id = createOrUpdateStockTransactionVM.Id, Stock = stock, Commission = createOrUpdateStockTransactionVM.Commission, Amount = createOrUpdateStockTransactionVM.Amount, Price = createOrUpdateStockTransactionVM.Price, When = createOrUpdateStockTransactionVM.When, TradeType = createOrUpdateStockTransactionVM.TradeType }; var checkIfExists = await _mediator.Send(new CheckExistsRequest <StockTransaction>(stock_transaction)); if (checkIfExists != null) { _notifications.AddNotification("400", "Already exist a transaction with the same data."); return(checkIfExists.ToVM()); } stock_transaction = await _mediator.Send(new CreateRequest <StockTransaction>(stock_transaction)); return(stock_transaction.ToVM()); }
public async Task <StockTransactionVM> GetAsync(string id) { StockTransaction transaction = await _mediator.Send(new GetSingleRequest <StockTransaction>(id)); if (transaction == null) { _notifications.AddNotification("404", "stock transaction was not found."); } return(transaction.ToVM()); }