Example #1
0
        public void Add(Schedule schedule)
        {
            SetRelativeEntities(schedule);

            db.Groups.Attach(schedule.Group);
            db.Courses.Attach(schedule.Course);

            db.Schedules.Add(schedule);
            db.SaveChanges();
        }
Example #2
0
        public void Edit(Schedule schedule)
        {
            var editingSchedule = db.Schedules.Find(schedule.id);

            SetRelativeEntities(editingSchedule, schedule);
            editingSchedule.day = schedule.day;

            db.Schedules.AddOrUpdate(editingSchedule);

            db.SaveChanges();
        }
Example #3
0
        private void SetRelativeEntities(Schedule schedule)
        {
            var group = db.Groups.Find(schedule.Group.id);
            schedule.Group = group;

            var course = db.Courses.Find(schedule.Course.id);
            schedule.Course = course;
        }
Example #4
0
        private void SetRelativeEntities(Schedule oldSchedule, Schedule newSchedule)
        {
            var group = db.Groups.Find(newSchedule.Group.id);
            oldSchedule.Group = group;

            var course = db.Courses.Find(newSchedule.Course.id);
            oldSchedule.Course = course;
        }