本文整理汇总了C#中UserRepository.FindByID方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.FindByID方法的具体用法?C# UserRepository.FindByID怎么用?C# UserRepository.FindByID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.FindByID方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddComment
public ActionResult AddComment(string content, string userId, string ariticleId, string comment_temp)
{
CommentRepository cr = new CommentRepository();
UserRepository ur = new UserRepository();
string result = "";
if (comment_temp != "null")
{
string[] array = comment_temp.Split('#');
int id = Int32.Parse(array[0]);
string firstUserId = array[1];
Comment c = cr.FindByID(id);
User u = ur.FindByID(userId);
User firstUser = ur.FindByID(firstUserId);
c.Isleaf = 1;
cr.Update(c);
Comment comment = new Comment();
comment.UserId = userId;
comment.AriticleId = ariticleId;
comment.Content = content;
comment.NickName = u.NickName;
comment.FirstNickName = firstUser.NickName;
comment.Pid = id;
comment.Isleaf = 0;
comment.CommentTime = DateTime.Now;
cr.Add(comment);
result = "";
result = JsonConvert.SerializeObject(comment);
}
else {
User u = ur.FindByID(userId);
Comment comment = new Comment();
comment.UserId = userId;
comment.Content = content;
comment.CommentTime = DateTime.Now;
comment.AriticleId = ariticleId;
comment.Pid = 0;
comment.Isleaf = 0;
comment.Level = 1;
comment.NickName = u.NickName;
comment.FirstNickName = null;
cr.Add(comment);
result = "";
result = JsonConvert.SerializeObject(comment);
;
}
return Content(result);
}
示例2: ValidateApproveAuthority
/// <summary>
/// 验证用户是否有审核权限
/// </summary>
/// <param name="ariticleId"></param>
/// <param name="userId"></param>
public bool ValidateApproveAuthority(string ariticleId, string userId)
{
bool canApprove=false;
User user;
using (UserRepository userRepository = new UserRepository())
{
user = userRepository.FindByID(userId);
if (user == null)
throw new Exception("审核失败,找不到userId对应的用户对象");
if(user.AuthorityCategory==EnumUserCategory.Membership||
user.AuthorityCategory==EnumUserCategory.Visitor)
throw new Exception("审核失败,用户不具有审核权限");
}
Ariticle ariticle;
using (AriticleRepository ariticleRepository = new AriticleRepository())
{
ariticle = ariticleRepository.FindById(ariticleId);
ariticleRepository.Db.Entry(ariticle).Reference(a => a.User).Load();
if (ariticle == null)
throw new Exception("审核失败,无法找到对应的文章");
}
if (user.AuthorityCategory == EnumUserCategory.Superman
&& ariticle != null)
{
//超级管理员具有审核所有文章的权限
canApprove = true;
}
if (user.AuthorityCategory == EnumUserCategory.Administrator &&
ariticle != null && ariticle.User.ContentGroupId == user.ContentGroupId)
{
//普通管理员具有审核其所在分组文章的权限
canApprove = true;
}
return canApprove;
}
示例3: ApproveUser
/// <summary>
/// 审核通过一个用户
/// </summary>
/// <param name="userId"></param>
/// <param name="replyContent"></param>
public void ApproveUser(string userId,string replyContent)
{
using (UserRepository userRepository = new UserRepository())
{
User user=userRepository.FindByID(userId);
if (user == null)
throw new Exception("用户不存在");
user.ApproveStatus = EnumUserApproveStatus.Approved;
user.ReplyContent = replyContent;
userRepository.Update(user);
}
}
示例4: SetUserGroup
/// <summary>
/// 为一个用户分配分组
/// </summary>
/// <param name="userId"></param>
/// <param name="groupId"></param>
public void SetUserGroup(string userId, int groupId)
{
using (UserGroupRepository groupRepository = new UserGroupRepository())
{
UserGroup group = groupRepository.ExecuteConditions(g => g.Id == groupId).
FirstOrDefault();
if (group == null)
throw new Exception("指定分组不存在");
}
using (UserRepository userRepository = new UserRepository())
{
User user = userRepository.FindByID(userId);
if (user == null)
throw new Exception("用户不存在");
if (user.ApproveStatus == EnumUserApproveStatus.Approved)
{
user.ContentGroupId = groupId;
userRepository.Update(user);
}
else
{
throw new Exception("当前用户还未通过审核,无法为其分配分组");
}
}
}