Ejemplo n.º 1
0
        public async Task <Result <TeacherData> > FindById(int teacherId)
        {
            using (SqlConnection con = new SqlConnection(_connectionString))
            {
                TeacherData teacher = await con.QueryFirstOrDefaultAsync <TeacherData>(
                    @"select t.TeacherId, t.FirstName, t.LastName, t.isPresent from iti.vTeacher t where t.TeacherId = @TeacherId;",
                    new { TeacherId = teacherId });

                if (teacher == null)
                {
                    return(Result.Failure <TeacherData>(Status.NotFound, "Teacher not found."));
                }
                return(Result.Success(teacher));
            }
        }
Ejemplo n.º 2
0
        public async Task <Result <TeacherData> > GetAssignedTeacher(int classId)
        {
            using (SqlConnection con = new SqlConnection(_connectionString))
            {
                TeacherData assignedTeacherData = await con.QueryFirstOrDefaultAsync <TeacherData>(
                    @"select c.TeacherId, 
                             c.TeacherFirstName as FirstName, 
                             c.TeacherLastName as LastName, 
                             c.TeacherPresence as Presence
                        from iti.vClass c where c.ClassId = @ClassId;",
                    new { ClassId = classId });

                if (assignedTeacherData == null)
                {
                    return(Result.Failure <TeacherData>(Status.BadRequest, "Teacher not found."));
                }

                return(Result.Success(assignedTeacherData));
            }
        }