示例#1
0
        public void GetCategories()
        {
            try
            {
                var apiUrl = Application.Current.Properties["DomainUrl"] + "/api/services/GetServiceCategoriesForCompany?companyId=" + CompanyId;
                var result = PostData("GET", "", apiUrl);
                ObservableCollection <Category> ListofAllCategories = JsonConvert.DeserializeObject <ObservableCollection <Category> >(result);
                foreach (var item in ListofAllCategories)
                {
                    var ApiUrl     = Application.Current.Properties["DomainUrl"] + "api/services/GetAllServicesForCategory?companyId=" + CompanyId + "&categoryId=" + item.Id;
                    var resultData = PostData("GET", "", ApiUrl);
                    ObservableCollection <Service> ListOfAssignService = JsonConvert.DeserializeObject <ObservableCollection <Service> >(resultData);

                    ServicesAllocatedToCategory AllocateServices = new ServicesAllocatedToCategory();
                    AllocateServices.CategoryName          = item.Name;
                    AllocateServices.CategoryId            = item.Id;
                    AllocateServices.AllocatedServiceCount = ListOfAssignService.Count + "services";

                    ListOfAssignServiceCount.Add(AllocateServices);
                }
                ListofCategoriesData.ItemsSource = ListOfAssignServiceCount;
                BindingContext = ListOfAssignServiceCount;
            }
            catch (Exception e)
            {
                e.ToString();
            }
        }
        public void GetCategories(string Id)
        {
            try
            {
                //Get ListOfAssignServices
                var apiUrl = Application.Current.Properties["DomainUrl"] + "/api/services/GetServiceCategoriesForCompany?companyId=" + Id;
                var result = PostData("GET", "", apiUrl);
                ObservableCollection <Category> ListofAllCategories = JsonConvert.DeserializeObject <ObservableCollection <Category> >(result);
                foreach (var item in ListofAllCategories)
                {
                    var ApiUrl     = Application.Current.Properties["DomainUrl"] + "/api/services/GetAllServicesForCategory?companyId=" + CompanyId + "&categoryId=" + item.Id;
                    var resultData = PostData("GET", "", ApiUrl);
                    ObservableCollection <Service> ListOfAssignService = JsonConvert.DeserializeObject <ObservableCollection <Service> >(resultData);
                    ServicesAllocatedToCategory    AllocateServices    = new ServicesAllocatedToCategory();
                    AllocateServices.CategoryName          = item.Name;
                    AllocateServices.CategoryId            = item.Id;
                    AllocateServices.AllocatedServiceCount = ListOfAssignService.Count + " services";
                    ListOfAssignServiceCount.Add(AllocateServices);
                }
                ListofCategoriesData.ItemsSource = ListOfAssignServiceCount;


                var apiU    = Application.Current.Properties["DomainUrl"] + "api/services/GetServicesForCompany?companyId=" + Id;
                var results = PostData("Get", "", apiU);
                ObservableCollection <Service> ListOfAllService = JsonConvert.DeserializeObject <ObservableCollection <Service> >(results);
                AllCompanyServicess.Text = ListOfAllService.Count + " services";



                foreach (var item in ListofAllCategories)
                {
                    var ApiUrl     = Application.Current.Properties["DomainUrl"] + "/api/services/GetAllServicesForCategory?companyId=" + CompanyId + "&categoryId=" + item.Id;
                    var resultData = PostData("GET", "", ApiUrl);
                    ObservableCollection <Service> ListOfAssignServices = JsonConvert.DeserializeObject <ObservableCollection <Service> >(resultData);


                    foreach (var items in ListOfAssignServices)
                    {
                        Service obj = new Service();
                        obj.Id   = items.Id;
                        obj.Name = items.Name;
                        ListOfServiceCount.Add(obj);
                    }
                }
                var dd = ListOfServiceCount.Select(x => x.Name).Distinct().ToList();
                dd = dd.Distinct(StringComparer.InvariantCultureIgnoreCase).ToList();

                var dds = ListOfAllService.Select(x => x.Name).Distinct().ToList();
                dds = dds.Distinct(StringComparer.InvariantCultureIgnoreCase).ToList();

                foreach (var item in dd.ToArray())
                {
                    foreach (var items in dds.ToArray())
                    {
                        if (item.ToString() == items.ToString())
                        {
                            dd.Remove(item);
                            dds.Remove(items);

                            //Service obj = new Service();
                            //obj.Name = item.ToString();
                            //ListOfNotServiceCount.Add(obj);
                        }
                    }
                }


                foreach (var item in dds)
                {
                    Service obj = new Service();
                    obj.Name = item.ToString();
                    ListOfNotServiceCount.Add(obj);
                }
                ListofNotAssignData.ItemsSource = ListOfNotServiceCount;
            }
            catch (Exception e)
            {
                e.ToString();
            }
        }