示例#1
0
 public async Task <NationalitiesApiResponse> InfoNationalitiesAsync(NationalitiesArgs args)
 {
     return(await TryInvoceAsync <NationalitiesApiResponse>(async() =>
     {
         var httpClient = GetHttpClientWidthAuthenticationHeader();
         var content = new StringContent(JsonConvert.SerializeObject(args), Encoding.UTF8,
                                         "application/json");
         return await httpClient.PostAsync("info/nationalities", content);
     }));
 }
示例#2
0
        public async Task <IEnumerable <ApiNationality> > GetNationalitiesAsync(NationalitiesArgs args)
        {
            var apiNationalitiesRespobse = await _apiClient.InfoNationalitiesAsync(args);

            if (!apiNationalitiesRespobse.Success)
            {
                App.Dialogs.ErrorToast("error", apiNationalitiesRespobse.Error);
                return(new List <ApiNationality>());
            }

            return(apiNationalitiesRespobse.Nationalities ?? new List <ApiNationality>());
        }
示例#3
0
        public List <ApiNationality> GetNationalitiesForApi(NationalitiesArgs args, out int total)
        {
            var culture = CultureHelper.GetCurrentCulture();
            Expression <Func <NationalityEntity, bool> > searchPredicate = nationality => true;
            Expression <Func <NationalityEntity, bool> > idPredicate     = nationality => true;
            Expression <Func <NationalityEntity, bool> > notDeleted      = nationality => !nationality.IsDeleted;

            if (args.Id != null)
            {
                idPredicate = nationality => nationality.Id == args.Id;
            }

            if (!string.IsNullOrWhiteSpace(args.Search))
            {
                if (culture == "ar")
                {
                    searchPredicate = nationality => nationality.Name.Ar.Contains(args.Search);
                }
                else
                {
                    searchPredicate = nationality => nationality.Name.En.Contains(args.Search);
                }
            }

            total = UnitOfWork.Context.Set <NationalityEntity>()
                    .Where(idPredicate)
                    .Where(searchPredicate)
                    .Where(notDeleted)
                    .Count();

            var nationalities =
                UnitOfWork.Context.Set <NationalityEntity>()
                .Where(idPredicate)
                .Where(searchPredicate)
                .Where(notDeleted)
                .OrderBy(nationality => nationality.Id)
                .Skip(args.Paging.PageNumber * args.Paging.PageSize)
                .Take(args.Paging.PageSize == 0 ? total : args.Paging.PageSize)
                .ToList();

            var list = nationalities.Select(nationality => new ApiNationality
            {
                Id   = nationality.Id,
                Name = nationality.Name.Default
            }).ToList();

            return(list);
        }
示例#4
0
        public NationalitiesApiResponse GetNationalities(NationalitiesArgs args)
        {
            return(TryInvoce(() =>
            {
                var result = new NationalitiesApiResponse {
                    Lang = Language
                };
                int total;
                var nationalities = _nationalitiesService.GetNationalitiesForApi(args, out total);

                result.Paging.TotalCount = total;
                result.Paging.PageNumber = args.Paging.PageNumber;
                result.Paging.PageSize = args.Paging.PageSize;
                result.Nationalities = nationalities;

                return result;
            }));
        }
示例#5
0
 public NationalitiesViewModel(IWebService webService) : base(webService)
 {
     Title = "Select nationality";
     State = Helpers.WaitPageState.Wait;
     _nationalitiesArgs = new NationalitiesArgs();
 }