예제 #1
0
 public void InsertOrUpdate(Teacher teacher)
 {
     if (teacher.Id == default(int)) {
         // New entity
         this.Context.Teachers.Add(teacher);
     } else {
         // Existing entity
         this.Context.Entry(teacher).State = EntityState.Modified;
     }
 }
        public void RegisterTeacher(Teacher teacher)
        {
            // Prepare repository.
            var repo = App.DefaultInjectionService.Get<ITeacherRepository>();

            // Connect with work types.
            teacher.TeacherWorkTypes = new Collection<Teacher_TeacherWorkType>()
            {
                new Teacher_TeacherWorkType() { TeacherWorkTypeId = 1 },
                new Teacher_TeacherWorkType() { TeacherWorkTypeId = 2 },
                new Teacher_TeacherWorkType() { TeacherWorkTypeId = 3 },
                new Teacher_TeacherWorkType() { TeacherWorkTypeId = 4 }
            };
            teacher.Calendars = new Collection<Calendar>()
            {
                new Calendar() { Id = 1 , Title = "Календар за замовчуванням", CreateDateTime = DateTime.Now, LastActivityDateTime = DateTime.Now}
            };

            // Add into database.
            repo.InsertOrUpdate(teacher);
            repo.SaveAllChanges();
            repo.Dispose();
        }