public Post ( |
||
message | The Message to be added to the Group's Wall. | |
return | void |
/// <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) { } }
/// <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."; } }
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"); }
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"); }