Exemplo n.º 1
0
        public List <Students> GetStudentsBySubject(string subjectId)
        {
            List <Students> studentsList = new List <Students>();

            try
            {
                string  query = String.Format("SELECT st.*  FROM [MediclassDB].[dbo].[Student_Subject] sb, [MediclassDB].[dbo].Students st where sb.StudentId = st.Id and sb.SubjectId = {0}", subjectId);
                DataSet ds    = _repository.Query(query);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        Students student = new Students
                        {
                            Id          = int.Parse(row[0] + string.Empty),
                            firstName   = row[1] + string.Empty,
                            lastName    = row[2] + string.Empty,
                            gender      = row[3] + string.Empty,
                            age         = int.Parse(row[4] + string.Empty),
                            phoneNumber = row[5] + string.Empty
                        };
                        studentsList.Add(student);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(studentsList);
        }