コード例 #1
0
        public async Task AddUserToGroupAsync(string userName, int groupId)
        {
            var user = await _repository.ApplicationUsers.SingleAsync(ApplicationUser.UserNameEquals(userName));

            var group = await _repository.Groups.SingleAsync(g => g.Id == groupId);

            var isUserAlreadyInThisGroup = await _repository.GroupUsers
                                           .Where(gu => gu.UserId == user.Id && gu.GroupId == group.Id)
                                           .AnyAsync();

            if (group.OwnerId == user.Id)
            {
                throw new GroupsException("You cannot add yourself to your group.");
            }

            if (isUserAlreadyInThisGroup)
            {
                throw new GroupsException("User is already in this group.");
            }

            var groupUser = new GroupUser
            {
                UserId  = user.Id,
                User    = user,
                GroupId = groupId,
                Group   = group
            };

            _repository.GroupUsers.Add(groupUser);
            await _repository.SaveChangesAsync();
        }
コード例 #2
0
        public int Add(GroupUserModel model)
        {
            try
            {
                var groupUser = new GroupUser()
                {
                    GroupId    = model.GroupId,
                    UserId     = model.UserId,
                    RoleId     = model.RoleId,
                    LastSeenOn = UnixTimeBaseClass.UnixTimeNow,
                    CreatedBy  = model.CreatedBy,
                    CreatedOn  = UnixTimeBaseClass.UnixTimeNow
                };

                _db.GroupUsers.Add(groupUser);
                _db.SaveChanges();

                return(groupUser.GroupUserId);
            }
            catch (Exception ex)
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                string json             = js.Serialize(model);
                Log.Error("Group User - Add- " + json, ex);
                throw;
            }
        }
コード例 #3
0
        public static bool AddUser(ref GroupUser model, out string strErrorMsg)
        {
            strErrorMsg = "";
            if (IsNameExist(model.Name))
            {
                strErrorMsg = ConstDefineBll.NameExist;
                return(false);
            }

            using (GLedDbEntities ent = new GLedDbEntities())
            {
                GroupUser newinfo = new GroupUser()
                {
                    Id         = model.Id,
                    MgrGroupId = model.MgrGroupId,
                    Name       = model.Name,
                    Password   = model.Password,
                    RefOrgId   = model.RefOrgId,
                    CreateDt   = DateTime.Now,
                    UpdateDt   = DateTime.Now
                };
                ent.GroupUser.Add(newinfo);
                ent.SaveChanges();
                model.Id = newinfo.Id;
            }
            return(true);
        }
コード例 #4
0
        // 直接加为群组成功,不用审核
        public virtual Result JoinGroupDone(User user, Group group, String joinReason)
        {
            GroupUser gu = db.find <GroupUser>("Member.Id=" + user.Id + " and Group.Id=" + group.Id).first();

            Result result;

            if (gu == null)
            {
                gu        = new GroupUser();
                gu.Member = user;
                gu.Group  = group;
                gu.Msg    = joinReason;
                result    = db.insert(gu);
            }
            else
            {
                gu.Status = GroupRole.Member.Id;
                gu.Msg    = joinReason;

                result = gu.update();
            }

            afterJoinDone(user, group, joinReason, gu);

            return(result);
        }
コード例 #5
0
        public virtual void RemoveOfficer(Group group, String userIds)
        {
            int[] ids = cvt.ToIntArray(userIds);
            foreach (int userId in ids)
            {
                GroupUser gu = db.find <GroupUser>(getCondition(group.Id, userId)).first();
                if (gu == null)
                {
                    continue;
                }

                if (gu.Status != GroupRole.Administrator.Id)
                {
                    continue;
                }

                gu.Status = GroupRole.Member.Id;
                db.update(gu, "Status");

                String msg  = string.Format(lang.get("groupAdminCanceledMsg") + ":“{0}”", group.Name);
                String body = string.Format(lang.get("groupAdminCanceledMsg") + ":“<a href='{1}'>{0}</a>”",
                                            group.Name, Link.ToMember(group));

                User receiver = userService.GetById(userId);
                msgService.SiteSend(msg, body, receiver);
            }
        }
コード例 #6
0
        public virtual void ApproveUser(Group group, String userIds)
        {
            int[] ids = cvt.ToIntArray(userIds);
            foreach (int userId in ids)
            {
                GroupUser gu = db.find <GroupUser>(getCondition(group.Id, userId)).first();
                if (gu == null)
                {
                    continue;
                }

                // 过滤掉已有成员
                if (gu.Status == GroupRole.Administrator.Id || gu.Status == GroupRole.Member.Id)
                {
                    continue;
                }

                gu.Status = GroupRole.Member.Id;
                db.update(gu, "Status");

                // 给申请者发送消息
                String msg  = string.Format(lang.get("groupMemberJoinedMsg") + "“{0}”", group.Name);
                String body = string.Format(lang.get("groupMemberJoinedMsg") + "“<a href=\"{1}\" target=\"_blank\">{0}</a>”",
                                            group.Name, Link.ToMember(group));

                User receiver = userService.GetById(userId);
                msgService.SiteSend(msg, body, receiver);

                addFeedInfo(gu);
            }

            recountMembers(group);
        }
コード例 #7
0
ファイル: GroupController.cs プロジェクト: nbl852003/iudico
        public ActionResult AddUsers(int id, Guid?userRef)
        {
            var group = _Storage.GetGroup(id);

            if (userRef == null)
            {
                var userList =
                    _Storage.GetUsersNotInGroup(group).Select(
                        u => new SelectListItem {
                    Text = u.Username, Value = u.Id.ToString(), Selected = false
                });

                var groupUser = new GroupUser
                {
                    Group    = group,
                    UserList = userList
                };

                ModelState.AddModelError("UserRef", Localization.getMessage("PleaseSelectUserFromList"));

                return(View(groupUser));
            }

            var user = _Storage.GetUser(u => u.Id == userRef.Value);

            _Storage.AddUserToGroup(group, user);

            return(RedirectToAction("Details", new { Id = id }));
        }
コード例 #8
0
        public async Task <bool> AddUserToGroup(int groupId, int userId)
        {
            Group foundGroup = await DbContext.Groups
                               .Include(x => x.GroupUsers)
                               .FirstOrDefaultAsync(x => x.Id == groupId);

            if (foundGroup == null)
            {
                return(false);
            }

            User foundUser = await DbContext.Users.FindAsync(userId);

            if (foundUser == null)
            {
                return(false);
            }

            var groupUser = new GroupUser {
                GroupId = foundGroup.Id, UserId = foundUser.Id
            };

            if (foundGroup.GroupUsers == null)
            {
                foundGroup.GroupUsers = new List <GroupUser>();
            }
            foundGroup.GroupUsers.Add(groupUser);
            await DbContext.SaveChangesAsync();

            return(true);
        }
コード例 #9
0
        public async Task <GroupUser> AcceptRequestJoin(GroupUser entity)
        {
            Context.Update(entity);
            await SaveAllAsync();

            return(entity);
        }
コード例 #10
0
        public async Task <ActionResult> AddUser(long groupId, string userName)
        {
            GroupUser currentUser = await guRepo.GetGroupUser(groupId, UserId);

            GroupDto currentGroup = await GetGroup(groupId);

            if (currentUser.Role == Role.owner || currentUser.Role == Role.admin)
            {
                Console.WriteLine($"{currentGroup.GroupUsers.Count}, {currentGroup.MaxUsers}");
                if (currentGroup.GroupUsers.Count < currentGroup.MaxUsers || currentGroup.MaxUsers == -1)
                {
                    await repository.AddUserAsync(groupId, userName);

                    long userId = await repository.FindUserIdByUserName(userName);

                    return(CreatedAtAction(nameof(AddUser), new { groupId, userName }, null));
                }
                else
                {
                    return(BadRequest("Cannot add users to this group. This group is currently full. Please upgrade to add more users."));
                }
            }
            else
            {
                return(Unauthorized("Only admins and owners can add users to this group. If you find this to be a mistake, please talk with your group admins."));
            }
        }
コード例 #11
0
        public async Task<IActionResult> EditUsersInGroup([FromBody] Users data)
        {
            var mgroup = await _context.Groups
                .Include(m => m.GroupUsers)
                .FirstOrDefaultAsync(m => m.GroupId == data.guid);
            if (mgroup == null)
            {
                return NotFound();
            }

            foreach (GroupUser guOld in mgroup.GroupUsers)
            {
                _context.GroupsUsers.Remove(guOld);
            }


            foreach (UserIds userid in data.items)
            {
                DB.Models.Domain.User u = await _context.Users.FindAsync(userid.value);
                if (u!=null)
                {
                    GroupUser gu = new GroupUser() { Group = mgroup, User = u };
                    _context.GroupsUsers.Add(gu);
                }

            }


                await _context.SaveChangesAsync();


            return Content("OK", "application/json");
        }
コード例 #12
0
 public static UserOutDto AsOutModel(this GroupUser user)
 => new UserOutDto
 {
     Id       = user.Id,
     Email    = user.Email,
     Username = user.Username
 };
コード例 #13
0
        public async Task <object> CreateGroup([FromBody] CreateGroupIn data)
        {
            // group name should be unique and is not allowed to be empty
            if (data.Name == null || context.Group.FirstOrDefault(g => data.Name.Equals(g.Name)) != null)
            {
                return(BadRequest("Group name not valid."));
            }


            var group = new Group
            {
                Name = data.Name.Trim()
            };
            var groupUserRelation = new GroupUser
            {
                User  = user,
                Group = group,
                //the user become group manager by default
                Role = 1
            };

            context.Group.Add(group);
            context.GroupUsers.Add(groupUserRelation);
            await context.SaveChangesAsync();

            return(new GroupPreview(group));
        }
コード例 #14
0
        public async Task <GroupUser> InsertGroupUser(GroupUser groupUser)
        {
            groupUser.Id = (int)await _connection.InsertAsync(groupUser)
                           .ConfigureAwait(false);

            return(groupUser);
        }
コード例 #15
0
        public async Task <Group> AddUsersToGroup(Group group, IEnumerable <User> usersToAdd)
        {
            var groupEntity = await AuthorizationDbContext.Groups.SingleOrDefaultAsync(g =>
                                                                                       g.Name == group.Name &&
                                                                                       g.TenantId == group.TenantId &&
                                                                                       g.IdentityProvider == group.IdentityProvider &&
                                                                                       !g.IsDeleted);

            if (groupEntity == null)
            {
                throw new NotFoundException <Group>($"Could not find {typeof(Group).Name} entity with ID {group.Name}");
            }

            var groupUsers = new List <GroupUser>();

            foreach (var user in usersToAdd)
            {
                group.Users.Add(user);
                var groupUser = new GroupUser
                {
                    GroupId          = groupEntity.GroupId,
                    IdentityProvider = user.IdentityProvider,
                    SubjectId        = user.SubjectId
                };

                AuthorizationDbContext.GroupUsers.Add(groupUser);
                groupUsers.Add(groupUser);
            }

            await AuthorizationDbContext.SaveChangesAsync();

            await EventService.RaiseEventAsync(new EntityAuditEvent <Group>(EventTypes.ChildEntityCreatedEvent, group.Id.ToString(), group));

            return(group);
        }
コード例 #16
0
        public void AddUsers(UsersListViewComponentViewModel inputModel, string groupId)
        {
            List <string> usersInGroup = this.context.GroupUsers
                                         .Where(gu => gu.GroupId == groupId)
                                         .Select(gu => gu.User.UserName).ToList();

            IEnumerable <string> userIds = inputModel.SelectedUsers
                                           .Except(usersInGroup)
                                           .Select(u => this.userManager.Users.FirstOrDefault(x => x.Email == u).Id);

            List <GroupUser> groupUsers = new List <GroupUser>();

            foreach (var id in userIds)
            {
                GroupUser groupUser = new GroupUser
                {
                    GroupId   = groupId,
                    UserId    = id,
                    CreatedOn = DateTime.UtcNow,
                };

                groupUsers.Add(groupUser);
            }

            this.context.GroupUsers.AddRange(groupUsers);
            this.context.SaveChanges();
        }
コード例 #17
0
        public ActionResult AddUser(Guid UserGroupID)
        {
            List <IdentityUser> userList     = db.Users.ToList <IdentityUser>();
            IdentityRole        identityRole = db.Roles.Find(UserGroupID.ToString());
            UserGroup           userGroup    = new UserGroup();

            userGroup.UserGroupID   = new Guid(identityRole.Id);
            userGroup.UserGroupName = identityRole.Name;
            ViewBag.UserGroup       = userGroup;
            List <GroupUser> reverseGroupUserList = new List <GroupUser>();

            foreach (IdentityUser identityUser in userList)
            {
                bool   bFound     = false;
                string UserRoleID = "";
                foreach (IdentityUserRole identityUserRole in identityRole.Users)
                {
                    if (identityUser.Id == identityUserRole.UserId)
                    {
                        UserRoleID = identityUserRole.RoleId;
                        bFound     = true;
                    }
                }
                if (!bFound)
                {
                    GroupUser groupUser = new GroupUser();
                    groupUser.UserID   = new Guid(identityUser.Id);
                    groupUser.UserName = identityUser.UserName;
                    groupUser.Email    = identityUser.Email;
                    reverseGroupUserList.Add(groupUser);
                }
            }
            return(PartialView("_AddUser", reverseGroupUserList));
        }
コード例 #18
0
        public async Task AddUser(string userId, int groupId, string userName)
        {
            var group = await _context.Group.FindAsync(groupId);

            GroupUser groupUser = new GroupUser
            {
                User    = await _context.User.FindAsync(userId),
                Group   = group,
                GroupId = groupId,
                UserId  = userId,
                DM      = group.DM
            };
            Message message = new Message {
                UserId = userId, GroupId = groupId, Body = $"{userName} has joined the group"
            };

            await _context.AddAsync(message);

            await _context.AddAsync(groupUser);

            await _context.SaveChangesAsync();

            await Clients.Groups(group.GroupName).SendAsync("ReceiveExternalMessage", message.Body);

            await Clients.Caller.SendAsync("PostAdd", userId, userName);
        }
コード例 #19
0
        public async Task <GroupConversation> CreateGroupConversation(GroupConversationDTO groupConversationDTO)
        {
            var groupConversation = new GroupConversation()
            {
                Name             = groupConversationDTO.GroupName,
                ConversationType = groupConversationDTO.ConversationType
            };

            await Context.GroupConversation
            .AddAsync(groupConversation);

            await Context.SaveChangesAsync();

            groupConversation = await Context.GroupConversation
                                .FirstOrDefaultAsync(gc => gc.Name == groupConversationDTO.GroupName);

            foreach (var groupMember in groupConversationDTO.GroupMembers)
            {
                var groupUser = new GroupUser()
                {
                    GroupId = groupConversation.Id,
                    UserId  = groupMember.Id
                };
                await Context.GroupUser
                .AddAsync(groupUser);
            }
            await Context.SaveChangesAsync();

            return(groupConversation);
        }
コード例 #20
0
        public IActionResult GetUserClassGroupByClassId([FromRoute] long classId)
        {
            var gu1 = new GroupUser()
            {
                IsLeader = true,
                Id       = 2757,
                Name     = "张三",
                Number   = "23320152202333"
            };
            var gu2 = new GroupUser()
            {
                IsLeader = false,
                Id       = 2756,
                Name     = "李四",
                Number   = "23320152202443"
            };
            var gu3 = new GroupUser()
            {
                IsLeader = false,
                Id       = 2777,
                Name     = "王五",
                Number   = "23320152202433"
            };

            return(Json(new List <GroupUser> {
                gu1, gu2, gu3
            }));
        }
コード例 #21
0
        protected override void CreateDeleteSql(BaseEntity entity, OleDbCommand cmd)
        {
            GroupUser g = entity as GroupUser;

            cmd.CommandText = "DELETE FROM GroupUser WHERE ID=@ID";
            cmd.Parameters.Add(new OleDbParameter("@ID", g.ID));
        }
コード例 #22
0
        public async Task <DatabaseResult> AddUserAsync(GroupUser user)
        {
            try
            {
                var userCheck = await GetGroupUserByIdAsync(user.Id);

                if (userCheck == null)
                {
                    await Database.InsertAsync(user);
                }
                else
                {
                    throw new Exception("User already exists");
                }
            }
            catch (Exception e)
            {
                return(new DatabaseResult()
                {
                    Success = false,
                    StatusMessage = e.Message,
                    Exception = e
                });
            }
            return(new DatabaseResult()
            {
                Success = true,
                StatusMessage = $"User {user.Name} has been successfully added to the group",
                ObjectId = user.Id
            });
        }
コード例 #23
0
        public async Task <IActionResult> LeaveConfirmed(int id)
        {
            var @group = await _context.Groups.FindAsync(id);

            var currentUser = await _usermanager.GetUserAsync(User);

            var groupUser = new GroupUser
            {
                UserId  = currentUser.Id,
                Group   = @group,
                GroupId = @group.ID,
                User    = currentUser
            };
            Boolean Inside = false;

            foreach (var item in _context.GroupUsers)
            {
                if (item.UserId == groupUser.UserId && item.GroupId == groupUser.GroupId)
                {
                    Inside = true;
                }
            }
            if (Inside)
            {
                _context.GroupUsers.Remove(groupUser);
            }
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #24
0
ファイル: GroupController.cs プロジェクト: zhuwansu/Rafy
        /// <summary>
        /// 设置组织的用户列表
        /// 用户列表必须是当前组织的所有用户集合
        /// </summary>
        /// <param name="userIds">用户Id集合</param>
        /// <param name="groupId">组织Id</param>
        public void SetGroupUser(IList <long> userIds, long groupId)
        {
            var groupUserRepository = RepositoryFacade.ResolveInstance <GroupUserRepository>();
            var groupUserList       = groupUserRepository.GetByParentId(groupId).Concrete();
            var changeGroupUserList = groupUserRepository.NewList();
            var groupUsers          = groupUserList as IList <GroupUser> ?? groupUserList.ToList();

            foreach (GroupUser item in groupUsers)
            {
                if (userIds.All(id => id != item.UserId))
                {
                    changeGroupUserList.Add(item);
                    item.PersistenceStatus = PersistenceStatus.Deleted;
                }
            }
            var group = new Group {
                Id = groupId
            };

            foreach (var userId in userIds)
            {
                if (groupUsers.All(g => g.UserId != userId))
                {
                    GroupUser groupUser = new GroupUser();
                    groupUser.Group = group;
                    groupUser.User  = new Accounts.User {
                        Id = userId
                    };
                    groupUser.PersistenceStatus = PersistenceStatus.New;
                    changeGroupUserList.Add(groupUser);
                }
            }
            groupUserRepository.Save(changeGroupUserList);
        }
コード例 #25
0
        public static GroupUserStatus GetUserStatusForGroup(this GroupUser user)
        {
            if (user == null)
            {
                return(GroupUserStatus.NotJoined);
            }

            if (user.Approved && !user.Banned && !user.Locked)
            {
                return(GroupUserStatus.Joined);
            }

            if (!user.Approved && !user.Banned && !user.Locked && !user.Rejected)
            {
                return(GroupUserStatus.Pending);
            }

            if (user.Approved && user.Banned && !user.Locked)
            {
                return(GroupUserStatus.Banned);
            }

            if (user.Approved && !user.Banned && user.Locked)
            {
                return(GroupUserStatus.Locked);
            }

            return(user.Rejected ? GroupUserStatus.Rejected : GroupUserStatus.NotJoined);
        }
コード例 #26
0
        public async Task <ActionResult> ChangeUserRole(long groupId, long userId, GroupUser groupUser)
        {
            GroupUser currentUser = await repository.GetGroupUser(groupId, CurrentUserId);

            GroupUser adjustedUser = await repository.GetGroupUser(groupId, userId);

            Role role = currentUser.Role;

            if (role == Role.user || role == Role.creator)
            {
                return(Unauthorized("Must be a group admin or owner to adjust other user's roles."));
            }
            if (role == Role.admin && (adjustedUser.Role == Role.admin || adjustedUser.Role == Role.owner))
            {
                return(Unauthorized("Admins cannot change the role of other admins."));
            }

            bool didDelete = await groupRepo.RemoveUserAsync(currentUser, adjustedUser);

            if (!didDelete)
            {
                return(Unauthorized("That user does not currently exist in this group. Something must have gone wrong. We're working on it."));
            }

            await groupRepo.AddUserAsync(groupId, adjustedUser.User.UserName, groupUser.Role);

            return(Ok());
        }
コード例 #27
0
        public GroupUser LeaveGroup(GroupUser groupUser)
        {
            _context.Remove(groupUser);
            _context.SaveChanges();

            return(groupUser);
        }
コード例 #28
0
        public GroupUser JoinGroup(GroupUser groupUser)
        {
            _context.Add(groupUser);
            _context.SaveChanges();

            return(groupUser);
        }
コード例 #29
0
        internal NGroupUser(GroupUser message)
        {
            AvatarUrl    = message.User.AvatarUrl;
            CreatedAt    = message.User.CreatedAt;
            Fullname     = message.User.Fullname;
            Handle       = message.User.Handle;
            Id           = message.User.Id;
            Lang         = message.User.Lang;
            LastOnlineAt = message.User.LastOnlineAt;
            Location     = message.User.Location;
            Metadata     = message.User.Metadata;
            Timezone     = message.User.Timezone;
            UpdatedAt    = message.User.UpdatedAt;

            switch (message.State)
            {
            case 0:
                State = UserState.Admin;
                break;

            case 1:
                State = UserState.Member;
                break;

            case 2:
                State = UserState.Join;
                break;
            }
        }
コード例 #30
0
        public Res_Group_User Create(Req_Group_User item)
        {
            try
            {
                using (CMSEntities _context = new CMSEntities())
                {
                    if (!_context.GroupUsers.Any(x => x.Code.Equals(item.Code)))
                    {
                        var Group_User = new GroupUser();
                        Group_User.Code        = item.Code;
                        Group_User.Name        = item.Name;
                        Group_User.Active      = item.Active;
                        Group_User.DateCreated = DateTime.UtcNow;
                        _context.GroupUsers.Add(Group_User);
                        _context.SaveChanges();

                        return(_context.GroupUsers.Where(x => x.Code.Equals(Group_User.Code)).Select(y => new Res_Group_User
                        {
                            Code = y.Code,
                            Name = y.Name,
                            Active = (bool)y.Active,
                            DateCreated = (DateTime)y.DateCreated
                        }).SingleOrDefault());
                    }
                    return(null);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }
コード例 #31
0
ファイル: MainController.cs プロジェクト: Boshin/wojilu
        private string getUserStyle( GroupUser mgr )
        {
            if (mgr.Status == GroupRole.Approving.Id)
                return "color:red;";

            if (mgr.Status == GroupRole.Administrator.Id)
                return "color:blue;";

            return "";
        }
コード例 #32
0
ファイル: MemberGroupService.cs プロジェクト: Boshin/wojilu
        public virtual void JoinCreateGroup( User user, Group group, String ip )
        {
            int users = db.find<GroupUser>( "Member.Id=" + user.Id + " and Group.Id=" + group.Id + " and IsFounder=1" ).count();
            if (users > 0) return;

            GroupUser gu = new GroupUser();

            gu.Member = user;
            gu.Group = group;
            gu.IsFounder = 1;
            gu.Status = GroupRole.Administrator.Id;
            gu.Ip = ip;

            db.insert( gu );

            recountMembers( group );
        }
コード例 #33
0
ファイル: MemberGroupService.cs プロジェクト: Boshin/wojilu
        public virtual Result JoinGroup( User user, Group group, String joinReason, String ip )
        {
            GroupUser gu = db.find<GroupUser>( "Member.Id=" + user.Id + " and Group.Id=" + group.Id ).first();

            if (gu == null) {

                gu = new GroupUser();
                gu.Member = user;
                gu.Group = group;
                gu.Msg = joinReason;
                gu.Ip = ip;

                gu.Status = GroupRole.GetInitRoleByGroup( group );

                Result addResult = db.insert( gu );

                if (group.AccessStatus == GroupAccessStatus.Open) {
                    afterJoinDone( user, group, joinReason, gu );
                }
                else {
                    addApprovingMsg( user, group, joinReason ); // 给管理员发消息
                }

                return addResult;
            }
            else {

                Result result = new Result();
                if (gu.Status == GroupRole.Blacklist.Id) {
                    result.Add( lang.get( "exGroupBeBlacklist" ) );
                }
                else if (gu.Status == GroupRole.Approving.Id) {
                    result.Add( lang.get( "exGroupApprovingTip" ) );
                }
                else
                    result.Add( lang.get( "exGroupBeMember" ) );

                return result;

            }
        }
コード例 #34
0
ファイル: MemberGroupService.cs プロジェクト: Boshin/wojilu
        // 直接加为群组成功,不用审核
        public virtual Result JoinGroupDone( User user, Group group, String joinReason, String ip )
        {
            GroupUser gu = db.find<GroupUser>( "Member.Id=" + user.Id + " and Group.Id=" + group.Id ).first();

            Result result;

            if (gu == null) {

                gu = new GroupUser();
                gu.Member = user;
                gu.Group = group;
                gu.Msg = joinReason;
                gu.Ip = ip;

                result = db.insert( gu );
            }
            else {
                gu.Status = GroupRole.Member.Id;
                gu.Msg = joinReason;

                result = gu.update();
            }

            afterJoinDone( user, group, joinReason, gu );

            return result;
        }
コード例 #35
0
ファイル: MemberGroupService.cs プロジェクト: Boshin/wojilu
 private void afterJoinDone( User user, Group group, String joinReason, GroupUser gu )
 {
     recountMembers( group ); // 重新统计成员数量
     addFeedInfo( gu, gu.Ip ); // 将信息加入用户的新鲜事
     sendOfficerMsg( gu, user, joinReason ); // 告知群组管理员
 }
コード例 #36
0
ファイル: DBDataContext.cs プロジェクト: supermuk/iudico
 partial void InsertGroupUser(GroupUser instance);
コード例 #37
0
ファイル: DBDataContext.cs プロジェクト: supermuk/iudico
 partial void DeleteGroupUser(GroupUser instance);
コード例 #38
0
ファイル: DBDataContext.cs プロジェクト: supermuk/iudico
 partial void UpdateGroupUser(GroupUser instance);
コード例 #39
0
ファイル: MemberGroupService.cs プロジェクト: Boshin/wojilu
        private void addFeedInfo( GroupUser relation, String ip )
        {
            Feed feed = new Feed();
            feed.Creator = relation.Member;
            feed.DataType = typeof( Group ).FullName;

            feed.TitleTemplate = "{*actor*} " + lang.get( "joinedGroup" ) + " {*group*}";
            feed.TitleData = getTitleData( relation.Group );
            feed.Ip = ip;
            feedService.publishUserAction( feed );
        }
コード例 #40
0
ファイル: MemberGroupService.cs プロジェクト: happyYao/wojilu
        private void addFeedInfo( GroupUser relation, String ip )
        {
            User user = relation.Member;
            Group g = relation.Group;

            String msg = string.Format( "<div class=\"feed-item-group\"><div class=\"feed-item-title\">我加入了小组 <a href=\"{0}\">{1}</a></div>", Link.ToMember( g ), g.Name );

            if (strUtil.HasText( g.Description )) {
                msg += string.Format( "<div class=\"feed-item-body\"><span class=\"feed-item-label\">小组简介</span>:{0}</div>", g.Description );
            }
            msg += string.Format( "<div class=\"feed-item-pic\"><a href=\"{1}\"><img src=\"{0}\"/></a></div>", g.LogoSmall, Link.ToMember( g ) );
            msg += "</div>";

            microblogService.Add( relation.Member, msg, typeof( Group ).FullName, relation.Group.Id, ip );
        }
コード例 #41
0
ファイル: MemberGroupService.cs プロジェクト: Boshin/wojilu
        private void sendOfficerMsg( GroupUser gu, User user, string joinReason )
        {
            Group group = gu.Group;

            String msg = string.Format( "用户 {0} 加入了群组 {1}", user.Name, group.Name );
            String body = string.Format( "用户 <a href=\"{1}\" target=\"_blank\">{0}</a> 加入了群组 <a href=\"{3}\" target=\"_blank\">{2}</a>", user.Name, Link.ToMember( user ), group.Name, Link.ToMember( group ) );
            if (strUtil.HasText( joinReason )) {
                body += "<br/>加入信息:" + joinReason;
            }

            List<User> officerList = GetOfficer( group.Id );
            foreach (User officer in officerList) {
                msgService.SiteSend( msg, body, officer );
            }
        }
コード例 #42
0
        public void AddUserToGroup(Group group, User user)
        {
            var db = this.GetDbContext();

            var groupUser = new GroupUser { GroupRef = group.Id, UserRef = user.Id };

            db.GroupUsers.InsertOnSubmit(groupUser);
            db.SubmitChanges();
        }
コード例 #43
0
ファイル: GroupController.cs プロジェクト: supermuk/iudico
        public ActionResult AddUsers(int id)
        {
            var group = _Storage.GetGroup(id);

            var userList =
                _Storage.GetUsersNotInGroup(group).Select(
                    u => new SelectListItem {Text = u.Username, Value = u.Id.ToString(), Selected = false});

            var groupUser = new GroupUser
                                {
                                    Group = group,
                                    UserList = userList
                                };

            return View(groupUser);
        }
コード例 #44
0
        private void addFeedInfo( GroupUser relation, String ip )
        {
            User user = relation.Member;
            Group g = relation.Group;

            String msg = GetFeedMsgByJoin( g );

            microblogService.AddSimple( relation.Member, msg, typeof( Group ).FullName, relation.Group.Id, ip );
        }
コード例 #45
0
 private void GenerateViewBagItems(GroupUser groupUsers = null)
 {
     if (groupUsers == null)
         groupUsers = new GroupUser();
     var userTypes = db.UserTypes.ToList();
     userTypes.Insert(0, null);
     ViewBag.UserTypeID = new SelectList(userTypes, "ID", "Name", groupUsers.UserTypeID);
     var users = db.Users.ToList();
     users.Insert(0, null);
     ViewBag.ChildID = new SelectList(users, "ID", "Name", groupUsers.ChildID);
     var groups = db.Groups.ToList();
     groups.Insert(0, null);
     ViewBag.ParentID = new SelectList(groups, "ID", "Name", groupUsers.ParentID);
 }
コード例 #46
0
ファイル: GroupController.cs プロジェクト: supermuk/iudico
        public ActionResult AddUsers(int id, Guid? userRef)
        {
            var group = _Storage.GetGroup(id);

            if (userRef == null)
            {
                var userList =
                _Storage.GetUsersNotInGroup(group).Select(
                    u => new SelectListItem { Text = u.Username, Value = u.Id.ToString(), Selected = false });

                var groupUser = new GroupUser
                {
                    Group = group,
                    UserList = userList
                };

                ModelState.AddModelError("UserRef", Localization.getMessage("PleaseSelectUserFromList"));

                return View(groupUser);
            }

            var user = _Storage.GetUser(u => u.Id == userRef.Value);
            
            _Storage.AddUserToGroup(group, user);

            return RedirectToAction("Details", new { Id = id });
        }