Beispiel #1
0
        public MarkDto AddMark(Mark mark)
        {
            var prof = _context.Profs.FirstOrDefault(x => x.Id == mark.ProfId);

            if (prof == null)
            {
                throw new Exception($"Prof {mark.Id} not found");
            }

            _context.Marks.Add(mark);
            var newId = _context.SaveChanges();

            return(new MarkDto(mark, _context.Profs.FirstOrDefault(p => p.Id == mark.ProfId)));
        }
Beispiel #2
0
        public Student CreateStudent(Student student)
        {
            var existingStudent = _context.Students.FirstOrDefault(x => x.Id == student.Id);

            if (existingStudent == null)
            {
                _context.Students.Add(student);
            }
            else
            {
                existingStudent.Name = student.Name;
                _context.Students.Update(existingStudent);
            }
            _context.SaveChanges();
            return(student);
        }
Beispiel #3
0
 public School CreateSchool(School school)
 {
     _context.Schools.Add(school);
     _context.SaveChanges();
     return(school);
 }