Пример #1
0
        public MainLotListing Filter(LotFilter filter)
        {
            var model      = new MainLotListing();
            var parameters = new OracleDynamicParameters();

            parameters.Add("o_result", null, OracleMappingType.RefCursor, ParameterDirection.Output);
            parameters.Add("o_Ending_Today_Lots_Count", null, OracleMappingType.Decimal, ParameterDirection.Output);
            parameters.Add("o_Active_Lots_Count", null, OracleMappingType.Decimal, ParameterDirection.Output);
            parameters.Add("o_My_Offers_Count", null, OracleMappingType.Decimal, ParameterDirection.Output);
            parameters.Add("o_Price_Range_Min", null, OracleMappingType.Decimal, ParameterDirection.Output);
            parameters.Add("o_Price_Range_Max", null, OracleMappingType.Decimal, ParameterDirection.Output);
            parameters.Add("p_Card_Size", filter.to - filter.from);
            parameters.Add("p_Region_Id", filter.regionId);
            parameters.Add("p_Company_Id", filter.companyId);
            parameters.Add("p_is_allowed_juridical", filter.isAllowedJuridic.HasValue && filter.isAllowedJuridic.Value ? 1 : 0);
            parameters.Add("p_is_allowed_individual", filter.isAllowedIndividual.HasValue && filter.isAllowedIndividual.Value ? 1 : 0);
            parameters.Add("p_price_from", filter.startPrice);
            parameters.Add("p_price_to", filter.endPrice);
            parameters.Add("p_Full_Numbers", filter.fullNumbers, OracleMappingType.Varchar2, size: 512);
            parameters.Add("p_is_today", filter.isToday.HasValue && filter.isToday.Value ? (int?)1 : null);
            parameters.Add("p_User_Id", null);

            using (var con = _connection)
            {
                model.Items = con.Query <MainLotItem>("Front.Get_Filtered_Lots", parameters, commandType: CommandType.StoredProcedure);

                model.EndingTodayLotsCount = (int?)parameters.Get <decimal?>("o_Ending_Today_Lots_Count");
                model.ActiveLotsCount      = (int?)parameters.Get <decimal?>("o_Active_Lots_Count");
                model.MyOffersCount        = (int?)parameters.Get <decimal?>("o_My_Offers_Count");
                model.PriceRangeMin        = (int?)parameters.Get <decimal?>("o_Price_Range_Min");
                model.PriceRangeMax        = (int?)parameters.Get <decimal?>("o_Price_Range_Max");
            }

            return(model);
        }
Пример #2
0
        public async Task <List <LotDto> > GetLots(LotFilter filter)
        {
            var fromDate = filter.FromDate ?? DateTime.MinValue;
            var toDate   = filter.ToDate ?? DateTime.MaxValue;
            var limit    = (filter.Limit > 0 & filter.Limit <= 50) ? filter.Limit : 50;

            using (var db = new BuckwheatContext())
            {
                var lotsQuery = db.Lots.AsQueryable();
                if (filter.ShopId != null)
                {
                    lotsQuery = lotsQuery.Where(x => x.Shop.Id == filter.ShopId);
                }
                if (filter.FromWeight != null)
                {
                    lotsQuery = lotsQuery.Where(x => x.WeightInGrams >= filter.FromWeight);
                }
                if (filter.ToWeight != null)
                {
                    lotsQuery = lotsQuery.Where(x => x.WeightInGrams <= filter.ToWeight);
                }

                var lastPricesQuery = lotsQuery.Select(lot =>
                                                       db.Prices
                                                       .Where(p => p.Lot.Id == lot.Id && p.Date >= fromDate && p.Date <= toDate)
                                                       .OrderByDescending(p => p.Date)
                                                       .FirstOrDefault());

                var orderedPricesQuery = lastPricesQuery;
                if (filter.Order == "expensive")
                {
                    orderedPricesQuery = orderedPricesQuery.OrderByDescending(x => x.Value);
                }
                else if (filter.Order == "cheap")
                {
                    orderedPricesQuery = orderedPricesQuery.OrderBy(x => x.Value);
                }

                var oredredLotsQuery = orderedPricesQuery
                                       .Take(limit)
                                       .Select(x => new { Lot = x.Lot, Price = x, Shop = x.Lot.Shop });

                var orderedLots = await oredredLotsQuery.ToListAsync();

                var orderedLotsDtos = orderedLots.Select(x =>
                {
                    var mapped   = mapper.Map <Lot, LotDto>(x.Lot);
                    mapped.Price = mapper.Map <Price, PriceDto>(x.Price);
                    mapped.Shop  = mapper.Map <Shop, ShopDto>(x.Shop);
                    return(mapped);
                });

                return(orderedLotsDtos.ToList());
            }
        }
        public MainLotListing FilterLots([FromServices] LotService lotService)
        {
            var filter = new LotFilter
            {
                isAllowedIndividual = true,
                isAllowedJuridic    = true,
                from = 0,
                to   = 2
            };

            return(lotService.Filter(filter));
        }
        public IEnumerable <MainLotItem> CardLots([FromQuery] int page, [FromQuery] int company, [FromServices] LotService lotService)
        {
            var filter = new LotFilter
            {
                isAllowedIndividual = true,
                isAllowedJuridic    = true,
                from      = (page - 1) * 2,
                to        = (page) * 2,
                companyId = company
            };

            return(lotService.CardItems(filter));
        }
Пример #5
0
        public IEnumerable <MainLotItem> CardItems(LotFilter filter, int?userId = null)
        {
            var parameters = new OracleDynamicParameters();

            parameters.Add("o_Result", null, OracleMappingType.RefCursor, ParameterDirection.Output);
            parameters.Add("p_From", filter.from);
            parameters.Add("p_To", filter.to);
            parameters.Add("p_Region_Id", filter.regionId);
            parameters.Add("p_Company_Id", filter.companyId);
            parameters.Add("p_is_allowed_juridical", filter.isAllowedJuridic.HasValue && filter.isAllowedJuridic.Value ? 1 : 0);
            parameters.Add("p_is_allowed_individual", filter.isAllowedIndividual.HasValue && filter.isAllowedIndividual.Value ? 1 : 0);
            parameters.Add("p_price_from", filter.startPrice);
            parameters.Add("p_price_to", filter.endPrice);
            parameters.Add("p_Full_Numbers", filter.fullNumbers, OracleMappingType.Varchar2, size: 512);
            parameters.Add("p_is_today", filter.isToday.HasValue && filter.isToday.Value ? (int?)1 : null);
            parameters.Add("p_User_Id", null);
            parameters.Add("p_Except_Ids_Arr", filter.exceptIdsArr);

            using (var con = _connection)
            {
                return(con.Query <MainLotItem>("Front.Load_Lot_Cards", parameters, commandType: CommandType.StoredProcedure));
            }
        }
Пример #6
0
 public async Task <List <LotDto> > GetLots([FromQuery] LotFilter filter)
 => await lotsService.GetLots(filter);
Пример #7
0
 public Task <List <LotDto> > GetLots(LotFilter filter)
 => lotsRepository.GetLots(filter);