Beispiel #1
0
        protected IQueryable <Trade> BuildQuery(TradeQuery queryParams)
        {
            IQueryable <Trade> tradeQuery = _context.Trades.AsNoTracking();

            if (queryParams.From.HasValue)
            {
                tradeQuery = tradeQuery.Where(row => row.Date >= queryParams.From.Value);
            }

            if (queryParams.To.HasValue)
            {
                tradeQuery = tradeQuery.Where(row => row.Date <= queryParams.To.Value);
            }

            if (queryParams.BIC != null)
            {
                tradeQuery = tradeQuery.Where(row => row.BIC == queryParams.BIC);
            }

            if (queryParams.ISIN != null)
            {
                tradeQuery = tradeQuery.Where(row => row.ISIN == queryParams.ISIN);
            }

            if (queryParams.Limit.HasValue)
            {
                tradeQuery = tradeQuery.Take(queryParams.Limit.Value);
            }

            return(tradeQuery);
        }
Beispiel #2
0
        public async Task <IEnumerable <Trade> > GetAllTradeAsync(TradeQuery queryObj)
        {
            var query = context.Trades
                        .Include(t => t.User)
                        .Include(t => t.Coin)
                        .Include(t => t.Fx)
                        .AsQueryable();

            if (queryObj.TradeId.HasValue)
            {
                query = query.Where(t => t.Id == queryObj.TradeId);
            }

            if (queryObj.CoinId.HasValue)
            {
                query = query.Where(t => t.TradeCoinId == queryObj.CoinId);
            }

            var columnsMap = new Dictionary <string, Expression <Func <Trade, object> > >()
            {
                ["user"]  = t => t.User.Name,
                ["coin"]  = t => t.Coin.Name,
                ["fx"]    = t => t.Fx.Name,
                ["price"] = t => t.Price
            };

            query = query.ApplyOrdering(queryObj, columnsMap);
            query = query.ApplyPaging(queryObj);

            return(await query.ToListAsync());
        }
Beispiel #3
0
        public async Task <ActionResult <IEnumerable <Trade> > > GetTradesByQuery([FromQuery] TradeQuery queryParams)
        {
            IQueryable <Trade> tradeQuery = BuildQuery(queryParams);

            IEnumerable <Trade> result = await tradeQuery
                                         .OrderBy(row => row.Date)
                                         .ToListAsync();

            return(Ok(result));
        }
Beispiel #4
0
        public void OnGet(string searchKey, Direction?direction)
        {
            Direction   = direction;
            UserContext = CoreService.GetUserContext();

            TradeQuery = DbContext.Trades
                         .Include(t => t.VetMember)
                         .Where(c => c.TradeStatus != TradeStatus.Cancel)
                         .AsQueryable();

            if (UnderRewordLimit.HasValue)
            {
                TradeQuery = TradeQuery
                             .Where(c => c.Reward >= UnderRewordLimit || c.Reward == null);
            }

            if (OverRewordLimit.HasValue)
            {
                TradeQuery = TradeQuery
                             .Where(c => c.Reward <= OverRewordLimit || c.Reward == null);
            }

            if (IsExceptRewardNull)
            {
                TradeQuery = TradeQuery
                             .Where(c => c.Reward != null);
            }

            if (!IsWorking)
            {
                TradeQuery = TradeQuery.Where(c => !c.Contracts.Any(d => d.ContractStatus == ContractStatus.Working || d.ContractStatus == ContractStatus.Deliveryed));
            }
            if (!IsCpmplited)
            {
                TradeQuery = TradeQuery.Where(c => !c.Contracts.Any(d => d.ContractStatus == ContractStatus.Complete) || c.IsContinued);
            }

            if (direction.HasValue)
            {
                TradeQuery = TradeQuery.Where(c => c.Direction == direction);
            }

            if (!string.IsNullOrEmpty(searchKey))
            {
                TradeQuery = TradeQuery
                             .Where(c =>
                                    c.Title.Contains(searchKey) ||
                                    c.Content.Contains(searchKey) ||
                                    c.VetMember.Name.Contains(searchKey));
            }

            Response.Cookies.Append("Test", "{ a:'BBB'}");
        }
Beispiel #5
0
        public void OnGet(string searchKey, Direction?direction)
        {
            Direction = direction;

            TradeQuery = DbContext.Trades
                         .Include(t => t.VetMember)
                         .Where(c => c.TradeStatus != TradeStatus.Cancel)
                         .AsQueryable();


            if (direction.HasValue)
            {
                TradeQuery = TradeQuery.Where(c => c.Direction == direction);
            }

            if (!string.IsNullOrEmpty(searchKey))
            {
                TradeQuery = TradeQuery
                             .Where(c =>
                                    c.Title.Contains(searchKey) ||
                                    c.Content.Contains(searchKey) ||
                                    c.VetMember.Name.Contains(searchKey));
            }
        }
Beispiel #6
0
        public async Task <ActionResult <IEnumerable <Trade> > > GetTradesByIsin([FromRoute] string isin, [FromQuery] TradeQuery queryParams)
        {
            Stock stockObject = await _stockService.GetStockByIsinAsync(isin);

            if (stockObject == null)
            {
                return(NotFound(new ProblemDetails
                {
                    Title = "Stock not found",
                    Detail = $"Stock with ISIN {isin} was not found"
                }));
            }

            IQueryable <Trade> tradeQuery = BuildQuery(queryParams);

            IEnumerable <Trade> result = await tradeQuery
                                         .Where(row => row.ISIN == isin)
                                         .ToListAsync();

            return(Ok(result));
        }