public async Task <IHttpActionResult> FindCurrencies([FromBody] SearchBindingModel search)
        {
            using (IUnitOfWork rep = Store.CreateUnitOfWork())
            {
                var items = await rep.CurrencyRepository.FindAsync(search.IsoCodes);

                if (items == null)
                {
                    return(NotFound());
                }
                return(Ok(items.AsCurrencyDTO(Url, false)));
            }
        }
Пример #2
0
        public IHttpActionResult SearchUsers([FromUri] SearchBindingModel bindingModel)
        {
            var currentUserId = this.UserIdProvider.GetUserId();
            var currentUser   = this.Data.Users.Find(currentUserId);
            var users         = this.Data
                                .Users
                                .All()
                                .OrderBy(u => u.Name)
                                .ThenBy(u => u.UserName)
                                .Where(u => u.Name.Contains(bindingModel.SearchWord))
                                .Take(5)
                                .Select(UserViewModelMinified.Create(currentUser));

            return(this.Ok(users));
        }
Пример #3
0
        public async Task <IActionResult> Search(SearchBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            var rides = (await this.ridesService
                         .GetAllUpcomingWithFreeSeatsAsync())
                        .Where(r => string.Equals(r.From, model.From, StringComparison.OrdinalIgnoreCase))
                        .Select(Mapper.Map <RideListingViewModel>);

            model.FoundRides = rides;

            return(this.View(model));
        }
Пример #4
0
        public async Task <IActionResult> Index(SearchBindingModel model)
        {
            var cookie = this.HttpContext.Request.Cookies;

            var sortDirectionKey = WebConstants.CookieUserSearchCarsSortDirectionKey;
            var sortDirection    = this.cookiesService.GetValueOrDefault <SortStrategyDirection>(cookie, sortDirectionKey);

            var sortTypeKey = WebConstants.CookieUserSearchCarsSortTypeKey;
            var sortType    = this.cookiesService.GetValueOrDefault <BaseCarSortStrategyType>(cookie, sortTypeKey);

            var sortStrategy = BaseCarSortStrategyFactory
                               .GetStrategy <BaseCar>(sortType, sortDirection);

            var splitedKeyWords = ParameterParser
                                  .ParseSearchKeyWordsParameter(model.KeyWords, WebConstants.MinSearchKeyWordLength)
                                  .Distinct()
                                  .ToArray();
            var filterStrategies = CarSearchFilterStrategyFactory.GetStrategies(splitedKeyWords);

            IEnumerable <CarInventoryConciseViewModel> carViewModels = new List <CarInventoryConciseViewModel>();
            int totalPagesCount = 0;

            if (filterStrategies.Count > 0)
            {
                var filteredCars          = this.carsService.GetFiltered <BaseCar>(filterStrategies.ToArray());
                var filteredAndSortedCars = sortStrategy.Sort(filteredCars);

                carViewModels = await(await this.carTestDriveService
                                      .GetCarTestDriveModelAsync <CarConciseTestDriveServiceModel>(filteredAndSortedCars, this.User, model.PageNumber))
                                .To <CarInventoryConciseViewModel>()
                                .ToArrayAsync();

                totalPagesCount = await PaginationHelper.CountTotalPagesCountAsync(filteredCars);
            }

            var searchModel = new CarSearchViewModel()
            {
                Cars = carViewModels,
                SortStrategyDirection = sortDirection,
                SortStrategyType      = sortType,
                CurrentPage           = model.PageNumber,
                TotalPagesCount       = totalPagesCount,
                KeyWords = splitedKeyWords
            };

            return(View(searchModel));
        }
        public ActionResult Search(SearchBindingModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                searchResults = new HashSet<CarViewModel>();

                var cars = this.Data.Cars
                    .All();

                if (model.ImporterId != 0)
                {
                    cars = cars
                        .Where(x => x.ImporterId == model.ImporterId);
                }

                if (!string.IsNullOrEmpty(model.Description))
                {
                    cars = cars.Where(x => x.Description.ToLower().Contains(model.Description.ToLower()));
                }

                var results = cars.OrderBy(x => x.YearManufactured)
                    .Select(CarViewModel.Create)
                    .AsEnumerable();

                foreach (var car in results)
                {
                    searchResults.Add(car);
                }

                return this.RedirectToAction(a => ViewResults());
            }

            this.LoadBrands();
            this.LoadImportersWithEmptyFirstField();

            return this.View(model);
        }
Пример #6
0
        public IHttpActionResult Search(SearchBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = unitOfWork.AppUsers.FirstOrDefault(u => u.Email == User.Identity.Name && u.Deleted == false);

            if (user == null)
            {
                return(BadRequest());
            }

            List <Ride> results = new List <Ride>();

            switch (user.Role)
            {
            case AppUser.UserRole.AppUser:

                results = user.CustomerRides.Where(r => model.DateFrom == null || r.OrderDT.Date.CompareTo((DateTime)model.DateFrom.Value.Date) >= 0)
                          .Where(r => model.DateTo == null || r.OrderDT.Date.CompareTo((DateTime)model.DateTo.Value.Date) <= 0)
                          .Where(r => model.PriceFrom == "" || r.Price >= double.Parse(model.PriceFrom))
                          .Where(r => model.PriceTo == "" || r.Price <= double.Parse(model.PriceTo))
                          .Where(r => model.RatingFrom == "" || r.UserComment.Count() != 0 && r.UserComment.First().Rating >= Int32.Parse(model.RatingFrom))
                          .Where(r => model.RatingTo == "" || r.UserComment.Count() != 0 && r.UserComment.First().Rating <= Int32.Parse(model.RatingTo)).ToList();

                break;

            case AppUser.UserRole.Driver:
                if (model.SearchFree == true)
                {
                    List <Ride> rides = unitOfWork.Rides.Find(r => r.Status == Status.Created).ToList();
                    results = rides.Where(r => model.DateFrom == null || r.OrderDT.Date.CompareTo((DateTime)model.DateFrom.Value.Date) >= 0)
                              .Where(r => model.DateTo == null || r.OrderDT.Date.CompareTo((DateTime)model.DateTo.Value.Date) <= 0)
                              .Where(r => model.PriceFrom == "" || r.Price >= double.Parse(model.PriceFrom))
                              .Where(r => model.PriceTo == "" || r.Price <= double.Parse(model.PriceTo))
                              .Where(r => model.RatingFrom == "" || r.UserComment.Count() != 0 && r.UserComment.First().Rating >= Int32.Parse(model.RatingFrom))
                              .Where(r => model.RatingTo == "" || r.UserComment.Count() != 0 && r.UserComment.First().Rating <= Int32.Parse(model.RatingTo)).ToList();
                }

                if (model.SearchMineD == true)
                {
                    results = user.DriverRides.Where(r => model.DateFrom == null || r.OrderDT.Date.CompareTo((DateTime)model.DateFrom.Value.Date) >= 0)
                              .Where(r => model.DateTo == null || r.OrderDT.Date.CompareTo((DateTime)model.DateTo.Value.Date) <= 0)
                              .Where(r => model.PriceFrom == "" || r.Price >= double.Parse(model.PriceFrom))
                              .Where(r => model.PriceTo == "" || r.Price <= double.Parse(model.PriceTo))
                              .Where(r => model.RatingFrom == "" || r.UserComment.Count() != 0 && r.UserComment.First().Rating >= Int32.Parse(model.RatingFrom))
                              .Where(r => model.RatingTo == "" || r.UserComment.Count() != 0 && r.UserComment.First().Rating <= Int32.Parse(model.RatingTo)).ToList();
                }
                break;

            case AppUser.UserRole.Admin:
                if (model.SearchAll == true)
                {
                    List <Ride> rides = unitOfWork.Rides.GetAll().ToList();
                    results = rides.Where(r => model.DateFrom == null || r.OrderDT.Date.CompareTo((DateTime)model.DateFrom.Value.Date) >= 0)
                              .Where(r => model.DateTo == null || r.OrderDT.Date.CompareTo((DateTime)model.DateTo.Value.Date) <= 0)
                              .Where(r => model.PriceFrom == "" || r.Price >= double.Parse(model.PriceFrom))
                              .Where(r => model.PriceTo == "" || r.Price <= double.Parse(model.PriceTo))
                              .Where(r => model.RatingFrom == "" || r.UserComment.Count() != 0 && r.UserComment.First().Rating >= Int32.Parse(model.RatingFrom))
                              .Where(r => model.RatingTo == "" || r.UserComment.Count() != 0 && r.UserComment.First().Rating <= Int32.Parse(model.RatingTo)).ToList();
                }

                if (model.SearchMine == true)
                {
                    results = user.DispatcherRides.Where(r => model.DateFrom == null || r.OrderDT.Date.CompareTo((DateTime)model.DateFrom.Value.Date) >= 0)
                              .Where(r => model.DateTo == null || r.OrderDT.Date.CompareTo((DateTime)model.DateTo.Value.Date) <= 0)
                              .Where(r => model.PriceFrom == "" || r.Price >= double.Parse(model.PriceFrom))
                              .Where(r => model.PriceTo == "" || r.Price <= double.Parse(model.PriceTo))
                              .Where(r => model.RatingFrom == "" || r.UserComment.Count() != 0 && r.UserComment.First().Rating >= Int32.Parse(model.RatingFrom))
                              .Where(r => model.RatingTo == "" || r.UserComment.Count() != 0 && r.UserComment.First().Rating <= Int32.Parse(model.RatingTo)).ToList();
                }
                break;
            }

            return(Ok(results));
        }