Пример #1
0
        /// <summary>
        /// Adds a Group's the list of Recent Acitivity Messages stored in the Database to the Group's Wall.
        /// </summary>
        /// <param name="group">The Group for which to retrieve Recent Activity Messages</param>
        public static void GetGroupRecentActivity(Group group)
        {
            int groupId = group.ID;

            try
            {
                using (SqlConnection connection = ConnectionManager.GetConnection())
                {
                    var data = new ActivEarthDataProvidersDataContext(connection);

                    List<Message> messages = (from m in data.MessageDataProviders
                                              where m.group_id == groupId
                                              select
                                              new Message(m.title, m.message, UserDAO.GetUserFromUserId(m.user_id), m.date, m.time)
                                         ).ToList();

                    foreach (Message message in messages)
                    {
                        group.Post(message);
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Пример #2
0
        /// <summary>
        /// Method called when the Create Group Button is clicked.  Pulls information from the text boxes on the page, adds a welcome
        /// message to the Group wall, and inserts the new group into the Database.
        /// </summary>
        protected void CreateNewGroup(object sender, EventArgs e)
        {
            if (GroupDAO.GetGroupFromName(txbGroupName.Text) == null)
            {
                List<string> hashTags = lblAllHashTags.Text.Substring(1, lblAllHashTags.Text.Length - 2).Split(',').Select(sValue => sValue.Trim()).ToList();

                User owner = (User) Session["userDetails"];

                Group group = new Group(txbGroupName.Text, owner, txbDescription.Text, hashTags);
                group.ID = GroupDAO.CreateNewGroup(group);
                string[] dateTime = DateTime.Now.ToString("MM/dd/yyyy h:mmtt").Split(' ');
                group.Post(new Message("Created Group", owner.FirstName + " " + owner.LastName + " created the group " + group.Name + "!",
                    owner, dateTime[0], dateTime[1]));
                GroupDAO.UpdateGroup(group);

                if (group.ID == 0)
                {
                    ErrorMessage.Text = "A Database error occurred creating the Group.";
                }
                else
                {
                    Response.Redirect("~/Groups/Groups.aspx");
                }
            }
            else
            {
                ErrorMessage.Text = "A Group with the given Group Name already exists.  Please choose a different Group Name.";
            }
        }
Пример #3
0
        /// <summary>
        /// Adds a group to a group Contest; will fail if a group is added to an individual contest.
        /// </summary>
        /// <param name="contestId">ID for the contest the group should be added to.</param>
        /// <param name="group">Group to be added.</param>
        /// <returns>True on success, false on failure.</returns>
        public static bool AddGroup(int contestId, Group group)
        {
            Contest contest = ContestDAO.GetContestFromContestId(contestId, false, false);

            if (contest.Type == ContestType.Group)
            {
                string teamName = group.Name;

                ContestTeam newTeam = new ContestTeam
                {
                    ContestId = contestId,
                    Name = teamName,
                    GroupId = group.ID
                };

                int teamId = TeamDAO.CreateNewTeam(newTeam);

                foreach (User user in group.Members)
                {
                    TeamDAO.CreateNewTeamMember(user.UserID, teamId);
                }

                contest.Reward = ContestManager.CalculateContestReward(
                    ContestManager.CalculateEstimatedLengthInDays(contest),
                    TeamDAO.GetTeamsFromContestId(contestId, false).Count);
                ContestDAO.UpdateContest(contest);

                return (teamId > 0);
            }
            else
            {
                return false;
            }
        }
Пример #4
0
        public void Initialize()
        {
            _user1 = new User("Test", "Subject1");
            _user2 = new User("Test", "Subject2");

            _allUsers = new Group(0, "All Users", _user1, string.Empty, new List<string>());
            _allUsers.Members.Add(_user1);
            _allUsers.Members.Add(_user2);

            _manager = new ChallengeManager(_allUsers);
            _trans = new TransactionScope();
        }
Пример #5
0
        public void Initialize()
        {
            _user1 = new User("Test", "Subject1");
            _user2 = new User("Test", "Subject2");
            _user3 = new User("Test", "Subject3");
            _user4 = new User("Test", "Subject4");

            _group1 = new Group(1, "Group 1", _user1, string.Empty, new List<string>());
            _group1.Members.Add(_user2);

            _group2 = new Group(2, "Group 2", _user3, string.Empty, new List<string>());
            _group2.Members.Add(_user4);
            _trans = new TransactionScope();
        }
Пример #6
0
        /// <summary>
        /// Creates a Group as a new entry in the DB.
        /// </summary>
        /// <param name="group">Group object to add to the DB.</param>
        /// <returns>ID of the created Group on success, 0 on failure.</returns>
        public static int CreateNewGroup(Group group)
        {
            try
            {
                using (SqlConnection connection = ConnectionManager.GetConnection())
                {
                    var data = new ActivEarthDataProvidersDataContext(connection);
                    var groupData = new GroupDataProvider
                    {
                        name = group.Name,
                        description = group.Description,
                        owner_id = group.Owner.UserID,
                        green_score = group.GreenScore,
                        badge_score = group.ActivityScore.BadgeScore,
                        challenge_score = group.ActivityScore.ChallengeScore,
                        contest_score = group.ActivityScore.ContestScore,
                    };
                    data.GroupDataProviders.InsertOnSubmit(groupData);
                    data.SubmitChanges();

                    foreach (User member in group.Members) {
                        GroupMemberDataProvider memberData = new GroupMemberDataProvider
                        {
                            user_id = member.UserID,
                            group_id = groupData.id
                        };
                        data.GroupMemberDataProviders.InsertOnSubmit(memberData);
                    }

                    foreach (string tag in group.HashTags)
                    {
                        GroupHashtagDataProvider hashtagData = new GroupHashtagDataProvider
                        {
                            hashtag = tag,
                            group_id = groupData.id
                        };
                        data.GroupHashtagDataProviders.InsertOnSubmit(hashtagData);
                    }

                    data.SubmitChanges();
                    data.Connection.Close();
                    return groupData.id;
                }
            }
            catch (Exception)
            {
                return 0;
            }
        }
Пример #7
0
        /// <summary>
        /// Adds a group to the Contest. In a group contest, members will be added as one team,
        /// while in an individual contest members will be added individually.
        /// </summary>
        /// <param name="group">Group to be added.</param>
        public void AddGroup(Group group)
        {
            if (this.Type == ContestType.Group)
            {
                string teamName = group.Name;
                //TODO: Assert that no team with this name exists already

                Team newTeam = new Team(teamName);

                foreach (User user in group.Members)
                {
                    newTeam.Members.Add(new TeamMember(user));
                }

                this.AddTeam(newTeam);
            }
            else
            {
                foreach (User user in group.Members)
                {
                    this.AddUser(user);
                }
            }
        }
Пример #8
0
 public ChallengeManager(Group allUsers)
 {
     _allUsers = allUsers;
 }
Пример #9
0
        public void TestCreateGroup()
        {
            var owner = new User
            {
                UserName = "******",
                Age = 25, City = "Bleaksburg", Email = "*****@*****.**", FirstName = "I.C.", Gender = "M",
                Height = 60, LastName = "Poorcode", State = "VA", Weight = 130
            };
            var member = new User
            {
                UserName = "******",
                Age = 25, City = "Bleaksburg", Email = "*****@*****.**", FirstName = "I.C.", Gender = "M",
                Height = 60, LastName = "Poorcode", State = "VA", Weight = 130
            };
            var notMember = new User
            {
                UserName = "******",
                Age = 25, City = "Bleaksburg", Email = "*****@*****.**", FirstName = "I.C.", Gender = "M",
                Height = 60, LastName = "Poorcode", State = "VA", Weight = 130
            };

            owner.UserID = UserDAO.CreateNewUser(owner, "password");
            member.UserID = UserDAO.CreateNewUser(member, "password");
            notMember.UserID = UserDAO.CreateNewUser(notMember, "password");

            List<string> tags = new List<string>();
            tags.Add("new");
            tags.Add("searchable");
            tags.Add("hashtags");

            Group testGroup = new Group("Test", owner, "This is a Group", tags);
            testGroup.Join(member);

            int id = GroupDAO.CreateNewGroup(testGroup);
            Assert.AreNotEqual(id, 0);

            Group dbGroup = GroupDAO.GetGroupFromGroupId(id);
            Assert.AreEqual("Test", dbGroup.Name);
            Assert.AreEqual("owner", dbGroup.Owner.UserName);
            Assert.AreEqual("This is a Group", dbGroup.Description);

            for (int i = 0; i < tags.Count; i++)
            {
                Assert.AreEqual(tags.ElementAt(i), dbGroup.HashTags.ElementAt(i));
            }

            Assert.AreEqual(2, dbGroup.Members.Count);
            foreach (User u in dbGroup.Members) {
                Assert.IsNotNull(u);
                Assert.AreNotEqual("notMember", u.UserName);
            }
        }
Пример #10
0
        public void TestUpdateGroup()
        {
            var owner = new User
            {
                UserName = "******",
                Age = 25,
                City = "Bleaksburg",
                Email = "*****@*****.**",
                FirstName = "I.C.",
                Gender = "M",
                Height = 60,
                LastName = "Poorcode",
                State = "VA",
                Weight = 130
            };
            var member1 = new User
            {
                UserName = "******",
                Age = 25,
                City = "Bleaksburg",
                Email = "*****@*****.**",
                FirstName = "I.C.",
                Gender = "M",
                Height = 60,
                LastName = "Poorcode",
                State = "VA",
                Weight = 130
            };
            var member2 = new User
            {
                UserName = "******",
                Age = 25,
                City = "Bleaksburg",
                Email = "*****@*****.**",
                FirstName = "I.C.",
                Gender = "M",
                Height = 60,
                LastName = "Poorcode",
                State = "VA",
                Weight = 130
            };

            owner.UserID = UserDAO.CreateNewUser(owner, "password");
            member1.UserID = UserDAO.CreateNewUser(member1, "password");
            member2.UserID = UserDAO.CreateNewUser(member2, "password");

            List<string> tags = new List<string>();
            tags.Add("new");
            tags.Add("searchable");

            Group testGroup = new Group("Test1", owner, "This is a Group", tags);
            testGroup.Join(member1);
            Message message1 = new Message("HI GUYS", "THIS IS AN AWESOME GROUP", owner, "March 16 2012", "12:34:25 PM");
            testGroup.Post(message1);
            testGroup.ID = GroupDAO.CreateNewGroup(testGroup);

            testGroup.Name = "AWESOME GROUP! YAY!";
            testGroup.Quit(member1);
            testGroup.Join(member2);
            testGroup.HashTags.Add("hashtags");
            testGroup.HashTags.Remove("searchable");
            Message message2 = new Message("JUST KIDDING", "I HATE YOU GUYS", owner, "March 16 2012", "12:34:25 PM");
            testGroup.Post(message2);
            GroupDAO.UpdateGroup(testGroup);

            Group dbGroup = GroupDAO.GetGroupFromGroupId(testGroup.ID);
            Assert.AreEqual(dbGroup.Name, "AWESOME GROUP! YAY!");
            Assert.AreEqual(dbGroup.HashTags.ElementAt(1), "hashtags");
            Assert.AreEqual(dbGroup.Members.ElementAt(1).UserName, "member2");
            Assert.AreEqual(dbGroup.Wall.Messages.Last().Text, "I HATE YOU GUYS");
        }
Пример #11
0
        public void TestGetGroupWall()
        {
            var owner = new User
            {
                UserName = "******",
                Age = 25,
                City = "Bleaksburg",
                Email = "*****@*****.**",
                FirstName = "I.C.",
                Gender = "M",
                Height = 60,
                LastName = "Poorcode",
                State = "VA",
                Weight = 130
            };

            owner.UserID = UserDAO.CreateNewUser(owner, "password");

            List<string> tags = new List<string>();
            tags.Add("new");
            tags.Add("searchable");
            tags.Add("hashtags");

            Group testGroup1 = new Group("Test1", owner, "This is a Group", tags);
            Message message1 = new Message("HI GUYS", "THIS IS AN AWESOME GROUP", owner, "March 16 2012", "12:34:25 PM");
            testGroup1.Post(message1);
            testGroup1.ID = GroupDAO.CreateNewGroup(testGroup1);

            Group testGroup2 = new Group("Test2", owner, "This is another Group", tags);
            Message message2 = new Message("I HATE YOU GUYS", "THIS IS AN AWFUL GROUP", owner, "March 16 2012", "12:34:25 PM");
            Message message3 = new Message("JUST KIDDING", "I LOVE YOU GUYS", owner, "March 16 2012", "12:34:25 PM");
            testGroup2.Post(message2);
            testGroup2.Post(message3);
            testGroup2.ID = GroupDAO.CreateNewGroup(testGroup2);

            Assert.AreNotEqual(testGroup1.ID, 0);
            Assert.AreNotEqual(testGroup2.ID, 0);

            GroupDAO.UpdateGroup(testGroup1);
            GroupDAO.UpdateGroup(testGroup2);

            Group dbGroup1 = GroupDAO.GetGroupFromGroupId(testGroup1.ID);
            Group dbGroup2 = GroupDAO.GetGroupFromGroupId(testGroup2.ID);
            Assert.AreEqual(dbGroup1.Wall.Messages.Count, 1);
            Assert.AreEqual(dbGroup1.Wall.Messages.First().Title, "HI GUYS");
            Assert.AreEqual(dbGroup1.Wall.Messages.First().Text, "THIS IS AN AWESOME GROUP");
            Assert.AreEqual(dbGroup1.Wall.Messages.First().Poster.UserName, "owner");
            Assert.AreEqual(dbGroup2.Wall.Messages.Count, 2);
            Assert.AreEqual(dbGroup2.Wall.Messages.First().Title, "I HATE YOU GUYS");
            Assert.AreEqual(dbGroup2.Wall.Messages.First().Text, "THIS IS AN AWFUL GROUP");
            Assert.AreEqual(dbGroup2.Wall.Messages.First().Poster.UserName, "owner");
            Assert.AreEqual(dbGroup2.Wall.Messages.Last().Title, "JUST KIDDING");
            Assert.AreEqual(dbGroup2.Wall.Messages.Last().Text, "I LOVE YOU GUYS");
            Assert.AreEqual(dbGroup2.Wall.Messages.Last().Poster.UserName, "owner");
        }
Пример #12
0
        public void TestGetGroupByName()
        {
            var owner = new User
            {
                UserName = "******",
                Age = 25,
                City = "Bleaksburg",
                Email = "*****@*****.**",
                FirstName = "I.C.",
                Gender = "M",
                Height = 60,
                LastName = "Poorcode",
                State = "VA",
                Weight = 130
            };
            var member1 = new User
            {
                UserName = "******",
                Age = 25,
                City = "Bleaksburg",
                Email = "*****@*****.**",
                FirstName = "I.C.",
                Gender = "M",
                Height = 60,
                LastName = "Poorcode",
                State = "VA",
                Weight = 130
            };
            var member2 = new User
            {
                UserName = "******",
                Age = 25,
                City = "Bleaksburg",
                Email = "*****@*****.**",
                FirstName = "I.C.",
                Gender = "M",
                Height = 60,
                LastName = "Poorcode",
                State = "VA",
                Weight = 130
            };

            owner.UserID = UserDAO.CreateNewUser(owner, "password");
            member1.UserID = UserDAO.CreateNewUser(member1, "password");
            member2.UserID = UserDAO.CreateNewUser(member2, "password");

            List<string> tags1 = new List<string>(); List<string> tags2 = new List<string>();
            tags1.Add("new"); tags2.Add("new");
            tags1.Add("searchable"); tags2.Add("searchable");
            tags2.Add("hashtags");

            Group testGroup1 = new Group("Test1", owner, "This is a Group", tags1);
            testGroup1.Join(member1);
            testGroup1.ID = GroupDAO.CreateNewGroup(testGroup1);

            Group testGroup2 = new Group("Test2", owner, "This is another Group", tags2);
            testGroup2.Join(member2);
            testGroup2.ID = GroupDAO.CreateNewGroup(testGroup2);

            Assert.AreNotEqual(testGroup1.ID, 0);
            Assert.AreNotEqual(testGroup2.ID, 0);

            List<Group> taggedGroups = GroupDAO.GetAllGroupsByName("Test2");
            Assert.AreEqual(taggedGroups.Count, 1);
            Assert.AreEqual(taggedGroups.First().Name, "Test2");
            Assert.AreEqual(2, taggedGroups.First().Members.Count);
            foreach (User u in taggedGroups.First().Members)
            {
                Assert.IsNotNull(u);
                Assert.AreNotEqual("member1", u.UserName);
            }

            taggedGroups = GroupDAO.GetAllGroupsByName("Test");
            Assert.AreEqual(taggedGroups.Count, 2);
            Assert.AreEqual(taggedGroups.First().Name, "Test1");
            Assert.AreEqual(taggedGroups.Last().Name, "Test2");
        }
Пример #13
0
        /// <summary>
        /// Updates a Group's the list of Recent Acitivity Messages in the Database.
        /// </summary>
        /// <param name="group">The Group for which to update Recent Activity Messages</param>
        public static bool UpdateGroupRecentActivity(Group group)
        {
            int groupId = group.ID;
            try
            {
                using (SqlConnection connection = ConnectionManager.GetConnection())
                {
                    var data = new ActivEarthDataProvidersDataContext(connection);
                    List<MessageDataProvider> messages = (from m in data.MessageDataProviders
                                                where m.group_id == groupId
                                                select
                                                    m
                                                ).ToList();

                    foreach (MessageDataProvider messageData in messages)
                    {
                        bool found = false;
                        foreach (Message message in group.Wall.Messages)
                        {
                            if (messageData.message == message.Text && messageData.user_id == message.Poster.UserID
                                && messageData.title == message.Title && messageData.time == message.Time && messageData.date == message.Date)
                            {
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            data.MessageDataProviders.DeleteOnSubmit(messageData);
                        }
                    }

                    foreach (Message message in group.Wall.Messages)
                    {
                        bool found = false;
                        foreach (MessageDataProvider messageData in messages)
                        {
                            if (messageData.message == message.Text && messageData.user_id == message.Poster.UserID
                                && messageData.title == message.Title && messageData.time == message.Time && messageData.date == message.Date)
                            {
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            MessageDataProvider messageData = new MessageDataProvider
                            {
                                title = message.Title,
                                message = message.Text,
                                user_id = message.Poster.UserID,
                                group_id = groupId,
                                date = message.Date,
                                time = message.Time
                            };
                            data.MessageDataProviders.InsertOnSubmit(messageData);
                        }
                    }

                    data.SubmitChanges();
                    return true;
                }
            }
            catch(Exception)
            {
                return false;
            }
        }
Пример #14
0
        public void TestUpdateContestAddTeamMembers()
        {
            using (_trans)
            {
                Log("Creating contest");
                Contest contest = new Contest("Test Contest1", "This is a test contest",
                    30, ContestEndMode.GoalBased, ContestType.Group, DateTime.Today,
                    new EndCondition(500), Statistic.Steps);

                Log("Creating Members");
                User member1 = new User("Test", "Subject1");
                User member2 = new User("Test", "Subject2");
                User member3 = new User("Test", "Subject3");
                User member4 = new User("Test", "Subject4");

                Log("Creating Groups");
                Group group1 = new Group(0, "Group 1", member1, string.Empty, new List<string>());
                group1.Members.Add(member2);

                Log("Adding group to the contest");
                contest.AddGroup(group1);

                Log("Adding Members to DB");
                Assert.Fail("Not yet implemented");
                /*UserDAO.CreateNewUser(member1);
                UserDAO.CreateNewUser(member2);
                UserDAO.CreateNewUser(member3);
                UserDAO.CreateNewUser(member4);*/

                Log("Saving to DB");
                int id = ContestDAO.CreateNewContest(contest);

                Log("Reading back from DB");
                Contest retrieved = ContestDAO.GetContestFromContestId(id);

                Log("Adding two more members to the team");
                retrieved.Teams[0].Members.Add(new TeamMember(member3));
                retrieved.Teams[0].Members.Add(new TeamMember(member4));

                Log("Updating Contest in DB");
                Assert.IsTrue(ContestDAO.UpdateContest(retrieved));

                Log("Re-loading contest from DB");
                Contest retrieved2 = ContestDAO.GetContestFromContestId(id);

                Log("Verifying the correct number of teams");
                Assert.AreEqual(retrieved.Teams.Count, retrieved2.Teams.Count);

                Log("Verifying that each member is found");
                Assert.IsTrue(retrieved2.Teams[0].ContainsMember(member1));
                Assert.IsTrue(retrieved2.Teams[0].ContainsMember(member2));
                Assert.IsTrue(retrieved2.Teams[0].ContainsMember(member3));
                Assert.IsTrue(retrieved2.Teams[0].ContainsMember(member4));
            }
        }
Пример #15
0
        public void Initialize()
        {
            _user1 = new User
            {
                UserName = "******",
                FirstName = "Test",
                LastName = "Subject1",
                City = "St. Louis",
                State = "MO",
                Gender = "M",
                Email = "*****@*****.**"
            };

            _user2 = new User
            {
                UserName = "******",
                FirstName = "Test",
                LastName = "Subject2",
                City = "Missoula",
                State = "MT",
                Gender = "M",
                Email = "*****@*****.**"
            };
            _user3 = new User
            {
                UserName = "******",
                FirstName = "Test",
                LastName = "Subject3",
                City = "Oakland",
                State = "CA",
                Gender = "F",
                Email = "*****@*****.**"
            };

            _user4 = new User
            {
                UserName = "******",
                FirstName = "Test",
                LastName = "Subject4",
                City = "Albany",
                State = "NY",
                Gender = "M",
                Email = "*****@*****.**"
            };

            _group1 = new Group
            {
                Name = "Group 1",
                Owner = _user1,
                Description = String.Empty
            };
            _group1.Members.Add(_user1);
            _group1.Members.Add(_user2);

            _group2 = new Group
            {
                Name = "Group 2",
                Owner = _user3,
                Description = String.Empty
            };
            _group2.Members.Add(_user3);
            _group2.Members.Add(_user4);

            _trans = new TransactionScope();
        }
Пример #16
0
        /// <summary>
        /// Removes a group from a Contest.
        /// </summary>
        /// <param name="contestId">ID for the contest the group should be removed from.</param>
        /// <param name="group">Group to be removed.</param>
        /// <returns>True on success, false on failure.</returns>
        public static bool RemoveGroup(int contestId, Group group)
        {
            try
            {
                ContestTeam team = TeamDAO.GetTeamsFromContestId(contestId, false).Where(t => t.GroupId == group.ID).FirstOrDefault();

                if (team != null && TeamDAO.RemoveTeam(team.ID))
                {
                    Contest contest = ContestDAO.GetContestFromContestId(contestId, false, false);
                    contest.Reward = ContestManager.CalculateContestReward(
                        ContestManager.CalculateEstimatedLengthInDays(contest),
                    TeamDAO.GetTeamsFromContestId(contestId, false).Count);
                    ContestDAO.UpdateContest(contest);

                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
Пример #17
0
        /// <summary>
        /// Updates an existing Group in the DB.
        /// </summary>
        /// <param name="group">Group whose information needs to be updated.</param>
        /// <returns>True on success, false on failure.</returns>
        public static bool UpdateGroup(Group group)
        {
            try
            {
                using (SqlConnection connection = ConnectionManager.GetConnection())
                {
                    var data = new ActivEarthDataProvidersDataContext(connection);
                    int groupId = group.ID;
                    GroupDataProvider dbGroup = (from g in data.GroupDataProviders
                                                 where g.id == groupId
                                                 select g).FirstOrDefault();
                    if (dbGroup != null)
                    {
                        dbGroup.name = group.Name;
                        dbGroup.description = group.Description;
                        dbGroup.owner_id = group.Owner.UserID;
                        dbGroup.green_score = group.GreenScore;
                        dbGroup.badge_score = group.ActivityScore.BadgeScore;
                        dbGroup.challenge_score = group.ActivityScore.ChallengeScore;
                        dbGroup.contest_score = group.ActivityScore.ContestScore;

                        //Update group_hashtags table
                        List<GroupHashtagDataProvider> hashtags = (from h in data.GroupHashtagDataProviders
                                                 where h.group_id == groupId
                                                 select
                                                     h
                                         ).ToList();

                        foreach (GroupHashtagDataProvider hashtagData in hashtags)
                        {
                            if (!group.HashTags.Contains(hashtagData.hashtag)){
                                data.GroupHashtagDataProviders.DeleteOnSubmit(hashtagData);
                            }
                        }

                        foreach (string hashtag in group.HashTags)
                        {
                            bool found = false;
                            foreach (GroupHashtagDataProvider hashtagData in hashtags)
                            {
                                if (hashtagData.hashtag == hashtag)
                                {
                                    found = true;
                                }
                            }
                            if (!found)
                            {
                                GroupHashtagDataProvider hashtagData = new GroupHashtagDataProvider
                                {
                                    hashtag = hashtag,
                                    group_id = groupId
                                };
                                data.GroupHashtagDataProviders.InsertOnSubmit(hashtagData);
                            }
                        }

                        //Update group_members table
                        List<GroupMemberDataProvider> members = (from u in data.GroupMemberDataProviders
                                                where u.group_id == groupId
                                                select
                                                    u
                                              ).ToList();

                        foreach (GroupMemberDataProvider memberData in members)
                        {
                            bool found = false;
                            foreach (User member in group.Members)
                            {
                                if (memberData.user_id == member.UserID)
                                {
                                    found = true;
                                }
                            }
                            if (!found)
                            {
                                data.GroupMemberDataProviders.DeleteOnSubmit(memberData);
                            }
                        }

                        foreach (User member in group.Members)
                        {
                            bool found = false;
                            foreach (GroupMemberDataProvider memberData in members)
                            {
                                if (memberData.user_id == member.UserID)
                                {
                                    found = true;
                                }
                            }
                            if (!found)
                            {
                                GroupMemberDataProvider memberData = new GroupMemberDataProvider
                                {
                                    user_id = member.UserID,
                                    group_id = groupId
                                };
                                data.GroupMemberDataProviders.InsertOnSubmit(memberData);
                            }
                        }

                        //Update Teams table
                        List<TeamDataProvider> contests = (from c in data.TeamDataProviders
                                                 where c.group_id == groupId
                                                 select
                                                     c
                                                 ).ToList();

                        foreach (TeamDataProvider contestData in contests)
                        {
                            bool found = false;
                            foreach (Contest contest in group.Contests)
                            {
                                if (contestData.contest_id == contest.ID)
                                {
                                    found = true;
                                }
                            }
                            if (!found)
                            {
                                data.TeamDataProviders.DeleteOnSubmit(contestData);
                            }
                        }

                        RecentActivityDAO.UpdateGroupRecentActivity(group);

                        data.SubmitChanges();
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
Пример #18
0
        public void TestUpdateContestLockInitialization()
        {
            using (_trans)
            {
                Log("Creating contest");
                Contest contest = new Contest("Test Contest1", "This is a test contest",
                    30, ContestEndMode.GoalBased, ContestType.Group, DateTime.Today,
                    new EndCondition(500), Statistic.Steps);

                Log("Creating Members");
                User member1 = new User("Test", "Subject1");
                User member2 = new User("Test", "Subject2");
                User member3 = new User("Test", "Subject3");
                User member4 = new User("Test", "Subject4");

                Log("Creating Groups");
                Group group1 = new Group(0, "Group 1", member1, string.Empty, new List<string>());
                group1.Members.Add(member2);

                Group group2 = new Group(0, "Group 2", member3, string.Empty, new List<string>());
                group2.Members.Add(member4);

                Log("Adding groups to the contest");
                contest.AddGroup(group1);
                contest.AddGroup(group2);

                Log("Adding Members to DB");
                Assert.Fail("Not yet implemented");
                /*UserDAO.CreateNewUser(member1);
                UserDAO.CreateNewUser(member2);
                UserDAO.CreateNewUser(member3);
                UserDAO.CreateNewUser(member4);*/

                Log("Saving to DB");
                int id = ContestDAO.CreateNewContest(contest);

                Log("Reading back from DB");
                Contest retrieved = ContestDAO.GetContestFromContestId(id);

                Log("Locking Initialization");
                retrieved.LockInitialValues();

                Log("Updating contest entry in DB");
                Assert.IsTrue(ContestDAO.UpdateContest(retrieved));

                Log("Reading back from DB");
                Contest retrieved2 = ContestDAO.GetContestFromContestId(id);

                Log("Verifying that contest participants have been locked");
                Assert.IsTrue(retrieved2.Teams[0].Members[0].Initialized);
                Assert.IsTrue(retrieved2.Teams[0].Members[1].Initialized);
                Assert.IsTrue(retrieved2.Teams[1].Members[0].Initialized);
                Assert.IsTrue(retrieved2.Teams[1].Members[1].Initialized);
            }
        }