// Get Audit by employee Id public EmployeeAuditModel GetEmployeeAuditByEmpId(int id) { // Declare list to work with EmployeeAuditModel employeeAudit = new EmployeeAuditModel(); // Establish database connection SqlConnection con = new SqlConnection(connectionString); con.Open(); // sql command get EmployeeAudit by provided id SqlCommand cmd = new SqlCommand("select * from EmployeeAudit where EmployeeId = @id and IsActive = @activeAudit", con); cmd.Parameters.AddWithValue("@id", id); cmd.Parameters.AddWithValue("@activeAudit", true); // This read database command SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read() == true) { employeeAudit.EmployeeAuditId = reader.GetInt32(0); employeeAudit.EmployeeId = reader.GetInt32(1); employeeAudit.TeamLeadId = reader.GetInt32(2); employeeAudit.ManagerId = reader.GetInt32(3); employeeAudit.AuditDate = reader.GetDateTime(4); employeeAudit.IsActive = reader.GetBoolean(5); } // Close current connection to the database con.Close(); return(employeeAudit); }
protected void Page_Load(object sender, EventArgs e) { // if no active session exist, insist user to login if (Session["Name"] == null) { Response.Redirect("~/Login"); } if (!IsPostBack) { List <OccupationModel> occupationModels = occupation.GetAllOccupations(); List <TeamModel> teamModels = team.GetAllTeams(); List <EmployeeModel> employeeModels = employee.GetAllEmployees(); int id = Convert.ToInt32(Request.QueryString["Id"].ToString()); EmployeeModel emp = employee.GetEmployeeById(id); lblName.InnerText = emp.Name; lblSurname.InnerText = emp.Surname; // get occupation foreach (var occ in occupationModels) { if (occ.OccupationId == emp.OccupationId) { lblOccupation.InnerText = occ.Description; break; } } // Get employee team description foreach (var t in teamModels) { if (t.TeamId == emp.TeamId) { lblTeam.InnerText = t.Description; break; } } EmployeeAuditModel employeeAuditModels = employeeAudit.GetEmployeeAuditByEmpId(emp.EmployeeId); List <EmployeeModel> tl = employee.GetTeamLeads(emp.TeamId); } }
// Get list of Employee Audits public List <EmployeeAuditModel> GetAllEmployeeAudit() { // Declare list to work with List <EmployeeAuditModel> employeeAuditList = new List <EmployeeAuditModel>(); // Establish database connection SqlConnection con = new SqlConnection(connectionString); con.Open(); // sql command for employeeAudit SqlCommand cmd = new SqlCommand("select * from EmployeeAudit", con); // This read database command SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { // create new employeeAudit instance EmployeeAuditModel employeeAudits = new EmployeeAuditModel { EmployeeAuditId = reader.GetInt32(0), EmployeeId = reader.GetInt32(1), TeamLeadId = reader.GetInt32(2), ManagerId = reader.GetInt32(3), AuditDate = reader.GetDateTime(4), IsActive = reader.GetBoolean(5) }; // add all EmployeeAudits to the list employeeAuditList.Add(employeeAudits); } // Close current connection to the database con.Close(); return(employeeAuditList); }