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


C# UserRepository.FindByID方法代码示例

本文整理汇总了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);
 }
开发者ID:hiyouth,项目名称:R2.RRDL,代码行数:48,代码来源:CommentController.cs

示例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;
        }
开发者ID:hiyouth,项目名称:R2.RRDL,代码行数:41,代码来源:AriticleApproveService.cs

示例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);
     }
 }
开发者ID:hiyouth,项目名称:R2.RRDL,代码行数:17,代码来源:Register.cs

示例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("当前用户还未通过审核,无法为其分配分组");
         }
     }
 }
开发者ID:hiyouth,项目名称:R2.RRDL,代码行数:30,代码来源:Register.cs


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