예제 #1
0
        public async Task <string> JoinGroup(Interfaces.IRepository repo, string u, string g)
        {
            string msg = "";

            string groupId = g;

            var group = await repo.GetGroupAsync(groupId);

            if (group == null)
            {
                msg = "group does not exist";
                return(msg);
            }

            UserDataModel user = await repo.GetUser(u);

            if (user == null)
            {
                msg = "user does not exist";
                return(msg);
            }

            if (group.MemberCount >= LibrarySettings.MAX_MEMBERS)
            {
                msg = group.Name + " reached maximum number of members";
            }
            else
            {
                // join group
                user.Groups.Add(groupId);

                await repo.UpdateUserAsync(user);

                group.MemberCount++;

                msg = u + " joined group " + group.Name;

                await repo.UpdateGroupAsync(group);
            }



            return(msg);
        }
예제 #2
0
        public async Task <string> LeaveGroup(Interfaces.IRepository repo, string u, string g)
        {
            string msg = "";

            string groupId = g;

            var group = await repo.GetGroupAsync(groupId);

            if (group == null)
            {
                msg = "group does not exist";
                return(msg);
            }

            UserDataModel user = await repo.GetUser(u);

            if (user == null)
            {
                msg = "user does not exist";
                return(msg);
            }

            if (user.Groups.Contains(groupId))
            {
                // leave group
                user.Groups.Remove(groupId);

                await repo.UpdateUserAsync(user);

                group.MemberCount--;

                msg = u + " left group " + group.Name;

                await repo.UpdateGroupAsync(group);
            }



            return(msg);
        }