Esempio n. 1
0
        public async Task <List <Models.Group> > getGroups(int facultyId,
                                                           int count  = -1,
                                                           int offset = -1)
        {
            Models.Db.Faculty dbFaculty = await this.getDbFaculty(id : facultyId);

            List <Models.Db.Group> dbGroups = null;

            if (count == -1)
            {
                dbGroups = await this.student_group.FromSqlRaw(
                    $"select * from student_group where faculty_id={facultyId} order by name asc")
                           .ToListAsync();
            }
            else
            {
                dbGroups = await this.student_group.FromSqlRaw(
                    $"select * from student_group where faculty_id={facultyId} order by name asc limit {count} offset {offset}")
                           .ToListAsync();
            }

            List <Models.Group> groups = new List <Models.Group>();

            foreach (Models.Db.Group group in dbGroups)
            {
                groups.Add(this.converter.fromDbModel(group, dbFaculty));
            }

            return(groups);
        }
 public Models.Faculty fromDbModel(Models.Db.Faculty faculty)
 {
     return(new Models.Faculty()
     {
         id = faculty.id,
         name = faculty.name,
         briefName = faculty.brief_name
     });
 }
 public Models.Teacher fromDbModel(Models.Db.Teacher teacher,
                                   Models.Db.Faculty faculty)
 {
     return(new Models.Teacher()
     {
         id = teacher.id,
         name = teacher.name,
         faculty = this.fromDbModel(faculty)
     });
 }
 public Models.Student fromDbModel(Models.Db.Student student,
                                   Models.Db.Group group,
                                   Models.Db.Faculty faculty)
 {
     return(new Models.Student()
     {
         id = student.id,
         name = student.name,
         group = this.fromDbModel(group, faculty),
         state = student.state
     });
 }
 public Models.Group fromDbModel(Models.Db.Group group,
                                 Models.Db.Faculty faculty)
 {
     return(new Models.Group()
     {
         id = group.id,
         name = group.name,
         year = group.year,
         type = group.type,
         faculty = this.fromDbModel(faculty)
     });
 }
Esempio n. 6
0
        public async Task updateTeacher(int id, Models.Teacher update)
        {
            Models.Db.Faculty dbFaculty = await this.getDbFaculty(briefName : update.faculty.briefName);

            if (dbFaculty == null)
            {
                throw new System.ArgumentException("invalid faculty");
            }

            this.Database.ExecuteSqlCommand(
                "update teacher set name={0}, faculty_id={1} where id={2}",
                update.name, dbFaculty.id, id);
        }
Esempio n. 7
0
        public async Task updateGroup(int id, Models.Group update)
        {
            Models.Db.Faculty dbFaculty = await this.getDbFaculty(briefName : update.faculty.briefName);

            if (dbFaculty == null)
            {
                throw new System.ArgumentException("invalid faculty");
            }

            this.Database.ExecuteSqlCommand(
                "update student_group set name={0}, faculty_id={1}, year={2}, type={3} where id={4}",
                update.name, dbFaculty.id, update.year, update.type, id);
        }
Esempio n. 8
0
        public async Task insertTeacher(Models.Teacher teacher)
        {
            Models.Db.Faculty dbFaculty = await this.getDbFaculty(briefName : teacher.faculty.briefName);

            if (dbFaculty == null)
            {
                throw new System.ArgumentException("invalid faculty");
            }

            this.Database.ExecuteSqlCommand(
                "insert into teacher (name, faculty_id) values ({0}, {1})",
                teacher.name, dbFaculty.id);
        }
Esempio n. 9
0
        public async Task insertGroup(Models.Group group)
        {
            Models.Db.Faculty dbFaculty = await this.getDbFaculty(briefName : group.faculty.briefName);

            if (dbFaculty == null)
            {
                throw new System.ArgumentException("invalid faculty");
            }

            this.Database.ExecuteSqlCommand(
                "insert into student_group (name, year, type, faculty_id) values ({0}, {1}, {2}, {3})",
                group.name, group.year, group.type, group.faculty.id);
        }
Esempio n. 10
0
        public async Task <List <Models.Teacher> > getTeachers(int facultyId,
                                                               int count,
                                                               int offset)
        {
            Models.Db.Faculty dbFaculty = await this.getDbFaculty(id : facultyId);

            List <Models.Db.Teacher> dbTeachers = await this.teacher.FromSqlRaw(
                $"select * from teacher where faculty_id={facultyId} order by name asc limit {count} offset {offset}")
                                                  .ToListAsync();

            List <Models.Teacher> teachers = new List <Models.Teacher>();

            foreach (Models.Db.Teacher teacher in dbTeachers)
            {
                teachers.Add(this.converter.fromDbModel(teacher, dbFaculty));
            }

            return(teachers);
        }
Esempio n. 11
0
        public async Task <List <Models.Student> > getStudents(int groupId,
                                                               int count,
                                                               int offset)
        {
            Models.Db.Group dbGroup = await this.getDbGroup(id : groupId);

            Models.Db.Faculty dbFaculty = await this.getDbFaculty(id : dbGroup.faculty_id);

            List <Models.Db.Student> dbStudents = await this.student.FromSqlRaw(
                $"select * from student where group_id={groupId} order by name asc limit {count} offset {offset}")
                                                  .ToListAsync();

            List <Models.Student> students = new List <Models.Student>();

            foreach (Models.Db.Student student in dbStudents)
            {
                students.Add(this.converter.fromDbModel(student, dbGroup, dbFaculty));
            }

            return(students);
        }