public async Task <JHomeModel> GetAllJobs(int UserId) { JHomeModel jobs = new JHomeModel(); try { if (CrossConnectivity.Current.IsConnected) { HttpClient httpClient = new HttpClient(); var uri = new Uri(string.Concat(Constants.baseUrl, "api/Jobs?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(); jobs = JsonConvert.DeserializeObject <JHomeModel>(result); } else { } } } catch (Exception e) { Console.Write(e.StackTrace); } return(jobs); }
async void ShowJobFullList() { try { aiJobPost.IsRunning = true; JHomeModel js = new JHomeModel(); JobServices jobServices = new JobServices(); RegisterUserModel loggedUser = App.Database.GetLoggedUser(); if (loggedUser == null) { js = await jobServices.GetAllJobs(0); } else { js = await jobServices.GetAllJobs(loggedUser.Id); } lblJobFullCount.Text = js.Total + " Job posts found"; for (int i = 0; i < js.Data.Count(); i++) { JobsHome j = js.Data.ElementAt(i); if (j != null) { if (j.BookMark) { j.BookmarkImage = "save_filled.png"; } else { j.BookmarkImage = "save.png"; } if (j.JobType == "N") { j.JobType = "Normal"; j.JobBgColor = "#289EF5"; j.JobTextColor = "#FFFFFF"; } else if (j.JobType == "U") { j.JobType = "Urgent"; j.JobBgColor = "#F63D38"; j.JobTextColor = "#FFFFFF"; } else { j.JobType = "Sponsored"; j.JobBgColor = "#FCDC55"; j.JobTextColor = "#000000"; } } if (j.Location != null && j.Location.Count() > 0) { j.JobLocationName = j.Location.ElementAt(0).LocationName; } if (j.IsDaily) { j.JobPriceLabel = "From $" + j.MinDailyPrice.Remove(j.MinDailyPrice.IndexOf(".")) + "-$" + j.MaxDailyPrice.Remove(j.MaxDailyPrice.IndexOf(".")) + "/Day"; } else if (j.IsMonthly) { j.JobPriceLabel = "From $" + j.MinMonthlyPrice.Remove(j.MinMonthlyPrice.IndexOf(".")) + "-$" + j.MaxMonthlyPrice.Remove(j.MaxMonthlyPrice.IndexOf(".")) + "/Month"; } else if (j.IsHourly) { j.JobPriceLabel = "From $" + j.MinHourlyPrice.Remove(j.MinHourlyPrice.IndexOf(".")) + "-$" + j.MaxHourlyPrice.Remove(j.MaxHourlyPrice.IndexOf(".")) + "/Hour"; } j.createDate = j.CreateDate.Substring(0, 10); js.Data.Select(x => x.JobId == j.JobId ? j : x); } jobsViewModel.JobFullList = new ObservableCollection <JobsHome>(js.Data); lvFullJobPost.ItemsSource = jobsViewModel.JobFullList; //lblJobsCount.Text = js.Count() + " Jobs found in " + selectedHelpersInCluster.LocationName; aiJobPost.IsRunning = false; } catch (Exception e) { Console.Write(e.StackTrace); } }