public List <Incident> GetIncidentsByTechnician(int techID) { List <Incident> lstIncidentsByTechnician = new List <Incident>(); DataTable dtIncidentsByTechnician = new DataTable(); IncidentDAL incDal = new IncidentDAL(); dtIncidentsByTechnician = incDal.RetrieveIncidentsByTechnician(techID); foreach (DataRow dr in dtIncidentsByTechnician.Rows) { Incident anIncident = new Incident(); anIncident.IncidentID = (int)dr["IncidentID"]; anIncident.CustomerID = (int)dr["CustomerID"]; anIncident.ProductCode = (string)dr["ProductCode"]; anIncident.TechID = dr["TechID"] == DBNull.Value ? (int?)null : Convert.ToInt32(dr["TechID"]); anIncident.DateOpened = (DateTime)dr["DateOpened"]; anIncident.DateClosed = dr["DateClosed"] == DBNull.Value ? (DateTime?)null : Convert.ToDateTime(dr["DateClosed"]); anIncident.Title = dr["Title"].ToString(); anIncident.Description = dr["Description"].ToString(); lstIncidentsByTechnician.Add(anIncident); } return(lstIncidentsByTechnician); }
public List <Incident> GetIncidentsByTechnician(int techID) { List <Incident> lstIncidentsByTech = new List <Incident>(); DataTable dtIncidentsByTech = new DataTable(); IncidentDAL incidentDAL = new IncidentDAL(); dtIncidentsByTech = incidentDAL.RetrieveIncidentsByTechnician(techID); foreach (DataRow dr in dtIncidentsByTech.Rows) { Incident incidentA = new Incident(); incidentA.IncidentID = (int)dr["IncidentID"]; incidentA.CustomerID = (int)dr["CustomerID"]; incidentA.ProductCode = dr["ProductCode"].ToString(); //Need to account for if the TechID value returns a null value. if (dr["TechID"] == DBNull.Value) { incidentA.TechID = null; } else { incidentA.TechID = (int?)dr["TechID"]; } incidentA.DateOpened = (DateTime)dr["DateOpened"]; if (dr["DateClosed"] == DBNull.Value) { incidentA.DateClosed = null; } else { incidentA.DateClosed = (DateTime?)dr["DateClosed"]; } incidentA.Title = dr["Title"].ToString(); incidentA.Description = dr["Description"].ToString(); lstIncidentsByTech.Add(incidentA); } return(lstIncidentsByTech); }