/// <summary> /// Create a new weather. /// </summary> /// <param name="sender">Object that requested the page load</param> /// <param name="e">The event arguments.</param> protected void CreateUser(object sender, EventArgs e) { if (UserDAO.GetUserFromUserName(txbUserName.Text) == null) { var user = new User { UserName = txbUserName.Text, FirstName = txbFirstName.Text, LastName = txbLastName.Text, Email = txbEmail.Text, Gender = (ddlGender.SelectedValue) }; user.UserID = UserDAO.CreateNewUser(user, txbPassword.Text); string[] dateTime = DateTime.Now.ToString("MM/dd/yyyy h:mmtt").Split(' '); user.Post(new Message("Welcome to ActivEarth!", "See the tabs to the right to start you on your way to a more active lifestyle!", user, dateTime[0], dateTime[1])); UserDAO.UpdateUserProfile(user); if (user.UserID == 0) { ErrorMessage.Text = "A Database error occurred creating the User."; } else{ Session["userDetails"] = user; Response.Redirect("~/Groups/Groups.aspx"); } } else { ErrorMessage.Text = "A User with the given User Name already exists. Please choose a different User Name."; } //UserDAO.CreateNewUser() }
/// <summary> /// Adds a User's the list of Recent Acitivity Messages stored in the Database to the User's Wall. /// </summary> /// <param name="user">The User for which to retrieve Recent Activity Messages</param> public static void GetUserRecentActivity(User user) { try { using (SqlConnection connection = ConnectionManager.GetConnection()) { var data = new ActivEarthDataProvidersDataContext(connection); List<Message> messages = (from m in data.MessageDataProviders where m.group_id == -1 && m.user_id == user.UserID select new Message(m.title, m.message, UserDAO.GetUserFromUserId(m.user_id), m.date, m.time) ).ToList(); foreach (Message message in messages) { user.Post(message); } } } catch (Exception) { } }
public void TestUserWall() { var user1 = new User { UserName = "******", Age = 25, City = "Bleaksburg", Email = "*****@*****.**", FirstName = "I.C.", Gender = "M", Height = 60, LastName = "Poorcode", State = "VA", Weight = 130, ActivityScore = new Objects.Competition.ActivityScore(0,0,0) }; var user2 = new User { UserName = "******", Age = 25, City = "Bleaksburg", Email = "*****@*****.**", FirstName = "I.C.", Gender = "M", Height = 60, LastName = "Poorcode", State = "VA", Weight = 130, ActivityScore = new Objects.Competition.ActivityScore(0, 0, 0) }; user1.UserID = UserDAO.CreateNewUser(user1, "password"); user2.UserID = UserDAO.CreateNewUser(user2, "password"); Message message1 = new Message("Recent Activity 1", "User joined ActivEarth!", user1, "March 16 2012", "12:34:25 PM"); user1.Post(message1); Message message2 = new Message("Recent Activity 2", "User ran 5 miles!", user2, "March 16 2012", "12:44:25 PM"); Message message3 = new Message("Recent Activity 3", "User saved $10 in gas!", user2, "March 16 2012", "12:54:25 PM"); user2.Post(message2); user2.Post(message3); UserDAO.UpdateUserProfile(user1); UserDAO.UpdateUserProfile(user2); User dbUser1 = UserDAO.GetUserFromUserId(user1.UserID); User dbUser2 = UserDAO.GetUserFromUserId(user2.UserID); Assert.AreEqual(dbUser1.Wall.Messages.Count, 1); Assert.AreEqual(dbUser1.Wall.Messages.First().Title, "Recent Activity 1"); Assert.AreEqual(dbUser1.Wall.Messages.First().Text, "User joined ActivEarth!"); Assert.AreEqual(dbUser1.Wall.Messages.First().Poster.UserName, "User1"); Assert.AreEqual(dbUser2.Wall.Messages.Count, 2); Assert.AreEqual(dbUser2.Wall.Messages.First().Title, "Recent Activity 2"); Assert.AreEqual(dbUser2.Wall.Messages.First().Text, "User ran 5 miles!"); Assert.AreEqual(dbUser2.Wall.Messages.First().Poster.UserName, "User2"); Assert.AreEqual(dbUser2.Wall.Messages.Last().Title, "Recent Activity 3"); Assert.AreEqual(dbUser2.Wall.Messages.Last().Text, "User saved $10 in gas!"); Assert.AreEqual(dbUser2.Wall.Messages.Last().Poster.UserName, "User2"); }