Example #1
0
 public void EditEmployee(Employee employee)
 {
     using (SqlConnection conn = new SqlConnection(DBHelper.GetConnection()))
     {
         SqlCommand cmd = new SqlCommand();
         cmd.Connection = conn;
         cmd.CommandText = @"update Employee
                             set Name = @Name,
                             Password = @Password,
                             PhoneNumber = @PhoneNumber
                             where EmployeeId = @EmployeeId";
         cmd.Parameters.AddWithValue("@Name",employee.Name);
         cmd.Parameters.AddWithValue("@Password",employee.Password);
         cmd.Parameters.AddWithValue("@PhoneNumber",employee.PhoneNumber);
         cmd.Parameters.AddWithValue("@EmployeeId",employee.EmployeeId);
         try
         {
             conn.Open();
             cmd.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally {
             cmd.Dispose();
             conn.Close();
         }
     }
 }
Example #2
0
 public Employee GetEmployeeById(string employeeId)
 {
     Employee emp = new Employee();
     using (SqlConnection conn = new SqlConnection(DBHelper.GetConnection()))
     {
         SqlCommand cmd = new SqlCommand();
         cmd.Connection = conn;
         cmd.CommandText = @"Select EmployeeId,Name,Password,
                             Department,PhoneNumber,RoleId,IsActive
                             from Employee
                             where EmployeeId = @employeeId";
         cmd.Parameters.AddWithValue("@employeeId", employeeId);
         try
         {
             conn.Open();
             SqlDataReader reader = cmd.ExecuteReader();
             while (reader.Read())
             {
                 emp.EmployeeId = employeeId;
                 emp.Name = reader.GetString(1);
                 emp.Password = reader.GetString(2);
                 emp.Department = reader.GetString(3);
                 emp.PhoneNumber = reader.GetString(4);
                 emp.Roles = GetRolesById(reader.GetInt32(5));
                 emp.IsActive = reader.GetBoolean(6);
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             conn.Close();
             cmd.Dispose();
         }
         return emp;
     }
 }
 public void EditEmployee(Employee employee)
 {
     editEmployeeDao.EditEmployee(employee);
 }