Example #1
0
        public GuestBookDTO Get(GuestBookDTO obj)
        {
            GuestBookDTO EmptyDTO = new GuestBookDTO();

            using (SqlConnection conn = new SqlConnection(DBConnection.CONNECTIONSTRING))
            {
                using (SqlCommand command = new SqlCommand("SELECT Id,User_Nickname,Message,PostTime FROM[GuestBook] " +
                                                           "WHERE [GuestBook].User_Nickname = @Nickname", conn))
                {
                    conn.Open();
                    command.Parameters.AddWithValue("Nickname", obj.NickName);
                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        int          id       = reader.GetInt32(0);
                        string       nickname = reader.GetString(1);
                        string       Message  = reader.GetString(2);
                        DateTime     PostDate = reader.GetDateTime(3);
                        GuestBookDTO Data     = new GuestBookDTO(id, PostDate, Message, nickname);

                        return(Data);
                    }

                    conn.Close();
                    return(EmptyDTO);
                }
            }
        }
Example #2
0
 public void WriteInGuestBook(GuestBookDTO guestBook)
 {
     if (!String.IsNullOrEmpty(guestBook.NickName))
     {
         guestBookAccess.Create(guestBook);
         return;
     }
     throw new Exception("No nickname found");
 }
Example #3
0
        public void WriteInGuestBookNoNicknameTest()//if the user leaves the nickname field empty after clearing it
        {
            GuestBookAccess = new TGuestBookAccess();
            Interactions    = new UserInteractions(GuestBookAccess);
            GuestBookDTO GuestBook = new GuestBookDTO(1, DateTime.MinValue, "TestMessage", null);

            Interactions.WriteInGuestBook(GuestBook);
            GuestBookDTO latest = GuestBookAccess.GetLatestEntry();

            Assert.Fail();
        }
Example #4
0
        public void WriteInGuestBookSuccessTest()
        {
            GuestBookAccess = new TGuestBookAccess();
            Interactions    = new UserInteractions(GuestBookAccess);
            GuestBookDTO GuestBook = new GuestBookDTO(1, DateTime.MinValue, "TestMessage", "Jim");

            Interactions.WriteInGuestBook(GuestBook);
            GuestBookDTO latest = GuestBookAccess.GetLatestEntry();

            Assert.AreEqual(GuestBook.PostDate, latest.PostDate);
            Assert.AreEqual(GuestBook.Message, latest.Message);
            Assert.AreEqual(GuestBook.NickName, latest.NickName);
        }
Example #5
0
 public void Create(GuestBookDTO obj)
 {
     using (SqlConnection conn = new SqlConnection(DBConnection.CONNECTIONSTRING))
     {
         conn.Open();
         using (SqlCommand command = new SqlCommand("INSERT INTO[GuestBook](User_Nickname,Message,PostTime) " +
                                                    "VALUES(@User, @Message, @Date)", conn))
         {
             command.Parameters.AddWithValue("User", obj.NickName);
             command.Parameters.AddWithValue("Message", obj.Message);
             command.Parameters.AddWithValue("Date", obj.PostDate);
             command.ExecuteNonQuery();
         }
         conn.Close();
     }
 }
Example #6
0
 public void Update(GuestBookDTO Original, GuestBookDTO Replacement)
 {
     throw new NotImplementedException();
 }
Example #7
0
 public GuestBookDTO Get(GuestBookDTO obj)
 {
     throw new NotImplementedException();
 }
Example #8
0
 public void Create(GuestBookDTO obj)
 {
     obj.Id = test.GuestBookEntries.Count;
     test.GuestBookEntries.Add(obj);
 }