public async Task <HHomeModel> GetAllHelpers(int UserId)
        {
            HHomeModel helpers = new HHomeModel();

            try
            {
                if (CrossConnectivity.Current.IsConnected)
                {
                    HttpClient httpClient = new HttpClient();
                    var        uri        = new Uri(string.Concat(Constants.baseUrl, "api/Home?UserId=" + UserId + "&PageNo=0"));

                    //var response = await httpClient.GetAsync(uri);

                    var requestTask = httpClient.GetAsync(uri);
                    var response    = Task.Run(() => requestTask);

                    if (response.Result.IsSuccessStatusCode)
                    {
                        string result = await response.Result.Content.ReadAsStringAsync();

                        helpers = JsonConvert.DeserializeObject <HHomeModel>(result);
                    }
                    else
                    {
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write(e.StackTrace);
            }

            return(helpers);
        }
Exemple #2
0
        async void ShowHelperFullList()
        {
            try
            {
                aiFindHelper.IsRunning = true;

                HHomeModel      hService        = new HHomeModel();
                HelpersServices helpersServices = new HelpersServices();

                RegisterUserModel loggedUser = App.Database.GetLoggedUser();
                if (loggedUser == null)
                {
                    hService = await helpersServices.GetAllHelpers(0);
                }
                else
                {
                    hService = await helpersServices.GetAllHelpers(loggedUser.Id);
                }

                var hs = hService.Data;

                lblHelperFullCount.Text = hService.Total + " Helpers found";

                for (int i = 0; i < hs.Count(); i++)
                {
                    HelperHome h = hs.ElementAt(i);
                    if (h.ProfilePicture == null)
                    {
                        h.ProfilePicture = "profile_default.png";
                    }

                    if (h.BookMark)
                    {
                        h.BookmarkImage = "save_filled.png";
                    }
                    else
                    {
                        h.BookmarkImage = "save.png";
                    }

                    if (h.Service != null && h.Service.Count() != 0)
                    {
                        HService hserv = h.Service.Where(x => x.ServiceName == "ChildCare").FirstOrDefault();
                        if (hserv == null)
                        {
                            hserv         = h.Service.ElementAt(h.Service.Count() - 1);
                            h.ServiceName = hserv.ServiceName;
                            if (hserv.price.Daily)
                            {
                                h.ServicePriceLabel = "from $" + hserv.price.Min.Remove(hserv.price.Min.IndexOf(".")) + "-$" + hserv.price.Max.Remove(hserv.price.Max.IndexOf(".")) + "/Day";
                            }
                            else if (hserv.price.Monthly)
                            {
                                h.ServicePriceLabel = "from $" + hserv.price.Min.Remove(hserv.price.Min.IndexOf(".")) + "-$" + hserv.price.Max.Remove(hserv.price.Max.IndexOf(".")) + "/Month";
                            }
                            else if (hserv.price.Hours)
                            {
                                h.ServicePriceLabel = "from $" + hserv.price.Min.Remove(hserv.price.Min.IndexOf(".")) + "-$" + hserv.price.Max.Remove(hserv.price.Max.IndexOf(".")) + "/Hour";
                            }

                            if (hserv.Location != null && hserv.Location.Count() > 0)
                            {
                                h.ServiceLocationName = hserv.Location.ElementAt(0).LocationName;
                            }
                            /* source.Select(element => element == oldValue ? newValue : element) */

                            if (h.AverageRatingCount == null)
                            {
                                h.AverageRatingCount = "(0)";
                            }
                            else
                            {
                                h.AverageRatingCount = h.AverageRating + " (" + h.AverageRatingCount + ")";
                            }

                            if (h.Status)
                            {
                                h.bgcolor      = "#32BDA0";
                                h.textcolor    = "#FFFFFF";
                                h.helperStatus = "Available";
                            }
                            else
                            {
                                h.bgcolor      = "#EAE9E9";
                                h.textcolor    = "#000000";
                                h.helperStatus = "Not Available";
                            }

                            if (h.AverageRating == null)
                            {
                                h.AverageRating = "0";
                            }

                            hs.Select(x => x.Name == h.Name ? h : x);
                        }
                    }
                }

                helpersViewModel.HelperFullList = new ObservableCollection <HelperHome>(hs);
                lvFullHelpa.ItemsSource         = helpersViewModel.HelperFullList;
                //lblHelperCount.Text = hs.Count() + " Helpers found in " + selectedHelpersInCluster.LocationName;

                aiFindHelper.IsRunning = false;
            }
            catch (Exception e)
            {
                Console.Write(e.StackTrace);
                aiFindHelper.IsRunning = false;
            }
        }