コード例 #1
0
 public IActionResult AddInProduct(ViewCategoryViewModel viewModel, int CategoryId)
 {
     viewModel.Association.CategoryId = CategoryId;
     dbContext.Add(viewModel.Association);
     dbContext.SaveChanges();
     return(RedirectToAction("Category", new{ CategoryId = CategoryId }));
 }
コード例 #2
0
ファイル: CategoryController.cs プロジェクト: yaobos/mvcforum
        public ActionResult Show(string slug, int?p)
        {
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                // Get the category
                var category = _categoryService.GetBySlugWithSubCategories(slug);

                // Allowed Categories for this user
                var allowedCategories = _categoryService.GetAllowedCategories(UsersRole);

                // Set the page index
                var pageIndex = p ?? 1;

                // check the user has permission to this category
                var permissions = RoleService.GetPermissions(category.Category, UsersRole);

                if (!permissions[AppConstants.PermissionDenyAccess].IsTicked)
                {
                    var topics = _topicService.GetPagedTopicsByCategory(pageIndex,
                                                                        SettingsService.GetSettings().TopicsPerPage,
                                                                        int.MaxValue, category.Category.Id);

                    var topicViewModels = ViewModelMapping.CreateTopicViewModels(topics.ToList(), RoleService, UsersRole, LoggedOnReadOnlyUser, allowedCategories, SettingsService.GetSettings());

                    // Create the main view model for the category
                    var viewModel = new ViewCategoryViewModel
                    {
                        Permissions  = permissions,
                        Topics       = topicViewModels,
                        Category     = category.Category,
                        PageIndex    = pageIndex,
                        TotalCount   = topics.TotalCount,
                        TotalPages   = topics.TotalPages,
                        User         = LoggedOnReadOnlyUser,
                        IsSubscribed = UserIsAuthenticated && (_categoryNotificationService.GetByUserAndCategory(LoggedOnReadOnlyUser, category.Category).Any())
                    };

                    // If there are subcategories then add then with their permissions
                    if (category.SubCategories.Any())
                    {
                        var subCatViewModel = new CategoryListViewModel
                        {
                            AllPermissionSets = new Dictionary <Category, PermissionSet>()
                        };
                        foreach (var subCategory in category.SubCategories)
                        {
                            var permissionSet = RoleService.GetPermissions(subCategory, UsersRole);
                            subCatViewModel.AllPermissionSets.Add(subCategory, permissionSet);
                        }
                        viewModel.SubCategories = subCatViewModel;
                    }

                    return(View(viewModel));
                }

                return(ErrorToHomePage(LocalizationService.GetResourceString("Errors.NoPermission")));
            }
        }
コード例 #3
0
        public override ActionResult Index(RenderModel model)
        {
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                // Get the category
                var category = CategoryMapper.MapCategory(model.Content, true);

                // Set the page index
                var pageIndex = AppHelpers.ReturnCurrentPagingNo();

                // check the user has permission to this category
                var permissions = ServiceFactory.PermissionService.GetPermissions(category, _usersRoles);

                if (!permissions[AppConstants.PermissionDenyAccess].IsTicked)
                {
                    var topics = ServiceFactory.TopicService.GetPagedTopicsByCategory(pageIndex,
                                                                                      Settings.TopicsPerPage,
                                                                                      int.MaxValue, category.Id);

                    var isSubscribed = UserIsAuthenticated && (ServiceFactory.CategoryNotificationService.GetByUserAndCategory(CurrentMember, category).Any());

                    // Create the main view model for the category
                    var viewModel = new ViewCategoryViewModel(model.Content)
                    {
                        Permissions  = permissions,
                        Topics       = topics,
                        Category     = category,
                        PageIndex    = pageIndex,
                        TotalCount   = topics.TotalCount,
                        User         = CurrentMember,
                        IsSubscribed = isSubscribed
                    };

                    // If there are subcategories then add then with their permissions
                    if (category.SubCategories.Any())
                    {
                        var subCatViewModel = new CategoryListViewModel
                        {
                            AllPermissionSets = new Dictionary <Category, PermissionSet>()
                        };
                        foreach (var subCategory in category.SubCategories)
                        {
                            var permissionSet = ServiceFactory.PermissionService.GetPermissions(subCategory, _usersRoles);

                            subCategory.LatestTopic = ServiceFactory.TopicService.GetPagedTopicsByCategory(1, Settings.TopicsPerPage, int.MaxValue, subCategory.Id).FirstOrDefault();
                            subCategory.TopicCount  = ServiceFactory.TopicService.GetTopicCountByCategory(subCategory.Id);
                            subCatViewModel.AllPermissionSets.Add(subCategory, permissionSet);
                        }
                        viewModel.SubCategories = subCatViewModel;
                    }

                    return(View(PathHelper.GetThemeViewPath("Category"), viewModel));
                }

                return(ErrorToHomePage("No Permission"));
            }
        }
コード例 #4
0
        public IActionResult ViewCategory(int id)
        {
            CheeseCategory category = context.Categories.Single(c => c.ID == id);
            List <Cheese>  cheeses  = context.Cheeses.Where(c => c.CategoryID == id).ToList();


            ViewCategoryViewModel viewCategoryViewModel = new ViewCategoryViewModel
            {
                Category = category,
                Cheeses  = cheeses
            };

            return(View(viewCategoryViewModel));
        }
コード例 #5
0
        public IActionResult Category(int CategoryId)
        {
            ViewCategoryViewModel viewModel = new ViewCategoryViewModel();

            viewModel.currentCategory = dbContext.Categories
                                        .Include(p => p.Associations)
                                        .ThenInclude(pc => pc.Product)
                                        .FirstOrDefault(p => p.CategoryId == CategoryId);
            viewModel.ProductList = dbContext.Products
                                    .Include(c => c.Associations)
                                    .ThenInclude(pc => pc.Category)
                                    .Where(c => !viewModel.currentCategory.Associations.Select(pc => pc.Product).Contains(c))
                                    .ToList();
            return(View("Category", viewModel));
        }
コード例 #6
0
        public IActionResult ViewCategory(int id)
        {
            try
            {
                CheeseCategory newCat =
                    context.Categories.Single(c => c.ID == id);
                List <Cheese> items = context
                                      .Cheeses
                                      .Include(item => item.Category)
                                      .Where(cc => cc.CategoryID == id)
                                      .ToList();

                ViewCategoryViewModel viewCategoryViewModel = new ViewCategoryViewModel
                {
                    Category = newCat,
                    Items    = items
                };
                return(View(viewCategoryViewModel));
            }
            catch (InvalidOperationException)
            {
                return(Redirect("/Category"));
            }
        }