Exemplo n.º 1
0
 public AcademicYear Create(AcademicYear itemToCreate)
 {
     var ayear = _context.AcademicYears.Add(itemToCreate);
     _context.Entry(ayear.Course).State = EntityState.Modified;
     _context.Entry(ayear.Grade).State = EntityState.Modified;
     _context.Entry(ayear.Teacher).State = EntityState.Modified;
     _context.SaveChanges();
     return ayear;
 }
Exemplo n.º 2
0
 public void Detach(AcademicYear academicYear)
 {
     _context.Entry(academicYear).State = EntityState.Detached;
 }
Exemplo n.º 3
0
        public AcademicYear Update(AcademicYear itemToUpdate)
        {
            var updateCourse = false;
            var updateGrade = false;
            var updateTeacher = false;

            var ayear = GetById(itemToUpdate.Id);
            ayear.Approved = itemToUpdate.Approved;
            ayear.IsActive = itemToUpdate.IsActive;
            ayear.Room = itemToUpdate.Room;
            ayear.Schedule = itemToUpdate.Schedule;
            ayear.Section = itemToUpdate.Section;
            ayear.StudentsLimit = itemToUpdate.StudentsLimit;
            ayear.TeacherEndDate = itemToUpdate.TeacherEndDate;
            ayear.TeacherStartDate = itemToUpdate.TeacherStartDate;
            ayear.Year = itemToUpdate.Year;
            ayear.StudentsCount = itemToUpdate.StudentsCount;

            if (ayear.Course.Id != itemToUpdate.Course.Id)
            {
                ayear.Course = itemToUpdate.Course;
                updateCourse = true;
            }

            if (ayear.Grade.Id != itemToUpdate.Grade.Id)
            {
                ayear.Course = itemToUpdate.Course;
                updateGrade = true;
            }

            if (ayear.Teacher.Id != itemToUpdate.Teacher.Id)
            {
                ayear.Teacher = itemToUpdate.Teacher;
                updateTeacher = true;
            }

            return Update(ayear, updateCourse, updateGrade, updateTeacher);
        }
Exemplo n.º 4
0
        public AcademicYear Update(AcademicYear itemToUpdate, bool updateCourse = true, bool updateGrade = true, 
            bool updateTeacher = true)
        {
            if (updateCourse)
                _context.Entry(itemToUpdate.Course).State = EntityState.Modified;

            if (updateGrade)
                _context.Entry(itemToUpdate.Grade).State = EntityState.Modified;

            if (updateTeacher)
                _context.Entry(itemToUpdate.Teacher).State = EntityState.Modified;

            _context.SaveChanges();
            return itemToUpdate;
        }