Beispiel #1
0
        public async Task Handle(AddTradeCommand notification)
        {
            var entityCurrent = Mapper.Map <TradeModel, Trade>(notification.TradeModel);

            if (!IsEntityValid(entityCurrent))
            {
                return;
            }

            var userEntity = GetUserEntityTrade(notification.UserLoggedIn, entityCurrent.UserGet, entityCurrent.UserLet);

            if (userEntity == null)
            {
                return;
            }
            if (!IsUsersValid(notification.UserLoggedIn, userEntity, entityCurrent.UserGet, entityCurrent.UserLet))
            {
                return;
            }

            await _tradeRepository.AddAsync(entityCurrent);

            if (Commit())
            {
                await _mediator.PublishEvent(new TradeAddedEvent(_logger, Mapper.Map <TradeModel>(notification.TradeModel)));
            }
        }
            public async Task <ResponseResult> Handle(Command request, CancellationToken cancellationToken)
            {
                if (!request.Trades.Any())
                {
                    return(ResponseResult.Error("请求参数不能为空."));
                }

                var list = new List <QueryStack.Models.Trade>();

                foreach (var t in request.Trades)
                {
                    list.Add(new QueryStack.Models.Trade()
                    {
                        TradeName   = t.Name,
                        TradeId     = t.Id,
                        ProdMaterId = t.ProductId,
                    });
                }

                using (var scope = _databaseScopeFactory.CreateWithTransaction())
                {
                    await _tradeRepository.AddAsync(list);

                    scope.SaveChanges();
                }

                return(ResponseResult.Ok());
            }
Beispiel #3
0
            private async Task <string> DeleteAndAddProductTrades(Command request)
            {
                string errorMsg = string.Empty;

                if (request.Trades == null || request.Trades.Length == 0)
                {
                    return(errorMsg);
                }

                request.Trades = request.Trades.Distinct().ToArray <string>();

                await _tradeRepository.DeleteByProductIdAsync(request.Id, request.UserId);

                List <MService.QueryStack.Models.Trade> entities = new List <MService.QueryStack.Models.Trade>();

                foreach (string trade in request.Trades)
                {
                    int    index     = trade.IndexOf("|||");
                    string tradeId   = trade.Substring(0, index);
                    string tradeName = trade.Substring(index + 3);
                    if (string.IsNullOrWhiteSpace(tradeId) || string.IsNullOrWhiteSpace(tradeName))
                    {
                        errorMsg = errorMsg = $"销售渠道参数:{trade} 不符合规则.";
                        return(errorMsg);
                    }

                    MService.QueryStack.Models.Trade entity = new MService.QueryStack.Models.Trade()
                    {
                        TradeId     = tradeId,
                        TradeName   = tradeName,
                        ProdMaterId = request.Id,
                    };
                    entities.Add(entity);
                }

                await _tradeRepository.AddAsync(entities);

                return(errorMsg);
            }
        public async Task <IActionResult> PostTradeAsync([FromBody] Trade trade, [FromRoute] int id)
        {
            Trade created;

            try {
                var stock = await _stockRepository.GetAsync(trade.Stock.Symbol);

                trade.Stock.Id = stock.Id;
                trade.Time     = DateTime.Now;
                var portfolio = await _portfolioRepository.GetAsync(id);

                created = await _tradeRepository.AddAsync(trade, portfolio);
            } catch (ArgumentException e) {
                _logger.LogInformation(e, "Attempted to add a trade with an already existing Id.");
                return(BadRequest(e.Message));
            } catch (DbUpdateException e) {
                _logger.LogInformation(e, "Attempted to add a trade that violated database constraints.");
                return(BadRequest(e.Message));
            }

            return(CreatedAtAction(nameof(TradesController.GetByIdAsync), "Trades", new { id = created.Id }, created));
        }