예제 #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> UserLogin(Interfaces.IRepository repo, string u, string country)
        {
            string        msg  = "";
            UserDataModel user = await repo.GetUser(u);

            if (user == null)
            {
                user = new UserDataModel
                {
                    id       = u.ToLower(),
                    UserName = u,
                    Country  = country,
                    Groups   = new List <string>()
                };
            }

            msg = await repo.UpdateUserAsync(user);

            return(msg);
        }
예제 #3
0
        public async Task <string> CreateGroup(Interfaces.IRepository repo, Models.GroupDataModel g)
        {
            string msg = "";

            g.id          = g.Name.Replace(' ', '-');
            g.Name        = g.Name.Replace(' ', '-');
            g.MemberCount = 1;
            msg           = await repo.AddGroupAsync(g);

            UserDataModel user = await repo.GetUser(g.Owner);

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

            user.Groups.Add(g.id);
            await repo.UpdateUserAsync(user);

            return(msg);
        }
예제 #4
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);
        }