internal async System.Threading.Tasks.Task CreateCategoryAsync()
        {
            if (NewCategoryName == "")
            {
                ErrorMessage = "Please enter the new category's name";
            }
            else if (CategoryNameIsInUse())
            {
                ErrorMessage = "That category name is already in use";
            }
            else
            {
                var values = new Dictionary <string, string>
                {
                    { "Name", NewCategoryName }
                };
                var content = new FormUrlEncodedContent(values);
                var result  = await Client.HttpClient.PostAsync("http://localhost:65177/api/Category", content);

                if (result.StatusCode == HttpStatusCode.OK)
                {
                    CategoriesList.Add(System.Threading.Tasks.Task.Run(() => GetCategories()).Result.Last());
                }
            }
        }
Ejemplo n.º 2
0
        public void AddCategoriesOption(CategoriesListApiViewModel categories, int regionId)
        {
            CategoriesList.TryGetValue(regionId, out Dictionary <string, UniversalSwitchViewModel> dictionaryForRegion);

            bool IsExist = dictionaryForRegion != null;

            if (!IsExist)
            {
                dictionaryForRegion = new Dictionary <string, UniversalSwitchViewModel>();
            }

            foreach (var category in categories.Category)
            {
                dictionaryForRegion.Add(category.Value, new UniversalSwitchViewModel {
                    Id = category.Key, Value = false
                });
            }

            if (IsExist)
            {
                CategoriesList[regionId] = dictionaryForRegion;
            }
            else
            {
                CategoriesList.Add(regionId, dictionaryForRegion);
            }
        }
 public HomeViewModel(List <Category> allCategories)
     : this()
 {
     foreach (Category category in allCategories)
     {
         HomeCategoriesViewModel item = new HomeCategoriesViewModel(category);
         CategoriesList.Add(item);
     }
 }
Ejemplo n.º 4
0
        public void InitializeCategoriesList(List <Category> catsList)
        {
            foreach (var category in catsList)
            {
                var newItem = new SelectListItem();
                newItem.Text  = category.CategoryTitle;
                newItem.Value = category.CategoryId.ToString();

                CategoriesList.Add(newItem);
            }
        }
Ejemplo n.º 5
0
        private void RefreshData()
        {
            CategoriesList.Clear();
            var tmp = CategoriesFunctions.GetAllCategories();

            foreach (var showableCategory in tmp)
            {
                CategoriesList.Add(showableCategory);
            }
            RefreshOverridingPossibilities();
            DataGrid.Items.Refresh();
        }
Ejemplo n.º 6
0
        public async Task RefresCategoriesAsync()
        {
            var result = await new CategoryService().GetCategoriesAsync();
            var data   = result.ToList();

            data.Insert(0, new Category()
            {
                CategoryId = -1, Name = "Add New Category"
            });
            CategoriesList.Clear();
            foreach (var item in data)
            {
                CategoriesList.Add(item);
            }
        }
        public async Task ListCategories()
        {
            APIResponse response = await GetCategories.ExecuteStrategy(null);

            if (response.IsSuccess)
            {
                Categories = JsonConvert.DeserializeObject <List <CategoryModel> >(response.Response);
                foreach (var c in Categories)
                {
                    CategoriesList.Add(c);
                }
            }
            else
            {
                Exception e;
            }
        }
        private CategoriesList BuildCategories()
        {
            CategoriesList categoriesList = new CategoriesList();

            try
            {
                string filepath =  System.Web.Hosting.HostingEnvironment.MapPath("~/data/Categories.xml"); 
                XmlDocument xmlDocument = new XMLConnector().GetXMLDocument(filepath);

                XmlNodeList categoryNodes = xmlDocument.SelectNodes("categories/category");
                if (categoryNodes != null)
                {
                    foreach (XmlNode categoryNode in categoryNodes)
                    {
                        string id = categoryNode.Attributes["id"].Value;                        
                        CategoryItem categoryItem = new CategoryItem(id);
                        categoryItem.Title = categoryNode.Attributes["title"].Value;

                        XmlNodeList providerMappingsNodes = categoryNode.SelectNodes("provider-mappings/provider-mapping");
                        if (providerMappingsNodes != null)
                        {
                            ProviderMappingList providerMappingList = categoryItem.ProviderMappingList;
                            foreach (XmlNode providerMappingNode in providerMappingsNodes)
                            {
                                ProviderMapping providerMapping = new ProviderMapping();
                                providerMapping.Provider = (ProviderEnum) Enum.Parse(typeof(ProviderEnum), providerMappingNode.Attributes["id"].Value);
                                providerMapping.Category = providerMappingNode.Attributes["category"].Value;

                                providerMappingList.Add(providerMapping);
                            }
                        }

                        XmlNodeList topicsNodes = categoryNode.SelectNodes("topics/topic");
                        if (topicsNodes != null)
                        {
                            TopicList topicList = categoryItem.TopicList;
                            foreach (XmlNode topicNode in topicsNodes)
                            {
                                string title = topicNode.Attributes["title"].Value;
                                TopicItem topicItem = new TopicItem(title, title);
                                topicList.Add(topicItem);
                            }
                        }

                        categoriesList.Add(categoryItem);
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorService.Log("CategorizationService", "BuildCategories", null, exception);
            }

            return categoriesList;
        }
 public void SelectCategory(CategoryViewModel categoryModel)
 {
     if (BackgroundTask.Instance.IsExecuting)
     {
         return;
     }
     if (categoryModel.Category is NextPageCategory)
     {
         // discover and append next page categories
         BackgroundTask.Instance.Start <bool>(
             () =>
         {
             SelectedSite.Site.DiscoverNextPageCategories(categoryModel.Category as NextPageCategory);
             return(true);
         },
             (success, result) =>
         {
             if (success)
             {
                 int selectNr = CategoriesList.Count - 1;
                 CategoriesList.Clear();
                 IList <Category> catList = categoryModel.Category.ParentCategory == null ? (IList <Category>)SelectedSite.Site.Settings.Categories : categoryModel.Category.ParentCategory.SubCategories;
                 foreach (Category c in catList)
                 {
                     CategoriesList.Add(new CategoryViewModel(c)
                     {
                         Selected = CategoriesList.Count == selectNr
                     });
                 }
                 ImageDownloader.GetImages <Category>(catList);
                 CategoriesList.FireChange();
             }
         },
             Translation.Instance.GettingNextPageVideos);
     }
     else
     {
         if (categoryModel.Category.HasSubCategories)
         {
             if (!categoryModel.Category.SubCategoriesDiscovered)
             {
                 // discover and show subcategories
                 BackgroundTask.Instance.Start <bool>(
                     () =>
                 {
                     SelectedSite.Site.DiscoverSubCategories(categoryModel.Category);
                     return(true);
                 },
                     (success, result) =>
                 {
                     if (success)
                     {
                         SelectedCategory = categoryModel;
                         ShowCategories(categoryModel.Category.SubCategories, categoryModel.Name);
                     }
                 },
                     Translation.Instance.GettingDynamicCategories);
             }
             else
             {
                 SelectedCategory = categoryModel;
                 ShowCategories(categoryModel.Category.SubCategories, categoryModel.Name);
             }
         }
         else
         {
             // discover and show videos of this category
             BackgroundTask.Instance.Start <List <VideoInfo> >(
                 () =>
             {
                 return(SelectedSite.Site.GetVideos(categoryModel.Category));
             },
                 (success, videos) =>
             {
                 if (success)
                 {
                     ShowVideos(categoryModel, videos);
                 }
             },
                 Translation.Instance.GettingCategoryVideos);
         }
     }
 }
Ejemplo n.º 10
0
        public void Add <T>(T model)
        {
            var theType = model.GetType().Name;

            switch (theType)
            {
            case "User": UsersList.Add(model as User); return;

            case "News": NewsesList.Add(model as Dal.Models.News); return;

            case "Category": CategoriesList.Add(model as Category); return;

            case "Magazine": MagazinesList.Add(model as Magazine); return;

            case "SmartLink": SmartLinksList.Add(model as SmartLink); return;

            case "Comment": CommentsList.Add(model as Comment); return;

            case "Visit": VisitsList.Add(model as Visit); return;

            case "NewsLetter": NewsLettersList.Add(model as NewsLetter); return;

            case "Slider": SlidersList.Add(model as Slider); return;

            case "Slide": SlidesList.Add(model as Slide); return;

            case "UserMagazine": UserMagazinesList.Add(model as UserMagazine); return;

            case "State": StatesList.Add(model as State); return;

            case "City": CitiesList.Add(model as City); return;

            case "Media": MediasList.Add(model as Media); return;

            case "Report": ReportsList.Add(model as Report); return;

            case "Vote": VotesList.Add(model as Vote); return;

            case "Advertise": AdvertisesList.Add(model as Advertise); return;

            case "AdCategory": AdCategoriesList.Add(model as AdCategory); return;

            case "Galery": GaleriesList.Add(model as Galery); return;

            case "GaleryImage": GaleryImagesList.Add(model as GaleryImage); return;

            case "Image": ImagesList.Add(model as Image); return;

            case "KeyPoint": KeyPointsList.Add(model as KeyPoint); return;

            case "KeyPointsContainer": KeyPointsContainersList.Add(model as KeyPointsContainer); return;

            case "Quiz": QuizesList.Add(model as Quiz); return;

            case "Question": QuestionsList.Add(model as Question); return;

            case "Answer": AnswersList.Add(model as Answer); return;

            case "Option": OptionList.Add(model as Option); return;

            case "ItemList": ItemsListList.Add(model as ItemList); return;

            default: throw new Exception("The type " + theType + " is not supported.");
            }
        }