Пример #1
0
        private static List <CategoryDropDownViewModel> categoryDropDownViewModels(ICollection <Category> categories)
        {
            List <CategoryDropDownViewModel> categoryDropDownViewModelsList = new List <CategoryDropDownViewModel>();

            foreach (var item in categories)
            {
                var ite = item.SubCat;
                if (ite == null)
                {
                    CategoryDropDownViewModel categoryDropDownViews = new CategoryDropDownViewModel()
                    {
                        Id      = item.Id,
                        Details = item.Name
                    };
                    categoryDropDownViewModelsList.Add(categoryDropDownViews);
                }

                if (ite != null)
                {
                    var iteName = ite.Name;
                    CategoryDropDownViewModel categoryDropDownView = new CategoryDropDownViewModel()
                    {
                        Id      = item.Id,
                        Details = item.Name + "->" + iteName
                    };
                    categoryDropDownViewModelsList.Add(categoryDropDownView);
                }
            }
            return(categoryDropDownViewModelsList);
        }
        public PartialViewResult UploadFile()
        {
            List<Category> categories;
            using (var db = new ApplicationDbContext())
            {
                categories = db.Categories.ToList();
            }
            var model = new CategoryDropDownViewModel()
            {
                Categories = categories
            };

            return PartialView("_UploadFile", model);
        }
        public async Task <IViewComponentResult> InvokeAsync(CategoryDropDownViewModel model)
        {
            if (model == null)
            {
                model = new CategoryDropDownViewModel();
            }

            if (model.SelectedCategories == null)
            {
                model.SelectedCategories = new int[0];
            }

            model.Categories = await BuildSelectionsAsync(model);

            return(View(model));
        }
        private async Task <IList <Selection <CategoryBase> > > BuildSelectionsAsync(CategoryDropDownViewModel model)
        {
            // Get categories
            var categories = await _categoryService.GetResultsAsync(
                model.Options, new PagerOptions()
            {
                Page = 1,
                Size = int.MaxValue
            });

            // Indicate selections
            return(categories?.Data?.Select(c => new Selection <CategoryBase>
            {
                IsSelected = model.SelectedCategories.Any(v => v == c.Id),
                Value = c
            })
                   .ToList());
        }
Пример #5
0
        public override async Task <IViewProviderResult> BuildEditAsync(Topic entity, IViewProviderContext updater)
        {
            // Get feature
            var feature = await _featureFacade.GetFeatureByIdAsync("Plato.Discuss.Categories");

            // Ensure we found the feature
            if (feature == null)
            {
                return(default(IViewProviderResult));
            }

            // Override breadcrumb configuration within base discuss controller
            IEnumerable <CategoryAdmin> parents = null;

            if (entity.CategoryId > 0)
            {
                parents = await _categoryStore.GetParentsByIdAsync(entity.CategoryId);
            }
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Discuss"], home => home
                                  .Action("Index", "Home", "Plato.Discuss")
                                  .LocalNav()
                                  );

                if (parents != null)
                {
                    builder.Add(S["Categories"], channels => channels
                                .Action("Index", "Home", "Plato.Discuss.Categories", new RouteValueDictionary()
                    {
                        ["opts.categoryId"] = null,
                        ["opts.alias"]      = null
                    })
                                .LocalNav()
                                );
                    foreach (var parent in parents)
                    {
                        builder.Add(S[parent.Name], c => c
                                    .Action("Index", "Home", "Plato.Discuss.Categories", new RouteValueDictionary
                        {
                            ["opts.categoryId"] = parent.Id,
                            ["opts.alias"]      = parent.Alias,
                        })
                                    .LocalNav()
                                    );
                    }
                }

                // Ensure we have a topic title
                if (!String.IsNullOrEmpty(entity.Title))
                {
                    builder.Add(S[entity.Title], t => t
                                .Action("Display", "Home", "Plato.Discuss", new RouteValueDictionary
                    {
                        ["opts.id"]    = entity.Id,
                        ["opts.alias"] = entity.Alias,
                    })
                                .LocalNav()
                                );
                }

                builder.Add(S[entity.Id > 0 ? "Edit Topic" : "New Topic"]);
            });

            var viewModel = new CategoryDropDownViewModel()
            {
                Options = new CategoryIndexOptions()
                {
                    FeatureId = feature.Id
                },
                HtmlName           = CategoryHtmlName,
                SelectedCategories = await GetCategoryIdsByEntityIdAsync(entity)
            };

            return(Views(
                       View <CategoryDropDownViewModel>("Discuss.Categories.Edit.Sidebar", model => viewModel)
                       .Zone("content-right").Order(5)
                       ));
        }