Ejemplo n.º 1
0
 /// <summary>
 /// Returns a student whose id matches the given id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Students GetStudent(int id)
 {
     using (var db = new BlazorDbContext(_dbContextOptions))
     {
         return(db.Students.Where(a => a.Id == id).FirstOrDefault());
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// returns a list of students
 /// </summary>
 /// <returns></returns>
 public List <Students> ReloadAllStudents()
 {
     using (var db = new BlazorDbContext(_dbContextOptions))
     {
         return(db.Students.ToList());
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// returns a list of students
 /// </summary>
 /// <returns></returns>
 public async Task <List <Students> > GetAllStudentsAsync()
 {
     using (var db = new BlazorDbContext(_dbContextOptions))
     {
         return(await db.Students.ToListAsync());
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new Student Entity
 /// </summary>
 /// <param name="student"></param>
 public void CreateStudent(Students student)
 {
     using (var db = new BlazorDbContext(_dbContextOptions))
     {
         db.Students.Add(student);
         db.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Deletes a student by Id
 /// </summary>
 /// <param name="id"></param>
 public void RemoveStudent(int id)
 {
     using (var db = new BlazorDbContext(_dbContextOptions))
     {
         var student = db.Students.Where(a => a.Id == id).FirstOrDefault();
         db.Remove(student);
         db.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Updates a selected student
 /// </summary>
 /// <param name="student"></param>
 public void UpdateStudent(Students student)
 {
     using (var db = new BlazorDbContext(_dbContextOptions))
     {
         var dbStudent = db.Students.Where(a => a.Id == student.Id).FirstOrDefault();
         dbStudent.FirstName   = student.FirstName;
         dbStudent.LastName    = student.LastName;
         dbStudent.Gender      = student.Gender;
         dbStudent.DateOfBirth = student.DateOfBirth;
         db.SaveChanges();
     }
 }