/// <summary>
 /// Deprecated Method for adding a new object to the Employees EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToEmployees(Employe employe)
 {
     base.AddObject("Employees", employe);
 }
 private void AddEmploye()
 {
     using (UniversitySheduleContainer cnt = new UniversitySheduleContainer("name=UniversitySheduleContainer"))
     {
         Employe emp = new Employe();
         emp.Name = selectedemploye.Name;
         emp.DegreeId = selectedemploye.DegreeId;
         emp.FacultyId = selectedemploye.FacultyId;
         emp.TitleId = selectedemploye.TitleId;
         cnt.Employees.AddObject(emp);
         cnt.SaveChanges();
         var emplist = (from e in cnt.Employees select e);
         Employes = new ObservableCollection<Employe>(emplist);
     }
 }
 /// <summary>
 /// Create a new Employe object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="titleId">Initial value of the TitleId property.</param>
 /// <param name="facultyId">Initial value of the FacultyId property.</param>
 /// <param name="degreeId">Initial value of the DegreeId property.</param>
 public static Employe CreateEmploye(global::System.Int32 id, global::System.String name, global::System.Int32 titleId, global::System.Int32 facultyId, global::System.Int32 degreeId)
 {
     Employe employe = new Employe();
     employe.Id = id;
     employe.Name = name;
     employe.TitleId = titleId;
     employe.FacultyId = facultyId;
     employe.DegreeId = degreeId;
     return employe;
 }
        public void Import()
        {
            int lines_count = readedstrings.Where(x => x.Add).Count();
            int i = 0;
            using (UniversitySheduleContainer cnt = new UniversitySheduleContainer("name=UniversitySheduleContainer"))
            {
                int depId = ReadedStrings.First().KafedraId;
                //Department department = (from lt in cnt.Departments where lt.Id == depId select lt).First();
                foreach (var res in ReadedStrings.Where(x => x.Add))
                {
                    if (res.SubjectType == 0) continue;
                    //LessonsType lessontype = (from lt in cnt.LessonsTypes where lt.Id == res.SubjectType select lt).First();
                    RegulatoryAction regaction = new RegulatoryAction()
                    {
                        LessonsTypeId = res.SubjectType,
                        Hours = res.Time,
                        DepartmentId = depId,
                    };
                    cnt.RegulatoryActions.AddObject(regaction);

                    IEnumerable<Employe> teachers = (from e in cnt.Employees where e.Name == res.Name2 select e);
                    Employe teacher = null;
                    if (teachers.Count() == 0)
                    {
                        //нет такого преподавателя, добавим его
                        teacher = new Employe()
                        {
                            Name = res.Name2,
                            FacultyId = 1,
                            TitleId = 1,
                            DegreeId = 1,
                        };
                        cnt.Employees.AddObject(teacher);
                        //cnt.SaveChanges();
                    }
                    else teacher = teachers.First();

                    AcademicLoad academicload = new AcademicLoad()
                    {
                        RegulatoryAction = regaction,
                        Employe = teacher
                    };
                    cnt.AcademicLoadSet.AddObject(academicload);

                    ///
                    IEnumerable<Subject> subjects = (from e in cnt.Subjects where e.Name == res.Subject select e);
                    Subject subject = null;
                    if (subjects.Count() == 0)
                    {
                        //нет такого предмета, добавим его
                        subject = new Subject()
                        {
                            Name = res.Subject,
                            Abbreviation = "",
                        };
                        cnt.Subjects.AddObject(subject);
                        Console.WriteLine("subj not found = " + res.Subject);
                    }
                    else
                    {
                        subject = subjects.First();
                        Console.WriteLine("subj found = " + subject.Name);
                    }
                    ///

                    ///
                    string [] splitedGroups = res.Groups.Split(';');
                    foreach (var splitedGroup in splitedGroups)
                    {
                        string trimedGroup = splitedGroup.Trim();
                        Console.WriteLine(res.Groups + "       " + trimedGroup);
                        IEnumerable<Group> groups = (from e in cnt.Groups.Include("EduPeriod") where e.GroupAbbreviation == trimedGroup select e);
                        Group group = null;
                        if (groups.Count() == 0)
                        {
                            Console.WriteLine("group not found = " + trimedGroup);
                            continue;
                        }
                        else
                        {
                            group = groups.First();
                            Console.WriteLine("group found = " + trimedGroup);
                            if (group.EduPeriod.Count == 0)
                            {
                                EduPeriod e = new EduPeriod
                                {
                                    Begin = DateTime.Parse(res.Date.Substring(0, 10)),
                                    End = DateTime.Parse(res.Date.Substring(10, 10)),
                                    GroupId = group.Id,
                                };
                                cnt.EduPeriods.AddObject(e);
                            }
                        }
                        ///

                        Curriculum curr = new Curriculum()
                        {
                            RegulatoryAction = regaction,
                            Subject = subject,
                            Group = group,
                        };
                        cnt.Curriculums.AddObject(curr);
                        cnt.SaveChanges();
                    }
                    ++i;
                    Message = "Выполняется импорт нагрузки. Добавлено " + i + " из " + lines_count;
                    DoEvents();
                }
                //cnt.SaveChanges();
            }
        }