本文整理汇总了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);
}
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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");
}
示例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);
}
}
}
}
示例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);
}
}
示例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();
}
示例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);
}
}