Exemplo n.º 1
0
        public async Task <int> Count(MarketPriceFilter filter)
        {
            IQueryable <MarketPriceDAO> MarketPrices = DataContext.MarketPrice.AsNoTracking();

            MarketPrices = DynamicFilter(MarketPrices, filter);
            return(await MarketPrices.CountAsync());
        }
Exemplo n.º 2
0
        public async Task <List <MarketPrice> > List(MarketPriceFilter filter)
        {
            if (filter == null)
            {
                return(new List <MarketPrice>());
            }
            IQueryable <MarketPriceDAO> MarketPriceDAOs = DataContext.MarketPrice.AsNoTracking();

            MarketPriceDAOs = DynamicFilter(MarketPriceDAOs, filter);
            MarketPriceDAOs = DynamicOrder(MarketPriceDAOs, filter);
            List <MarketPrice> MarketPrices = await DynamicSelect(MarketPriceDAOs, filter);

            return(MarketPrices);
        }
Exemplo n.º 3
0
        public async Task <List <MarketPrice> > List(MarketPriceFilter MarketPriceFilter)
        {
            try
            {
                List <MarketPrice> MarketPrices = await UOW.MarketPriceRepository.List(MarketPriceFilter);

                return(MarketPrices);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(MarketPriceService));
            }
            return(null);
        }
Exemplo n.º 4
0
        public async Task <int> Count(MarketPriceFilter MarketPriceFilter)
        {
            try
            {
                int result = await UOW.MarketPriceRepository.Count(MarketPriceFilter);

                return(result);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(MarketPriceService));
            }
            return(0);
        }
Exemplo n.º 5
0
        public async Task <bool> ValidateId(MarketPrice MarketPrice)
        {
            MarketPriceFilter MarketPriceFilter = new MarketPriceFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = MarketPrice.Id
                },
                Selects = MarketPriceSelect.Id
            };

            int count = await UOW.MarketPriceRepository.Count(MarketPriceFilter);

            if (count == 0)
            {
                MarketPrice.AddError(nameof(MarketPriceValidator), nameof(MarketPrice.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
Exemplo n.º 6
0
        public async Task <List <Store_MarketPriceDTO> > SingleListMarketPrice([FromBody] Store_MarketPriceFilterDTO Store_MarketPriceFilterDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            MarketPriceFilter MarketPriceFilter = new MarketPriceFilter();

            MarketPriceFilter.Skip      = 0;
            MarketPriceFilter.Take      = int.MaxValue;
            MarketPriceFilter.OrderBy   = MarketPriceOrder.Id;
            MarketPriceFilter.OrderType = OrderType.ASC;
            MarketPriceFilter.Selects   = MarketPriceSelect.ALL;
            MarketPriceFilter.Id        = Store_MarketPriceFilterDTO.Id;
            MarketPriceFilter.Name      = Store_MarketPriceFilterDTO.Name;

            List <MarketPrice> MarketPrices = await MarketPriceService.List(MarketPriceFilter);

            List <Store_MarketPriceDTO> Store_MarketPriceDTOs = MarketPrices
                                                                .Select(x => new Store_MarketPriceDTO(x)).ToList();

            return(Store_MarketPriceDTOs);
        }
Exemplo n.º 7
0
        private IQueryable <MarketPriceDAO> DynamicOrder(IQueryable <MarketPriceDAO> query, MarketPriceFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case MarketPriceOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

                case MarketPriceOrder.Code:
                    query = query.OrderBy(q => q.Code);
                    break;

                case MarketPriceOrder.Name:
                    query = query.OrderBy(q => q.Name);
                    break;
                }
                break;

            case OrderType.DESC:
                switch (filter.OrderBy)
                {
                case MarketPriceOrder.Id:
                    query = query.OrderByDescending(q => q.Id);
                    break;

                case MarketPriceOrder.Code:
                    query = query.OrderByDescending(q => q.Code);
                    break;

                case MarketPriceOrder.Name:
                    query = query.OrderByDescending(q => q.Name);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }
Exemplo n.º 8
0
        private IQueryable <MarketPriceDAO> OrFilter(IQueryable <MarketPriceDAO> query, MarketPriceFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <MarketPriceDAO> initQuery = query.Where(q => false);

            foreach (MarketPriceFilter MarketPriceFilter in filter.OrFilter)
            {
                IQueryable <MarketPriceDAO> queryable = query;
                if (MarketPriceFilter.Id != null && MarketPriceFilter.Id.HasValue)
                {
                    queryable = queryable.Where(q => q.Id, MarketPriceFilter.Id);
                }
                if (MarketPriceFilter.Code != null && MarketPriceFilter.Code.HasValue)
                {
                    queryable = queryable.Where(q => q.Code, MarketPriceFilter.Code);
                }
                if (MarketPriceFilter.Name != null && MarketPriceFilter.Name.HasValue)
                {
                    queryable = queryable.Where(q => q.Name, MarketPriceFilter.Name);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
Exemplo n.º 9
0
 private IQueryable <MarketPriceDAO> DynamicFilter(IQueryable <MarketPriceDAO> query, MarketPriceFilter filter)
 {
     if (filter == null)
     {
         return(query.Where(q => false));
     }
     if (filter.Id != null && filter.Id.HasValue)
     {
         query = query.Where(q => q.Id, filter.Id);
     }
     if (filter.Code != null && filter.Code.HasValue)
     {
         query = query.Where(q => q.Code, filter.Code);
     }
     if (filter.Name != null && filter.Name.HasValue)
     {
         query = query.Where(q => q.Name, filter.Name);
     }
     query = OrFilter(query, filter);
     return(query);
 }
Exemplo n.º 10
0
        private async Task <List <MarketPrice> > DynamicSelect(IQueryable <MarketPriceDAO> query, MarketPriceFilter filter)
        {
            List <MarketPrice> MarketPrices = await query.Select(q => new MarketPrice()
            {
                Id   = filter.Selects.Contains(MarketPriceSelect.Id) ? q.Id : default(long),
                Code = filter.Selects.Contains(MarketPriceSelect.Code) ? q.Code : default(string),
                Name = filter.Selects.Contains(MarketPriceSelect.Name) ? q.Name : default(string),
            }).ToListAsync();

            return(MarketPrices);
        }