Example #1
0
 public void RegisterStudent(Student student)
 {
     using (var ctx = new ArgonDbContext(_connectionStringWrapper))
     {
         ctx.Students.Add(student);
         ctx.SaveChanges();
     }
 }
Example #2
0
 public void UnregisterStudent(int id)
 {
     using (var ctx = new ArgonDbContext(_connectionStringWrapper))
     {
         var student = GetStudent(id);
         if (student == null)
         {
             throw new ArgumentException($"Student {id} does not exist.");
         }
         ctx.Students.Remove(student);
         ctx.SaveChanges();
     }
 }
Example #3
0
 public void Update(int id, Student student)
 {
     using (var ctx = new ArgonDbContext(_connectionStringWrapper))
     {
         var entity = ctx.Students.FirstOrDefault(q => q.Id == id);
         if (entity == null)
         {
             throw new ArgumentException($"Student {id} does not exist.");
         }
         entity.Name    = student.Name;
         entity.Surname = student.Surname;
         ctx.Students.Update(entity);
         ctx.SaveChanges();
     }
 }