Exemplo n.º 1
0
        public IEnumerable <EmpModel> GetAllEmp()
        {
            List <EmpModel> lstemp = new List <EmpModel>();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("showemp", con);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    EmpModel em = new EmpModel();
                    em.empid         = Convert.ToInt32(rdr[0]);
                    em.empname       = rdr[1].ToString();
                    em.empemail      = rdr[2].ToString();
                    em.emphomeadd    = rdr[3].ToString();
                    em.empdep        = rdr[4].ToString();
                    em.empphone      = string.IsNullOrEmpty(rdr[5].ToString()) ? (int?)null : Convert.ToInt32(rdr[5]);
                    em.emprepmanager = rdr[6].ToString();
                    em.empofficeadd  = rdr[7].ToString();
                    em.IsDeleted     = (rdr[8]).ToString();
                    em.IsActive      = (rdr[9]).ToString();
                    em.addedby       = rdr[10].ToString();
                    em.addedon       = Convert.ToDateTime(rdr[11]);
                    em.modifiedby    = rdr[12].ToString();
                    em.modifiedon    = Convert.ToDateTime(rdr[13]);


                    lstemp.Add(em);
                }
                con.Close();
            }
            return(lstemp);
        }