public ActionResult Search(Guid countryId)
        {
            var countriesResult = client.Get <List <SelectModel> >(APIUrls.CountryIdNames);
            var countryResult   = GetCountryById(countryId);
            var userResult      = client.Get <CMS_Db.Entity.User>(APIUrls.LoggedInUser);
            var selectList      = new SelectList(countriesResult.Data, "Id", "Name");
            var user            = (CMS_Entity.Db.User) this.HttpContext.Cache[KeyConstants.User.ToString()];

            var fevCountry = countryResult.Data.FavoriteUserCountries.FirstOrDefault(c => user.Id.Equals(c.UserId));

            if (fevCountry == null)
            {
                fevCountry = new FavoriteUserCountry()
                {
                    UserId = user.Id, CountryId = countryResult.Data.Id, IsFavorite = false
                };
            }

            SearchCountryViewModel searchCountry = new SearchCountryViewModel()
            {
                CountriesToSearch = selectList,
                Country           = countryResult.Data,
                FevCountry        = fevCountry,
            };

            return(View(searchCountry));
        }
Esempio n. 2
0
        // GET: Settings/Places
        public ActionResult Index(SearchCountryViewModel searchModel)
        {
            PagedEntity <CountryViewModel> result = _placesService.GetCountries(searchModel);

            searchModel.Items = new PagedList.StaticPagedList <CountryViewModel>(result.Items
                                                                                 , searchModel.PageIndex + 1, searchModel.PageSize, result.TotalCount);
            return(View(searchModel));
        }
        // GET: Countries
        public ActionResult Search()
        {
            var result     = client.Get <List <SelectModel> >(APIUrls.CountryIdNames);
            var selectList = new SelectList(result.Data, "Id", "Name");

            SearchCountryViewModel searchCountry = new SearchCountryViewModel()
            {
                CountriesToSearch = selectList
            };

            return(View(searchCountry));
        }
Esempio n. 4
0
        // GET: Settings/Places
        public ActionResult Index(SearchCountryViewModel searchModel)
        {
            PagedEntity <CountryViewModel> result = _placesService.GetCountries(searchModel);
            var pagedList = new PagedList.StaticPagedList <CountryViewModel>(result.Items
                                                                             , searchModel.PageIndex + 1, searchModel.PageSize, result.TotalCount);

            if (pagedList.Count == 0 && pagedList.TotalItemCount > 0)
            {
                searchModel.PageIndex = pagedList.HasPreviousPage ?
                                        pagedList.PageNumber - 2 : 0;
                return(RedirectToAction("Index", searchModel));
            }

            searchModel.Items = pagedList;
            return(View(searchModel));
        }
Esempio n. 5
0
        public PagedEntity <CountryViewModel> GetCountries(SearchCountryViewModel searchCountryModel)
        {
            if (searchCountryModel == null)
            {
                searchCountryModel = new SearchCountryViewModel();
            }

            ExpressionSpecification <Country> specification
                = new ExpressionSpecification <Country>(c =>
                                                        (string.IsNullOrEmpty(searchCountryModel.CountryName) ||
                                                         c.Name.Contains(searchCountryModel.CountryName) ||
                                                         c.NameEn.Contains(searchCountryModel.CountryName)) &&
                                                        (string.IsNullOrEmpty(searchCountryModel.CountryCode) ||
                                                         c.Code.Contains(searchCountryModel.CountryCode)));

            var result = _unitOfWork.CountryRepository.Find(specification, searchCountryModel.PageIndex, searchCountryModel.PageSize);

            return(new PagedEntity <CountryViewModel>(result.Items.Select(c => c.ToCountryModel()), result.TotalCount));
        }
Esempio n. 6
0
        public void GetCountries_WithValidAndInvalidIndex_GetItemsOrEmptyItems
            ([Values("", "Country")] string countryName, [Values(0, 20)] int pageIndex)
        {
            SearchCountryViewModel searchViewModel = new SearchCountryViewModel
            {
                PageIndex = pageIndex,
            };

            var countriesPage = _placesServices.GetCountries(searchViewModel);

            countriesPage.TotalCount.Should().BeGreaterOrEqualTo(1);
            if (pageIndex == 0)
            {
                countriesPage.Items.Count().Should().BeGreaterOrEqualTo(1);
            }
            else
            {
                countriesPage.Items.Count().Should().Be(0);
            }
        }
Esempio n. 7
0
        public CountryViewModel Countries(int page, SearchCountryViewModel search)
        {
            int pageSize           = 1;
            int pageNo             = page - 1;
            CountryViewModel model = new CountryViewModel();

            var query = _countryRepository
                        .GetAllCountries();

            if (!string.IsNullOrEmpty(search.Name))
            {
                query = query.Where(c => c.Name.Contains(search.Name));
            }
            if (!string.IsNullOrEmpty(search.Priority))
            {
                int priority;
                int.TryParse(search.Priority, out priority);
                query = query.Where(c => c.Priority == priority);
            }
            model.Countries = query
                              .OrderBy(c => c.Id)
                              .Skip(pageNo * pageSize)
                              .Take(pageSize)
                              .Select(c => new CountryItemViewModel
            {
                Id         = c.Id,
                Name       = c.Name,
                DateCreate = c.DateCreate,
                Priority   = c.Priority
            });
            int count = query.Count();

            model.TotalPage   = (int)Math.Ceiling((double)count / pageSize);
            model.CurrentPage = page;
            model.Search      = search;
            return(model);
        }
Esempio n. 8
0
 public SearchCountryPage()
 {
     InitializeComponent();
     BindingContext = viewModel = new SearchCountryViewModel(new RestService());
 }
Esempio n. 9
0
        // GET: Admin/Location
        public ActionResult Index(SearchCountryViewModel search, int page = 1)
        {
            var model = _locationProvider.Countries(page, search);

            return(View(model));
        }