当前位置: 首页>>代码示例>>C#>>正文


C# DomainModel.Category类代码示例

本文整理汇总了C#中MVCForum.Domain.DomainModel.Category的典型用法代码示例。如果您正苦于以下问题:C# Category类的具体用法?C# Category怎么用?C# Category使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Category类属于MVCForum.Domain.DomainModel命名空间,在下文中一共展示了Category类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Delete

        /// <summary>
        /// Delete a category
        /// </summary>
        /// <param name="category"></param>
        public void Delete(Category category)
        {
            // Check if anyone else if using this role
            var okToDelete = !category.Topics.Any();

            if (okToDelete)
            {
                // Get any categorypermissionforoles and delete these first
                var rolesToDelete = _categoryPermissionForRoleRepository.GetByCategory(category.Id);

                foreach (var categoryPermissionForRole in rolesToDelete)
                {
                    _categoryPermissionForRoleRepository.Delete(categoryPermissionForRole);
                }

                var categoryNotificationsToDelete = new List<CategoryNotification>();
                categoryNotificationsToDelete.AddRange(category.CategoryNotifications);
                foreach (var categoryNotification in categoryNotificationsToDelete)
                {
                    _categoryNotificationService.Delete(categoryNotification);
                }

                _categoryRepository.Delete(category);
            }
            else
            {
                var inUseBy = new List<Entity>();
                inUseBy.AddRange(category.Topics);
                throw new InUseUnableToDeleteException(inUseBy);
            }
        }
开发者ID:R3MUSDevPack,项目名称:Forums,代码行数:35,代码来源:CategoryService.cs

示例2: AddPost

        public void AddPost()
        {
            var postRepository = Substitute.For<IPostRepository>();
            var topicRepository = Substitute.For<ITopicRepository>();
            var roleService = Substitute.For<IRoleService>();
            var membershipUserPointsService = Substitute.For<IMembershipUserPointsService>();
            var settingsService = Substitute.For<ISettingsService>();
            settingsService.GetSettings().Returns(new Settings { PointsAddedPerPost = 20 });
            var localisationService = Substitute.For<ILocalizationService>();
            var postService = new PostService(membershipUserPointsService, settingsService, roleService, postRepository, topicRepository, localisationService, _api);

            var category = new Category();
            var role = new MembershipRole{RoleName = "TestRole"};

            var categoryPermissionForRoleSet = new List<CategoryPermissionForRole>
                                                   {
                                                       new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionEditPosts }, IsTicked = true},
                                                       new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionDenyAccess }, IsTicked = false},
                                                       new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionReadOnly  }, IsTicked = false}
                                                   };

            var permissionSet = new PermissionSet(categoryPermissionForRoleSet);
            roleService.GetPermissions(category, role).Returns(permissionSet);

            var topic = new Topic { Name = "Captain America", Category = category};
            var user = new MembershipUser {
                UserName = "SpongeBob",
                Roles = new List<MembershipRole>{role}
            };

            var newPost = postService.AddNewPost("A test post", topic, user, out permissionSet);

            Assert.AreEqual(newPost.User, user);
            Assert.AreEqual(newPost.Topic, topic);
        }
开发者ID:kangjh0815,项目名称:test,代码行数:35,代码来源:PostServiceTests.cs

示例3: GetByCategory

 /// <summary>
 /// Return all notifications by a specified category
 /// </summary>
 /// <param name="category"></param>
 /// <returns></returns>
 public IList<CategoryNotification> GetByCategory(Category category)
 {
     return _context.CategoryNotification
         .AsNoTracking()
         .Where(x => x.Category.Id == category.Id)
         .ToList();
 }
开发者ID:ivanchen52,项目名称:mvcforum,代码行数:12,代码来源:CategoryNotificationService.cs

示例4: GetCategoryRow

 public IList<CategoryPermissionForRole> GetCategoryRow(MembershipRole role, Category cat)
 {
     return _context.CategoryPermissionForRole
         .Where(x => x.Category.Id == cat.Id &&
                     x.MembershipRole.Id == role.Id)
                     .ToList();
 }
开发者ID:kangjh0815,项目名称:test,代码行数:7,代码来源:CategoryPermissionForRoleRepository.cs

示例5: GetAllDeepSubCategories

 /// <summary>
 /// Gets all categories right the way down
 /// </summary>
 /// <param name="category"></param>
 /// <returns></returns>
 public IList<Category> GetAllDeepSubCategories(Category category)
 {
     var catGuid = category.Id.ToString().ToLower();
     return _context.Category
             .Where(x => x.Path != null && x.Path.ToLower().Contains(catGuid))
             .OrderBy(x => x.SortOrder)
             .ToList();
 }
开发者ID:huchao007,项目名称:mvcforum,代码行数:13,代码来源:CategoryRepository.cs

示例6: Update

 public void Update(Category item)
 {
     // Check there's not an object with same identifier already in context
     if (_context.Category.Local.Select(x => x.Id == item.Id).Any())
     {
         throw new ApplicationException("Object already exists in context - you do not need to call Update. Save occurs on Commit");
     }
     _context.Entry(item).State = EntityState.Modified; 
 }
开发者ID:Xamarui,项目名称:mvcforum,代码行数:9,代码来源:CategoryRepository.cs

示例7: GetByUserAndCategory

 /// <summary>
 /// Return notifications for a specified user and category
 /// </summary>
 /// <param name="user"></param>
 /// <param name="category"></param>
 /// <param name="addTracking"></param>
 /// <returns></returns>
 public IList<CategoryNotification> GetByUserAndCategory(MembershipUser user, Category category, bool addTracking = false)
 {
     var notifications = _context.CategoryNotification
         .Where(x => x.Category.Id == category.Id && x.User.Id == user.Id);
     if (addTracking)
     {
         return notifications.ToList();
     }
     return notifications.AsNoTracking().ToList();
 }
开发者ID:ivanchen52,项目名称:mvcforum,代码行数:17,代码来源:CategoryNotificationService.cs

示例8: GetCategoryRow

 /// <summary>
 /// Returns a row with the permission and CPFR
 /// </summary>
 /// <param name="role"></param>
 /// <param name="cat"></param>
 /// <returns></returns>
 public Dictionary<Permission, CategoryPermissionForRole> GetCategoryRow(MembershipRole role, Category cat)
 {
     var catRowList = _context.CategoryPermissionForRole
                     .Include(x => x.MembershipRole)
                     .Include(x => x.Category)
                     .AsNoTracking()
                     .Where(x => x.Category.Id == cat.Id &&
                                 x.MembershipRole.Id == role.Id)
                                 .ToList();
     return catRowList.ToDictionary(catRow => catRow.Permission);
 }
开发者ID:ivanchen52,项目名称:mvcforum,代码行数:17,代码来源:CategoryPermissionForRoleService.cs

示例9: GetSubCategories

        public List<Category> GetSubCategories(Category category, List<Category> allCategories, int level = 2)
        {
            var catsToReturn = new List<Category>();
            var cats = allCategories.Where(x => x.ParentCategory != null && x.ParentCategory.Id == category.Id).OrderBy(x =>x.SortOrder);
            foreach (var cat in cats)
            {
                cat.Level = level;
                catsToReturn.Add(cat);
                catsToReturn.AddRange(GetSubCategories(cat, allCategories, level + 1));
            }

            return catsToReturn;
        }
开发者ID:huchao007,项目名称:mvcforum,代码行数:13,代码来源:CategoryService.cs

示例10: Add

        /// <summary>
        /// Add a new category
        /// </summary>
        /// <param name="category"></param>
        public void Add(Category category)
        {
            // Sanitize
            category = SanitizeCategory(category);

            // Set the create date
            category.DateCreated = DateTime.UtcNow;

            // url slug generator
            category.Slug = ServiceHelpers.GenerateSlug(category.Name, _categoryRepository.GetBySlugLike(ServiceHelpers.CreateUrl(category.Name)), null);

            // Add the category
            _categoryRepository.Add(category);
        }
开发者ID:R3MUSDevPack,项目名称:Forums,代码行数:18,代码来源:CategoryService.cs

示例11: CreateCategory

        public ActionResult CreateCategory(CreateCategoryViewModel categoryViewModel)
        {
            if (ModelState.IsValid)
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        var category = new Category
                                           {
                                               Name = categoryViewModel.Name,
                                               Description = categoryViewModel.Description,
                                               IsLocked = categoryViewModel.IsLocked,
                                               SortOrder = categoryViewModel.SortOrder,
                                           };

                        if (categoryViewModel.ParentCategory != null)
                        {
                            category.ParentCategory =
                                _categoryService.Get(categoryViewModel.ParentCategory.Value);
                        }

                        _categoryService.Add(category);

                        // We use temp data because we are doing a redirect
                        TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                                                                        {
                                                                            Message = "Category Created",
                                                                            MessageType =
                                                                                GenericMessages.success
                                                                        };
                        unitOfWork.Commit();
                    }
                    catch (Exception)
                    {
                        unitOfWork.Rollback();
                    }
                }
            }

            return RedirectToAction("Index");
        }
开发者ID:kangjh0815,项目名称:test,代码行数:42,代码来源:AdminCategoryController.cs

示例12: NotifyNewTopics

        private void NotifyNewTopics(Category cat, IUnitOfWork unitOfWork)
        {
            // Get all notifications for this category
            var notifications = _categoryNotificationService.GetByCategory(cat).Select(x => x.User.Id).ToList();

            if (notifications.Any())
            {
                // remove the current user from the notification, don't want to notify yourself that you
                // have just made a topic!
                notifications.Remove(LoggedOnUser.Id);

                if (notifications.Count > 0)
                {
                    // Now get all the users that need notifying
                    var usersToNotify = MembershipService.GetUsersById(notifications);

                    // Create the email
                    var sb = new StringBuilder();
                    sb.AppendFormat("<p>{0}</p>", string.Format(LocalizationService.GetResourceString("Topic.Notification.NewTopics"), cat.Name));
                    sb.AppendFormat("<p>{0}</p>", string.Concat(SettingsService.GetSettings().ForumUrl, cat.NiceUrl));

                    // create the emails and only send them to people who have not had notifications disabled
                    var emails = usersToNotify.Where(x => x.DisableEmailNotifications != true).Select(user => new Email
                    {
                        Body = _emailService.EmailTemplate(user.UserName, sb.ToString()),
                        EmailTo = user.Email,
                        NameTo = user.UserName,
                        Subject = string.Concat(LocalizationService.GetResourceString("Topic.Notification.Subject"), SettingsService.GetSettings().ForumName)
                    }).ToList();

                    // and now pass the emails in to be sent
                    _emailService.SendMail(emails);

                    try
                    {
                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LoggingService.Error(ex);
                    }
                }
            }
        }
开发者ID:R3MUSDevPack,项目名称:Forums,代码行数:45,代码来源:TopicController.cs

示例13: GetCategoryBreadcrumb

 public PartialViewResult GetCategoryBreadcrumb(Category category)
 {
     using (UnitOfWorkManager.NewUnitOfWork())
     {
         var viewModel = new BreadcrumbViewModel
         {
             Categories = _categoryService.GetCategoryParents(category).ToList(),
             Category = category
         };
         return PartialView("GetCategoryBreadcrumb", viewModel);
     }
 }
开发者ID:R3MUSDevPack,项目名称:Forums,代码行数:12,代码来源:CategoryController.cs

示例14: GetCategoryParents

 public List<Category> GetCategoryParents(Category category, List<Category> allowedCategories)
 {
     var cats = _categoryRepository.GetCategoryParents(category);
     var allowedCatIds = new List<Guid>();
     if (allowedCategories != null && allowedCategories.Any())
     {
         allowedCatIds.AddRange(allowedCategories.Select(x => x.Id));
     }
     return cats.Where(x => allowedCatIds.Contains(x.Id)).ToList();
 }
开发者ID:huchao007,项目名称:mvcforum,代码行数:10,代码来源:CategoryService.cs

示例15: GetCategoryBreadcrumb

        public PartialViewResult GetCategoryBreadcrumb(Category category)
        {
            var allowedCategories = _categoryService.GetAllowedCategories(UsersRole);

            using (UnitOfWorkManager.NewUnitOfWork())
            {
                var viewModel = new BreadcrumbViewModel
                {
                    Categories = _categoryService.GetCategoryParents(category,allowedCategories),
                    Category = category
                };
                return PartialView("GetCategoryBreadcrumb", viewModel);
            }
        }
开发者ID:huchao007,项目名称:mvcforum,代码行数:14,代码来源:CategoryController.cs


注:本文中的MVCForum.Domain.DomainModel.Category类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。