Example #1
0
        public Employee Get(int id)
        {
            SqlDataReader reader = null;

            dbConnection = DBConnect.getConnection();

            if (dbConnection.State.ToString() == "Closed")
            {
                dbConnection.Open();
            }
            SqlCommand sqlCmd = new SqlCommand();
            sqlCmd.CommandType = CommandType.Text;
            sqlCmd.CommandText = "Select * from tblEmployee where EmployeeId=" + id + "";
            sqlCmd.Connection = dbConnection;
            reader = sqlCmd.ExecuteReader();
            Employee emp = null;
            while (reader.Read())
            {
                emp = new Employee();
                emp.EmployeeId = Convert.ToInt32(reader.GetValue(0));
                emp.Name = reader.GetValue(1).ToString();
                emp.ManagerId = Convert.ToInt32(reader.GetValue(2));

            }

            dbConnection.Close();

            return emp;
        }
Example #2
0
 //Add Employee
 // Content-Type: application/json use this to send an object using fiddler
 //Format of the JSON Object {"EmployeeId":23,"Name":"Mac Miller","ManagerId":34}
 public String PostEmployee(Employee emp)
 {
     repository.PostEmployee(emp);
     return "Success";
 }
Example #3
0
        public void PostEmployee(Employee employee)
        {
            SqlDataReader reader = null;

            dbConnection = DBConnect.getConnection();

            if (dbConnection.State.ToString() == "Closed")
            {
                dbConnection.Open();
            }

            SqlCommand sqlCmd = new SqlCommand();
            sqlCmd.CommandType = CommandType.Text;
            sqlCmd.CommandText = "INSERT INTO tblEmployee (EmployeeId,Name,ManagerId) Values (@EmployeeId,@Name,@ManagerId)";
            sqlCmd.Connection = dbConnection;

            sqlCmd.Parameters.AddWithValue("@EmployeeId", employee.EmployeeId);
            sqlCmd.Parameters.AddWithValue("@Name", employee.Name);
            sqlCmd.Parameters.AddWithValue("@ManagerId", employee.ManagerId);

            int rowInserted = sqlCmd.ExecuteNonQuery();

            dbConnection.Close();
        }