/// <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(); } }
/// <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(); } }
/// <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(); } }