Beispiel #1
0
 public async Task <AgenciesApiResponse> InfoAgenciesAsync(AgenciesArgs args)
 {
     return(await TryInvoceAsync <AgenciesApiResponse>(async() =>
     {
         var httpClient = GetHttpClientWidthAuthenticationHeader();
         var content = new StringContent(JsonConvert.SerializeObject(args), Encoding.UTF8,
                                         "application/json");
         return await httpClient.PostAsync("info/agencies", content);
     }));
 }
Beispiel #2
0
        public async Task <IEnumerable <ApiAgency> > GetAgenciesAsync(AgenciesArgs args)
        {
            var apiLanguagesRespobse = await _apiClient.InfoAgenciesAsync(args);

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

            return(apiLanguagesRespobse.Agancies ?? new List <ApiAgency>());
        }
Beispiel #3
0
        public AgenciesApiResponse GetAgencies(AgenciesArgs args)
        {
            return(TryInvoce(() =>
            {
                var result = new AgenciesApiResponse {
                    Lang = Language
                };
                int total;
                var agancies = _agenciesService.GetAgenciesForApi(args, out total);

                result.Paging.TotalCount = total;
                result.Paging.PageNumber = args.Paging.PageNumber;
                result.Paging.PageSize = args.Paging.PageSize;
                result.Agancies = agancies;

                return result;
            }));
        }
Beispiel #4
0
        public List <ApiAgency> GetAgenciesForApi(AgenciesArgs args, out int total)
        {
            var culture = CultureHelper.GetCurrentCulture();
            Expression <Func <AgencyEntity, bool> > searchPredicate = agency => true;
            Expression <Func <AgencyEntity, bool> > idPredicate     = agency => true;
            Expression <Func <AgencyEntity, bool> > notDeleted      = agency => !agency.IsDeleted;

            if (args.Id != null)
            {
                idPredicate = agency => agency.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 <AgencyEntity>()
                    .Where(idPredicate)
                    .Where(searchPredicate)
                    .Where(notDeleted)
                    .Count();

            var agencies =
                UnitOfWork.Context.Set <AgencyEntity>()
                .Include(agency => agency.City)
                .Include(agency => agency.City.Country)
                .Where(idPredicate)
                .Where(searchPredicate)
                .Where(notDeleted)
                .OrderBy(agency => agency.Name.En)
                .Skip(args.Paging.PageNumber * args.Paging.PageSize)
                .Take(args.Paging.PageSize == 0 ? total : args.Paging.PageSize)
                .ToList();

            var list = agencies.Select(agency => new ApiAgency
            {
                Id                 = agency.Id,
                Name               = agency.Name.Default,
                Logo               = agency.Logo,
                Address            = agency.Address.Default,
                TradeLicenseNumber = agency.TradeLicenseNumber,
                Email              = agency.Email,
                Phone              = agency.City != null ? "1" : "0" /*agency.Phone*/,
                Mobile             = agency.Mobile,
                City               = agency.City != null
                    ? new ApiCity
                {
                    Id        = agency.City.Id,
                    Name      = agency.City.Name?.Default,
                    CountryId = agency.City.CountryId,
                    Country   = agency.City.Country != null
                            ? new ApiCountry
                    {
                        Id          = agency.City.CountryId,
                        CountryCode = agency.City.Country.CountryCode,
                        Name        = agency.City.Country.Name.Default
                    }
                            : null
                }
                    : null
            }).ToList();

            return(list);
        }