Пример #1
0
 public void DeleteUser()
 {
     var userRepository = new UsersRepository();
     var userDelete = new User
     {
         Id = 7
     };
     userRepository.Delete(userDelete);
 }
Пример #2
0
 public void ShouldCreateUser()
 {
     //arrange
     var userRepository = new UsersRepository();
     var user = new User
     {
         Email = "*****@*****.**",
         FullName = "test",
         Twitter = "test.tw",
         Facebook = "test.fb"
     };
     //act
     userRepository.Create(user);
     //asserts
     //var resultUser = userRepository.Get(user.Id);
     //Assert.AreEqual(user.Email, resultUser.Email);
 }
Пример #3
0
 public void Create(User user)
 {
     if (user == null)
         throw new ArgumentNullException("user");
        using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         using (var command = connection.CreateCommand())
         {
             command.CommandText = "INSERT INTO [dbo].[users] (fullname, email, twitter, facebook) VALUES (@fullname, @email, @twitter, @facebook)";
             command.Parameters.AddWithValue("@fullname", user.FullName);
             command.Parameters.AddWithValue("@email", user.Email);
             command.Parameters.AddWithValue("@twitter", user.Twitter);
             command.Parameters.AddWithValue("@facebook", user.Facebook);
             command.ExecuteNonQuery();
         }
     }
 }
Пример #4
0
 public void Update(int id, User user)
 {
     using (var connection = new SqlConnection(_connectionString))
         {
             connection.Open();
             using (var command = connection.CreateCommand())
             {
                 //нужно поправить, проблемы с null
                 command.CommandText = "UPDATE [dbo].[users] SET fullname=@fullname WHERE id = @id";
                 command.Parameters.AddWithValue("@id", id);
                 command.Parameters.AddWithValue("@fullname", user.FullName);
                // command.Parameters.AddWithValue("@email", user.Email);
                // command.Parameters.AddWithValue("@twitter",user.Twitter);
               //  command.Parameters.AddWithValue("@facebook", user.Facebook);
                 command.ExecuteNonQuery();
             }
         }
 }