public User Update(User user) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("dbo.uspUpdateUser", connection)) { command.Connection = connection; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@pUserId", user.UserID)); command.Parameters.Add(new SqlParameter("@pLoginName", user.LoginName)); command.Parameters.Add(new SqlParameter("@pPassword", user.Password)); command.Parameters.Add(new SqlParameter("@pFirstName", user.FirstName)); command.Parameters.Add(new SqlParameter("@pLastName", user.LastName)); command.Parameters.Add(new SqlParameter("@pActiveUser", LoggedInDetails.GetUserLogged())); var rowsAffected = command.ExecuteNonQuery(); if (rowsAffected == 0) { throw new Exception("Sql Connection Error"); } return(user); } } }
public Student Insert(Student student) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("dbo.uspAddStudent", connection)) { command.Connection = connection; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@pFirstName", student.FirstName)); command.Parameters.Add(new SqlParameter("@pLastName", student.LastName)); command.Parameters.Add(new SqlParameter("@pEmail", student.Email)); command.Parameters.Add(new SqlParameter("@pPhone", student.Phone)); command.Parameters.Add(new SqlParameter("@pAddressLine1", student.AddressLine1)); command.Parameters.Add(new SqlParameter("@pAddressLine2", student.AddressLine2)); command.Parameters.Add(new SqlParameter("@pCity", student.City)); command.Parameters.Add(new SqlParameter("@pCounty", student.County)); command.Parameters.Add(new SqlParameter("@pCountry", student.Country)); command.Parameters.Add(new SqlParameter("@pLevel", student.Level)); command.Parameters.Add(new SqlParameter("@pCourse", student.Course)); command.Parameters.Add(new SqlParameter("@pStudentNumber", student.StudentNumber)); command.Parameters.Add(new SqlParameter("@pActiveUser", LoggedInDetails.GetUserLogged())); var rowsAffected = command.ExecuteNonQuery(); if (rowsAffected == 0) { throw new Exception("Sql Connection Error"); } return(student); } } }
public void Delete(int id) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("dbo.uspDeleteUser", connection)) { command.Connection = connection; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@pUserID", id)); command.Parameters.Add(new SqlParameter("@pLoginName", LoggedInDetails.GetUserLogged())); command.ExecuteNonQuery(); } } }
public void Delete(long studentNumber) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("dbo.uspDeleteStudent", connection)) { command.Connection = connection; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@pStudentNumber", studentNumber)); command.Parameters.Add(new SqlParameter("@pActiveUser", LoggedInDetails.GetUserLogged())); command.ExecuteNonQuery(); } } }
private void setTsUserName() { tsUserName.Text = LoggedInDetails.GetUserLogged(); }