public List <Incident> GetOpenIncidentsByTechnician(int techID) { List <Incident> lstOpenIncidentsByTechnician = new List <Incident>(); DataTable dtOpenIncidentsByTechnician = new DataTable(); IncidentDAL incDal = new IncidentDAL(); dtOpenIncidentsByTechnician = incDal.RetrieveOpenIncidentsByTechnician(techID); //DataRow dr; (cant declare this up here for some reason foreach (DataRow dr in dtOpenIncidentsByTechnician.Rows)//this statement needs the "DataRow" before dr { 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(); lstOpenIncidentsByTechnician.Add(anIncident); } return(lstOpenIncidentsByTechnician); }
public List <Incident> GetOpenIncidentsByTechnican(int techID) { List <Incident> lstOpenIncidentsByTech = new List <Incident>(); DataTable dtOpenIncidentsByTech = new DataTable(); IncidentDAL incidentDAL = new IncidentDAL(); dtOpenIncidentsByTech = incidentDAL.RetrieveOpenIncidentsByTechnician(techID); foreach (DataRow dr in dtOpenIncidentsByTech.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(); lstOpenIncidentsByTech.Add(incidentA); } return(lstOpenIncidentsByTech); }