public List <ApiCity> GetCitiesForApi(CitiesArgs args, out int total) { var culture = CultureHelper.GetCurrentCulture(); Expression <Func <CityEntity, bool> > searchPredicate = city => true; Expression <Func <CityEntity, bool> > idPredicate = city => true; Expression <Func <CityEntity, bool> > notDeleted = city => !city.IsDeleted; if (args.Id != null) { idPredicate = city => city.Id == args.Id; } if (!string.IsNullOrWhiteSpace(args.Search)) { if (culture == "ar") { searchPredicate = city => city.Name.Ar.Contains(args.Search); } else { searchPredicate = city => city.Name.En.Contains(args.Search); } } total = UnitOfWork.Context.Set <CityEntity>() .Where(idPredicate) .Where(searchPredicate) .Where(notDeleted) .Count(); var nationalities = UnitOfWork.Context.Set <CityEntity>() .Where(idPredicate) .Where(searchPredicate) .Where(notDeleted) .OrderBy(city => city.Name.En) .Skip(args.Paging.PageNumber * args.Paging.PageSize) .Take(args.Paging.PageSize == 0 ? total : args.Paging.PageSize) .ToList(); var list = nationalities.Select(city => new ApiCity { Id = city.Id, Name = city.Name.Default, CountryId = city.CountryId, Country = city.Country != null ? new ApiCountry { Id = city.CountryId, CountryCode = city.Country.CountryCode, Name = city.Country.Name?.Default } : null }).ToList(); return(list); }
public async Task <CitiesApiResponse> InfoCitiesAsync(CitiesArgs args) { return(await TryInvoceAsync <CitiesApiResponse>(async() => { var httpClient = GetHttpClientWidthAuthenticationHeader(); var content = new StringContent(JsonConvert.SerializeObject(args), Encoding.UTF8, "application/json"); return await httpClient.PostAsync("info/cities", content); })); }
public async Task <IEnumerable <ApiCity> > GetCitiesAsync(CitiesArgs args) { var apiCitiesResponse = await _apiClient.InfoCitiesAsync(args); if (!apiCitiesResponse.Success) { App.Dialogs.ErrorToast("error", apiCitiesResponse.Error); return(new List <ApiCity>()); } return(apiCitiesResponse.Cities ?? new List <ApiCity>()); }
public CitiesApiResponse GetCities(CitiesArgs args) { return(TryInvoce(() => { var result = new CitiesApiResponse { Lang = Language }; int total; var cities = _citiesService.GetCitiesForApi(args, out total); result.Paging.TotalCount = total; result.Paging.PageNumber = args.Paging.PageNumber; result.Paging.PageSize = args.Paging.PageSize; result.Cities = cities; return result; })); }
public CitiesViewModel(IWebService webService) : base(webService) { Title = "Select city"; State = Helpers.WaitPageState.Wait; _citiesArgs = new CitiesArgs(); }