本文整理汇总了C#中MVCForum.Domain.DomainModel.MembershipUser类的典型用法代码示例。如果您正苦于以下问题:C# MembershipUser类的具体用法?C# MembershipUser怎么用?C# MembershipUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MembershipUser类属于MVCForum.Domain.DomainModel命名空间,在下文中一共展示了MembershipUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: UserToMemberEditViewModel
public static MemberEditViewModel UserToMemberEditViewModel(MembershipUser user)
{
var viewModel = new MemberEditViewModel
{
IsApproved = user.IsApproved,
Id = user.Id,
IsLockedOut = user.IsLockedOut,
IsBanned = user.IsBanned,
Roles = user.Roles.Select(x => x.RoleName).ToArray(),
UserName = user.UserName,
Age = user.Age,
Comment = user.Comment,
Email = user.Email,
Facebook = user.Facebook,
Location = user.Location,
PasswordAnswer = user.PasswordAnswer,
PasswordQuestion = user.PasswordQuestion,
Signature = user.Signature,
Twitter = user.Twitter,
Website = user.Website,
DisableEmailNotifications = (user.DisableEmailNotifications == true),
DisablePosting = (user.DisablePosting == true),
DisablePrivateMessages = (user.DisablePrivateMessages == true),
DisableFileUploads = (user.DisableFileUploads == true),
Avatar = user.Avatar
};
return viewModel;
}
示例3: Rule
public bool Rule(MembershipUser user, IMVCForumAPI api)
{
//Post is marked as the answer to a topic - give the post author a badge
var usersSolutions = api.Post.GetSolutionsWrittenByMember(user.Id);
return (usersSolutions.Count >= 1);
}
示例4: Rule
public bool Rule(MembershipUser user)
{
// Get all down votes
var voteService = DependencyResolver.Current.GetService<IVoteService>();
var downVotes = voteService.GetAllVotesByUser(user.Id).Where(x => x.Amount < 1).ToList();
return downVotes.Count() >= 10;
}
示例5: GetUsersPrivateMessages
public IPagedList<PrivateMessageListItem> GetUsersPrivateMessages(int pageIndex, int pageSize, MembershipUser user)
{
var query = _context.PrivateMessage
.AsNoTracking()
.Include(x => x.UserFrom)
.Include(x => x.UserTo)
.Where(x => (x.UserTo.Id == user.Id && x.IsSentMessage != true) || (x.UserFrom.Id == user.Id && x.IsSentMessage == true))
.Select(x => new PrivateMessageListItem
{
Date = x.DateSent,
User = (x.IsSentMessage == true ? x.UserTo : x.UserFrom),
HasUnreadMessages = (x.IsSentMessage != true && x.UserFrom.Id != user.Id && (x.IsRead == false))
})
.GroupBy(x => x.User.Id)
.Select(x => x.OrderByDescending(d => d.Date).FirstOrDefault())
.OrderByDescending(x => x.Date);
var total = query.Count();
var results = query
.Skip((pageIndex - 1) * pageSize)
.Take(pageSize)
.ToList();
// Return a paged list
return new PagedList<PrivateMessageListItem>(results, pageIndex, pageSize, total);
}
示例6: GetUsersPrivateMessages
//public IPagedList<PrivateMessage> GetPagedSentMessagesByUser(int pageIndex, int pageSize, MembershipUser user)
//{
// var totalCount = _context.PrivateMessage
// .Include(x => x.UserTo)
// .Include(x => x.UserFrom)
// .Count(x => x.UserFrom.Id == user.Id && x.IsSentMessage == true);
// // Get the topics using an efficient
// var results = _context.PrivateMessage
// .Include(x => x.UserTo)
// .Include(x => x.UserFrom)
// .Where(x => x.UserFrom.Id == user.Id)
// .Where(x => x.IsSentMessage == true)
// .OrderByDescending(x => x.DateSent)
// .Skip((pageIndex - 1) * pageSize)
// .Take(pageSize)
// .ToList();
// // Return a paged list
// return new PagedList<PrivateMessage>(results, pageIndex, pageSize, totalCount);
//}
//public IPagedList<PrivateMessage> GetPagedReceivedMessagesByUser(int pageIndex, int pageSize, MembershipUser user)
//{
// var totalCount = _context.PrivateMessage
// .Include(x => x.UserTo)
// .Include(x => x.UserFrom)
// .OrderByDescending(x => x.DateSent)
// .Count(x => (x.UserTo.Id == user.Id || x.UserFrom.Id == user.Id) && x.IsSentMessage != true);
// var results = _context.PrivateMessage
// .Include(x => x.UserTo)
// .Include(x => x.UserFrom)
// .OrderByDescending(x => x.DateSent)
// .Where(x => (x.UserTo.Id == user.Id || x.UserFrom.Id == user.Id) && x.IsSentMessage != true)
// .Skip((pageIndex - 1) * pageSize)
// .Take(pageSize)
// .ToList();
// // Return a paged list
// return new PagedList<PrivateMessage>(results, pageIndex, pageSize, totalCount);
//}
public IPagedList<PrivateMessageListItem> GetUsersPrivateMessages(int pageIndex, int pageSize, MembershipUser user)
{
//TODO - Need to rework this as it's not very efficient
// Get all received pms
var members = user.PrivateMessagesReceived.Where(x => x.IsSentMessage == true).OrderByDescending(x => x.DateSent).DistinctBy(x => x.UserFrom.Id).Select(x => new PrivateMessageListItem
{
Date = x.DateSent,
User = x.UserFrom
}).ToList();
// Get all sent pms + ISSent
var sentToMembers = user.PrivateMessagesSent.Where(x => x.IsSentMessage != true).OrderByDescending(x => x.DateSent).DistinctBy(x => x.UserTo.Id).Select(x => new PrivateMessageListItem
{
Date = x.DateSent,
User = x.UserTo
}).ToList();
// Add lists
members.AddRange(sentToMembers);
// Get the full amount
var uniqueMembers = members.OrderByDescending(x => x.Date).DistinctBy(x => x.User.Id).ToList();
var uniqueMembersCount = uniqueMembers.Count;
// Now distinct the lists again
members = uniqueMembers.Skip((pageIndex - 1) * pageSize)
.Take(pageSize)
.ToList();
// Return a paged list
return new PagedList<PrivateMessageListItem>(members, pageIndex, pageSize, uniqueMembersCount);
}
示例7: Rule
public bool Rule(MembershipUser user)
{
//Post is marked as the answer to a topic - give the post author a badge
var postService = DependencyResolver.Current.GetService<IPostService>();
var usersSolutions = postService.GetSolutionsByMember(user.Id);
return (usersSolutions.Count >= 10);
}
示例8: AddNewPost
/// <summary>
/// Add a new post
/// </summary>
/// <param name="postContent"> </param>
/// <param name="topic"> </param>
/// <param name="user"></param>
/// <param name="permissions"> </param>
/// <returns>True if post added</returns>
public Post AddNewPost(string postContent, Topic topic, MembershipUser user, out PermissionSet permissions)
{
// Get the permissions for the category that this topic is in
permissions = _roleService.GetPermissions(topic.Category, UsersRole(user));
// Check this users role has permission to create a post
if (permissions[AppConstants.PermissionDenyAccess].IsTicked || permissions[AppConstants.PermissionReadOnly].IsTicked)
{
// Throw exception so Ajax caller picks it up
throw new ApplicationException(_localizationService.GetResourceString("Errors.NoPermission"));
}
// Has permission so create the post
var newPost = new Post
{
PostContent = postContent,
User = user,
Topic = topic,
IpAddress = StringUtils.GetUsersIpAddress(),
DateCreated = DateTime.UtcNow,
DateEdited = DateTime.UtcNow
};
// Sort the search field out
var category = topic.Category;
if (category.ModeratePosts == true)
{
newPost.Pending = true;
}
var e = new PostMadeEventArgs { Post = newPost };
EventManager.Instance.FireBeforePostMade(this, e);
if (!e.Cancel)
{
// create the post
Add(newPost);
// Update the users points score and post count for posting
_membershipUserPointsService.Add(new MembershipUserPoints
{
Points = _settingsService.GetSettings().PointsAddedPerPost,
User = user,
PointsFor = PointsFor.Post,
PointsForId = newPost.Id
});
// add the last post to the topic
topic.LastPost = newPost;
EventManager.Instance.FireAfterPostMade(this, new PostMadeEventArgs { Post = newPost });
return newPost;
}
return newPost;
}
示例9: Delete
public void Delete(MembershipUser user, PointsFor type, Guid referenceId)
{
var mp =
_context.MembershipUserPoints.Where(
x => x.User.Id == user.Id && x.PointsFor == type && x.PointsForId == referenceId);
var mpoints = new List<MembershipUserPoints>();
mpoints.AddRange(mp);
Delete(mpoints);
}
示例10: Rule
public bool Rule(MembershipUser user)
{
var lastPost = user.Posts.OrderByDescending(x => x.DateCreated).FirstOrDefault();
if (lastPost != null && lastPost.PostContent.ToLower().Contains("umbraco"))
{
return true;
}
return false;
}
示例11: GetByUserAndTag
public IList<TagNotification> GetByUserAndTag(MembershipUser user, TopicTag tag, bool addTracking = false)
{
var notifications = _context.TagNotification
.Where(x => x.User.Id == user.Id && x.Tag.Id == tag.Id);
if (addTracking)
{
return notifications.ToList();
}
return notifications.AsNoTracking().ToList();
}
示例12: Create
public MembershipUser Create(string name)
{
var newUser = new MembershipUser
{
UserName = name
};
// Id is created by API
return _api.Member.Create(newUser);
}
示例13: 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();
}
示例14: GetByUser
public IEnumerable<MembershipUserPoints> GetByUser(MembershipUser user, bool removeTracking = true)
{
var users = _context.MembershipUserPoints
.Where(x => x.User.Id == user.Id);
if (removeTracking)
{
return users.AsNoTracking();
}
return users;
}
示例15: MemberJoinedActivityAdd
public void MemberJoinedActivityAdd()
{
const string guidStr = "515b7240-3be1-43d4-8846-c0b589cd1cd2";
var activityRepository = Substitute.For<IActivityRepository>();
IActivityService activityService = new ActivityService(activityRepository, _badgeRepository, _membershipRepository, _loggingService);
var user = new MembershipUser { Id = new Guid(guidStr), UserName = "SpongeBob" };
activityService.MemberJoined(user);
activityRepository.Received().Add((Arg.Is<Activity>(x => x.Data == MemberJoinedActivity.KeyUserId + "=" + guidStr)));
}