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) }); }
public async Task updateStudent(int id, Models.Student update) { Models.Db.Group dbGroup = await this.getDbGroup(name : update.group.name); if (dbGroup == null) { throw new System.ArgumentException("invalid group"); } this.Database.ExecuteSqlCommand( "update student set name={0}, state={1}, group_id={2} where id={3}", update.name, update.state, dbGroup.id, id); }
public async Task insertStudent(Models.Student student) { Models.Db.Group dbGroup = await this.getDbGroup(name : student.group.name); if (dbGroup == null) { throw new System.ArgumentException("invalid group"); } this.Database.ExecuteSqlCommand( "insert into student (name, state, group_id) values ({0}, {1}, {2})", student.name, student.state, dbGroup.id); }
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); }