Пример #1
0
        public async Task <PagedList <Value> > GetValues(ValueParams valueParams)
        {
            var values = context.Values.Include(p => p.Photos).Include(q => q.Questions).AsQueryable();

            if (valueParams.Mark != null)
            {
                values = values.Where(v => v.Mark.ToLower() == valueParams.Mark.ToLower());
            }
            if (valueParams.Model != null)
            {
                values = values.Where(v => v.Model.ToLower() == valueParams.Model.ToLower());
            }
            if (valueParams.Year != null)
            {
                values = values.Where(v => v.year.ToLower() == valueParams.Year.ToLower());
            }
            if (valueParams.EngineCapacity != null)
            {
                values = values.Where(v => v.EngineCapacity == valueParams.EngineCapacity);
            }
            if (valueParams.PriceFrom != "0" || valueParams.PriceTo != "1000000")
            {
                values = values.Where(v =>
                                      Convert.ToInt32(v.price.Replace(" ", "")) >= Convert.ToInt32(valueParams.PriceFrom.Replace(" ", "")) &&
                                      Convert.ToInt32(v.price.Replace(" ", "")) <= Convert.ToInt32(valueParams.PriceTo.Replace(" ", "")));
            }

            if (!string.IsNullOrEmpty(valueParams.OrderBy))
            {
                switch (valueParams.OrderBy)
                {
                case "recent": values = values.OrderByDescending(v => v.Id);
                    break;

                case "mark": values = values.OrderBy(v => v.Mark);
                    break;

                case "model": values = values.OrderBy(v => v.Model);
                    break;

                case "year": values = values.OrderBy(v => v.year);
                    break;

                case "engineCapacity": values = values.OrderBy(v => v.EngineCapacity);
                    break;

                case "mileage": values = values.OrderBy(v => v.mileage);
                    break;

                case "price": values = values.OrderBy(v => Convert.ToInt32(v.price.Replace(" ", "")));
                    break;
                }
            }

            return(await PagedList <Value> .CreateListAsync(values, valueParams.PageNumber, valueParams.PageSize));
        }
Пример #2
0
        public string Format()
        {
            var sigtext = sbuild();

            sigtext.Append(ReturnType.Format());
            sigtext.Append(AsciSym.Space);
            sigtext.Append(MethodName);
            sigtext.Append(ValueParams.Format(true));
            var text = sigtext.ToString();

            return(text);
        }
Пример #3
0
        public async Task <IActionResult> GetValues([FromQuery] ValueParams valueParams)
        {
            var values = await repository.GetValues(valueParams);

            var valuesToMapping = mapper.Map <IEnumerable <ValueForListDto> >(values);

            Response.AddPagination(values.CurrentPage, values.PageSize, values.TotalCount, values.TotalPages);
            //  string price = "15 000";
            //  price = price.Replace(" ", "");
            //  int priceInt = Convert.ToInt16(price.Replace(" ", ""));
            //  Console.WriteLine("-----------------------------------------------------Cena" + priceInt);


            return(Ok(valuesToMapping));
        }