public void Delete(int id) { _db = new StudentDbEntities(); Student student = _db.Students.First(p => p.Id == id); _db.Students.Remove(student); _db.SaveChanges(); }
public void Delete(int id) { _db = new StudentDbEntities(); Class c = _db.Classes.First(p => p.Id == id); _db.Classes.Remove(c); _db.SaveChanges(); }
public void Update(ClassDTO classDto) { _db = new StudentDbEntities(); Class c = _db.Classes.First(p => p.Id == classDto.Id); c.Name = classDto.Name; c.Code = classDto.Code; _db.SaveChanges(); }
public void Save(ClassDTO classDto) { _db = new StudentDbEntities(); Class c = new Class(); c.Id = GetMaxId(); c.Name = classDto.Name; c.Code = classDto.Code; _db.Classes.Add(c); _db.SaveChanges(); }
public void Save(StudentDTO studentDto) { _db = new StudentDbEntities(); var student = new Student {Id = GetMaxId()}; student.Name = studentDto.Name; student.ClassId = studentDto.ClassId; student.Mark1 = (decimal?) studentDto.Mark1; student.Mark2 = (decimal?) studentDto.Mark2; student.Mark3 = (decimal?) studentDto.Mark3; _db.Students.Add(student); _db.SaveChanges(); }
public void Update(StudentDTO studentDto) { _db = new StudentDbEntities(); Student student = _db.Students.First(p => p.Id == studentDto.Id); studentDto.Name = student.Name; studentDto.ClassId = student.ClassId; if (student.Mark1 != null) studentDto.Mark1 = (double) student.Mark1; if (student.Mark2 != null) studentDto.Mark2 = (double) student.Mark2; if (student.Mark3 != null) studentDto.Mark3 = (double) student.Mark3; _db.SaveChanges(); }