public async void GetControls() { if (SelectedOffice != null) { try { IsBusy = true; // Dbcontext = new ServiceReference1.Service1Client(ServiceReference1.Service1Client.EndpointConfiguration.BasicHttpBinding_IService1); // await Dbcontext.OpenAsync(); InternalControlOffice cont; InternalControlOfficeGoal goal; var result = Dbcontext.GetOfficeInternalControls(Application.Current.Properties["UN"].ToString(), Application.Current.Properties["PW"].ToString(), Application.Current.Properties["Ucid"].ToString(), SelectedOffice.Id); ObservableCollection <InternalControlOffice> temp = new ObservableCollection <InternalControlOffice>(); if (result != null && result.Length > 0) { foreach (ServiceReference1.InternalControlOfficeData data in result) { cont = new InternalControlOffice(); cont.Id = data.Id; cont.Name = data.Name; //cont.CountThisMonth = data.PerformedThisMonth + " st"; //cont.CountThisYear = data.PerformedThisYear + " st"; cont.Goals = new ObservableCollection <InternalControlOfficeGoal>(); goal = new InternalControlOfficeGoal(); goal.BrandName = "Tot mån"; goal.MonthResult = data.PerformedThisMonth + " st"; cont.Goals.Add(goal); goal = new InternalControlOfficeGoal(); goal.BrandName = "Tot år"; goal.MonthResult = data.PerformedThisYear + " st"; cont.Goals.Add(goal); if (data.Goals != null && data.Goals.Count() > 0) { foreach (InternalControlBrandGoalData goaldata in data.Goals) { goal = new InternalControlOfficeGoal(); goal.BrandName = goaldata.BrandName; goal.MonthResult = goaldata.MonthResult + "/" + goaldata.MonthGoal; goal.YearResult = goaldata.YearResult + "/" + goaldata.YearGoal; cont.Goals.Add(goal); } } temp.Add(cont); } } // await Dbcontext.CloseAsync(); AllInternalControls = new ObservableCollection <InternalControlOffice>(temp); IsBusy = false; } catch (Exception e) { IsBusy = false; await Application.Current.MainPage.DisplayAlert("Fel", e.Message, "Stäng"); } } }