示例#1
0
            public async Task <ResponseResult> Handle(Command request, CancellationToken cancellationToken)
            {
                using (var scope = _databaseScopeFactory.CreateWithTransaction())
                {
                    await _tradeRepository.DeleteByProductIdAsync(request.ProductId, request.UserId);

                    scope.SaveChanges();
                }

                return(ResponseResult.Ok());
            }
示例#2
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);
            }