Esempio n. 1
0
        public async Task CreateGroup(params CurriculumGroupModel[] groupModels)
        {
            foreach (var groupModel in groupModels)
            {
                var academicYearId = await _blockRepository.GetAcademicYearId(groupModel.BlockId);

                if (academicYearId == null)
                {
                    throw new NotFoundException("Academic year not found for block.");
                }

                if (!await _groupRepository.CheckUniqueCode(academicYearId.Value, groupModel.Code))
                {
                    throw new InvalidDataException($"Curriculum group with code {groupModel.Code} already exists.");
                }

                var group = new CurriculumGroup
                {
                    Code        = groupModel.Code,
                    Description = groupModel.Description,
                    BlockId     = groupModel.BlockId
                };

                _groupRepository.Create(group);
            }

            await _groupRepository.SaveChanges();
        }
Esempio n. 2
0
        private void createCurricula(string shortName, string name)
        {
            var orgs = Db.Organisers.Where(x => x.ShortName.StartsWith("FK")).ToList();

            foreach (var org in orgs)
            {
                var cieB = org.Curricula.SingleOrDefault(x => x.ShortName.Equals(shortName));

                if (cieB == null)
                {
                    cieB = new Curriculum
                    {
                        Name      = name,
                        ShortName = shortName,
                        Organiser = org
                    };

                    Db.Curricula.Add(cieB);
                }

                var firstGroup = cieB.CurriculumGroups.FirstOrDefault();
                if (firstGroup != null)
                {
                    firstGroup.Name = string.Empty;
                }
                else
                {
                    firstGroup = new CurriculumGroup
                    {
                        Curriculum     = cieB,
                        Name           = string.Empty,
                        IsSubscribable = true
                    };

                    Db.CurriculumGroups.Add(firstGroup);
                }

                var firstCapGroup = firstGroup.CapacityGroups.FirstOrDefault();

                if (firstCapGroup == null)
                {
                    firstCapGroup = new  CapacityGroup
                    {
                        CurriculumGroup = firstGroup,
                        Name            = string.Empty,
                        InSS            = true,
                        InWS            = true
                    };

                    Db.CapacityGroups.Add(firstCapGroup);
                }
            }



            Db.SaveChanges();
        }
Esempio n. 3
0
 public static string GetDisplayName(this CurriculumGroup value)
 {
     System.Reflection.FieldInfo fieldInfo             = value.GetType().GetField(value.ToString());
     DisplayAttribute[]          descriptionAttributes = fieldInfo.GetCustomAttributes(typeof(DisplayAttribute), false) as DisplayAttribute[];
     if (descriptionAttributes == null)
     {
         return(string.Empty);
     }
     return((descriptionAttributes.Length > 0) ? descriptionAttributes[0].Name : value.ToString());
 }
        public CurriculumGroup AddCurriculumGroup(string shortName, string groupName, string aliasName, string semesterGroup)
        {
            var cur   = GetCurriculum(shortName);
            var group = cur.CurriculumGroups.SingleOrDefault(g => g.Name.Equals(groupName));

            if (group == null)
            {
                group = new CurriculumGroup
                {
                    Name       = groupName,
                    Curriculum = cur
                };

                _db.CurriculumGroups.Add(group);
                _db.SaveChanges();
            }

            /*
             * var alias = cur.GroupAliases.SingleOrDefault(a => a.Name.Equals(aliasName));
             *
             * if (alias == null)
             * {
             *  alias = new GroupAlias
             *  {
             *      Curriculum = cur,
             *      Name = aliasName
             *  };
             *
             *  _db.GroupAliases.Add(alias);
             *  _db.SaveChanges();
             * }
             *
             *
             * var template = alias.GroupTemplates.SingleOrDefault(t => t.CurriculumGroupName.Equals(groupName));
             * if (template == null)
             * {
             *  template = new GroupTemplate
             *  {
             *      Alias = alias,
             *      CurriculumGroupName = groupName,
             *      SemesterGroupName = semesterGroup
             *  };
             *
             *  _db.GroupTemplates.Add(template);
             *  _db.SaveChanges();
             * }
             */
            return(group);
        }
Esempio n. 5
0
        private void LoadFromModel(CurriculumGroup model)
        {
            BlockId        = model.BlockId;
            StudentGroupId = model.StudentGroupId;

            if (model.Block != null)
            {
                Block = new CurriculumBlockModel(model.Block);
            }

            if (model.StudentGroup != null)
            {
                StudentGroup = new StudentGroupModel(model.StudentGroup);
            }
        }
Esempio n. 6
0
        public ActionResult CreateGroup(CurriculumGroupCreateModel model)
        {
            var curriculum = Db.Curricula.SingleOrDefault(c => c.Id == model.Curriculum.Id);

            var group = new CurriculumGroup
            {
                Curriculum     = curriculum,
                IsSubscribable = model.IsSubscribable,
                Name           = model.Name
            };

            Db.CurriculumGroups.Add(group);

            if (model.CapacityGroupCount > 1)
            {
                for (int i = 1; i <= model.CapacityGroupCount; i++)
                {
                    Char c = (Char)((65) + (i - 1));

                    var capGroup = new CapacityGroup
                    {
                        CurriculumGroup = group,
                        InSS            = true,
                        InWS            = true,
                        Name            = c.ToString()
                    };

                    group.CapacityGroups.Add(capGroup);
                }
            }
            else
            {
                var capGroup = new CapacityGroup
                {
                    CurriculumGroup = group,
                    InSS            = true,
                    InWS            = true
                };

                group.CapacityGroups.Add(capGroup);
            }


            Db.SaveChanges();

            return(RedirectToAction("Structure", "Curriculum", new { id = model.Curriculum.Id }));
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="db"></param>
        /// <param name="gruppenId">Gruppenalias nach dem in der Datenbank gesucht wird</param>
        /// <returns></returns>
        private List <SemesterGroup> InitSemesterGroups(TimeTableDbContext db, string gruppenId)
        {
            var semester = db.Semesters.SingleOrDefault(s => s.Id == _semId);
            var org      = db.Organisers.SingleOrDefault(x => x.Id == _orgId);

            // Annahme, die Semestergruppen existieren!
            var semGroupList = new List <SemesterGroup>();

            // suche alle aktuellen Zuordnungen zu dieser gruppenID
            var zuordnungen = _import.GruppenZuordnungen.Where(x => x.Alias.Equals(gruppenId));

            foreach (var zuordnung in zuordnungen)
            {
                // Studiengang finden
                var curr = db.Curricula.SingleOrDefault(x =>
                                                        x.ShortName.Equals(zuordnung.Studiengang) &&
                                                        x.Organiser.Id == org.Id);
                if (curr == null)
                {
                    curr = new TimeTable.Data.Curriculum
                    {
                        Organiser = org,
                        ShortName = zuordnung.Studiengang,
                        Name      = zuordnung.Studiengang
                    };
                    db.Curricula.Add(curr);
                }

                var sg = curr.CurriculumGroups.SingleOrDefault(x => x.Name.Equals(zuordnung.Studiengruppe));
                if (sg == null)
                {
                    sg = new CurriculumGroup
                    {
                        Name           = zuordnung.Studiengruppe,
                        IsSubscribable = true,
                        Curriculum     = curr
                    };
                    db.CurriculumGroups.Add(sg);
                    curr.CurriculumGroups.Add(sg);
                }

                var cg = string.IsNullOrEmpty(zuordnung.Kapazitätsgruppe) ?
                         sg.CapacityGroups.SingleOrDefault(x => string.IsNullOrEmpty(x.Name)) :
                         sg.CapacityGroups.SingleOrDefault(x => x.Name.Equals(zuordnung.Kapazitätsgruppe));
                if (cg == null)
                {
                    cg = new CapacityGroup
                    {
                        InSS            = true,
                        InWS            = true,
                        Name            = zuordnung.Kapazitätsgruppe,
                        CurriculumGroup = sg
                    };
                    db.CapacityGroups.Add(cg);
                    sg.CapacityGroups.Add(cg);
                }

                // bis hierher habe ich ohne Semesterbezug gearbeitet
                // jetzt noch die Semestergruppe

                var semGroup = cg.SemesterGroups.SingleOrDefault(x => x.Semester.Id == semester.Id);
                if (semGroup == null)
                {
                    // semestergruppe gibt es nicht => auf jeden Fall anlegen
                    semGroup = new SemesterGroup
                    {
                        CapacityGroup = cg,
                        Semester      = semester,
                    };

                    _Logger.InfoFormat("Semestergruppe {0} angelegt {1}", semGroup.FullName, gruppenId);

                    cg.SemesterGroups.Add(semGroup);
                    db.SemesterGroups.Add(semGroup);
                }

                semGroupList.Add(semGroup);
            }

            db.SaveChanges();


            return(semGroupList);
        }
Esempio n. 8
0
        public ActionResult ImportData(HttpPostedFileBase importFile)
        {
            if (importFile != null)
            {
                var bytes = new byte[importFile.ContentLength];
                importFile.InputStream.Read(bytes, 0, importFile.ContentLength);

                var stream = new System.IO.MemoryStream(bytes);
                var reader = new System.IO.StreamReader(stream, Encoding.Default);
                var text   = reader.ReadToEnd();

                string[] lines = text.Split('\n');


                var i = 0;
                foreach (var line in lines)
                {
                    if (i > 0)
                    {
                        string newline = line.Trim();

                        if (!string.IsNullOrEmpty(newline))
                        {
                            string[] words = newline.Split(';');

                            var fk    = words[0]; // Kurzname Fakultät
                            var cu    = words[1]; // Kurzname Studiengang
                            var sg    = words[2]; // Name Studiengruppe
                            var cg    = words[3]; // Name Kapazitätsgruppe - kann leer sein
                            var ws    = words[4]; // Kapazitätsgruppe wird im WS angeboten
                            var ss    = words[5]; // Kapazitätsgruppe wird im SS angeboten
                            var untis = words[6]; // Kürzel gpUntis

                            // Vorbedingung
                            // Fakultät und Studiengang müssen existieren
                            var faculty = Db.Organisers.SingleOrDefault(f => f.ShortName.Equals(fk));
                            if (faculty != null)
                            {
                                var curriculum = faculty.Curricula.SingleOrDefault(c => c.ShortName.Equals(cu));

                                if (curriculum != null)
                                {
                                    var studyGroup = curriculum.CurriculumGroups.SingleOrDefault(g => g.Name.Equals(sg));

                                    // Neue Studiengruppen werden automatisch angelegt
                                    if (studyGroup == null)
                                    {
                                        studyGroup = new CurriculumGroup
                                        {
                                            Name           = sg,
                                            Curriculum     = curriculum,
                                            IsSubscribable = false
                                        };
                                        Db.CurriculumGroups.Add(studyGroup);
                                        Db.SaveChanges();
                                    }

                                    var capacityGroup = string.IsNullOrEmpty(cg) ?
                                                        studyGroup.CapacityGroups.SingleOrDefault(g => string.IsNullOrEmpty(g.Name)) :
                                                        studyGroup.CapacityGroups.SingleOrDefault(g => g.Name.Equals(cg));

                                    // Neue Kapazitätsgruppen werden automatisch angelegt
                                    if (capacityGroup == null)
                                    {
                                        capacityGroup = new CapacityGroup
                                        {
                                            CurriculumGroup = studyGroup,
                                            Name            = cg
                                        };
                                        Db.CapacityGroups.Add(capacityGroup);
                                        Db.SaveChanges();
                                    }

                                    // ggf. bereits vorhandene Eigenschaften überschreiben
                                    capacityGroup.InWS = string.Equals(ws, "WS");
                                    capacityGroup.InSS = string.Equals(ss, "SS");
                                    Db.SaveChanges();

                                    var alias = capacityGroup.Aliases.SingleOrDefault(a => a.Name.Equals(untis));

                                    if (alias == null)
                                    {
                                        alias = new GroupAlias
                                        {
                                            CapacityGroup = capacityGroup,
                                            Name          = untis
                                        };
                                        Db.GroupAliases.Add(alias);
                                        Db.SaveChanges();
                                    }
                                }
                            }
                        }
                    }
                    i++;
                }
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 9
0
        private TimeTable.Data.Curriculum GetCurriculum(TimeTableDbContext db, Semester semester, string orgName, string currName)
        {
            var org  = db.Organisers.SingleOrDefault(x => x.ShortName.Equals(orgName));
            var curr = org.Curricula.SingleOrDefault(x => x.ShortName.Equals(currName));

            if (curr == null)
            {
                curr = new TimeTable.Data.Curriculum
                {
                    ShortName = currName,
                    Name      = currName,
                    Organiser = org
                };
                db.Curricula.Add(curr);
                db.SaveChanges();
            }

            // Gleich alles notwendige anlegen
            var wpmCurrciculumGroup = curr.CurriculumGroups.SingleOrDefault(x => x.Name.Equals("WPM"));

            if (wpmCurrciculumGroup == null)
            {
                wpmCurrciculumGroup = new CurriculumGroup
                {
                    Curriculum     = curr,
                    Name           = "WPM",
                    IsSubscribable = true,
                };
                db.CurriculumGroups.Add(wpmCurrciculumGroup);
                db.SaveChanges();
            }

            var wpmCapacityGroup = wpmCurrciculumGroup.CapacityGroups.FirstOrDefault();

            if (wpmCapacityGroup == null)
            {
                wpmCapacityGroup = new CapacityGroup
                {
                    CurriculumGroup = wpmCurrciculumGroup,
                    Name            = string.Empty,
                    InSS            = true,
                    InWS            = true
                };
                db.CapacityGroups.Add(wpmCapacityGroup);
                db.SaveChanges();
            }

            var wpmSemesterGroup = db.SemesterGroups.FirstOrDefault(x =>
                                                                    x.CapacityGroup.Id == wpmCapacityGroup.Id && x.Semester.Id == semester.Id);

            if (wpmSemesterGroup == null)
            {
                wpmSemesterGroup = new SemesterGroup
                {
                    Semester      = semester,
                    CapacityGroup = wpmCapacityGroup,
                    IsAvailable   = false // zu Beginn nicht freigegeben
                };
                db.SemesterGroups.Add(wpmSemesterGroup);



                db.SaveChanges();
            }


            return(curr);
        }
Esempio n. 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="db"></param>
        /// <param name="gruppenId">Gruppenalias nach dem in der Datenbank gesucht wird</param>
        /// <returns></returns>
        private List <SemesterGroup> InitSemesterGroups(TimeTableDbContext db, string gruppenId)
        {
            var semester = db.Semesters.SingleOrDefault(s => s.Id == _semId);
            var org      = db.Organisers.SingleOrDefault(x => x.Id == _orgId);

            // Annahme, die Semestergruppen existieren!
            var semGroupList = new List <SemesterGroup>();

            // Annahme, die Semestergruppen existieren nicht alle und müssen ggf. angelegt werden

            // damit man nach den Alias namen in Abhängigkeit der Studiengänge / Fakultät suchen kann
            // so müssen die Namen derzeit auf globale Ebene eindeutig sein
            var aliasList = db.GroupAliases.Where(g => g.Name.ToUpper().Equals(gruppenId.ToUpper()) &&
                                                  g.CapacityGroup.CurriculumGroup.Curriculum.Organiser.Id == _orgId).ToList();

            // falls leer, jetzt in Zuordnungen nachsehen
            if (!aliasList.Any())
            {
                var zuordnungen = _import.GruppenZuordnungen.Where(x => x.Alias.Equals(gruppenId));

                foreach (var zuordnung in zuordnungen)
                {
                    // Studiengang finden
                    var curr = db.Curricula.SingleOrDefault(x =>
                                                            x.ShortName.Equals(zuordnung.Studiengang) &&
                                                            x.Organiser.Id == org.Id);
                    if (curr == null)
                    {
                        curr = new TimeTable.Data.Curriculum
                        {
                            Organiser = org,
                            ShortName = zuordnung.Studiengang,
                            Name      = zuordnung.Studiengang
                        };
                        db.Curricula.Add(curr);
                    }

                    var sg = curr.CurriculumGroups.SingleOrDefault(x => x.Name.Equals(zuordnung.Studiengruppe));
                    if (sg == null)
                    {
                        sg = new CurriculumGroup
                        {
                            Name           = zuordnung.Studiengruppe,
                            IsSubscribable = true,
                            Curriculum     = curr
                        };
                        db.CurriculumGroups.Add(sg);
                        curr.CurriculumGroups.Add(sg);
                    }

                    var cg = string.IsNullOrEmpty(zuordnung.Kapazitätsgruppe) ?
                             sg.CapacityGroups.SingleOrDefault(x => string.IsNullOrEmpty(x.Name)) :
                             sg.CapacityGroups.SingleOrDefault(x => x.Name.Equals(zuordnung.Kapazitätsgruppe));
                    if (cg == null)
                    {
                        cg = new CapacityGroup
                        {
                            InSS            = true,
                            InWS            = true,
                            Name            = zuordnung.Kapazitätsgruppe,
                            CurriculumGroup = sg
                        };
                        db.CapacityGroups.Add(cg);
                        sg.CapacityGroups.Add(cg);
                    }

                    var al = cg.Aliases.SingleOrDefault(x => x.Name.Equals(zuordnung.Alias));
                    if (al == null)
                    {
                        al = new GroupAlias
                        {
                            Name          = zuordnung.Alias,
                            CapacityGroup = cg
                        };
                        db.GroupAliases.Add(al);
                        cg.Aliases.Add(al);
                    }

                    aliasList.Add(al);
                }
                db.SaveChanges();
            }


            foreach (var groupAlias in aliasList)
            {
                // zugehörige Kapazitätsgruppe
                var capGroup = groupAlias.CapacityGroup;

                // im semester suchen
                var semGroup = semester.Groups.SingleOrDefault(g => g.CapacityGroup.Id == capGroup.Id);

                if (semGroup == null)
                {
                    // semestergruppe gibt es nicht => auf jeden Fall anlegen
                    semGroup = new SemesterGroup
                    {
                        CapacityGroup = capGroup,
                        Semester      = semester,
                    };

                    _Logger.InfoFormat("Semestergruppe {0} angelegt {1}", semGroup.FullName, gruppenId);

                    capGroup.SemesterGroups.Add(semGroup);
                    db.SemesterGroups.Add(semGroup);
                    db.SaveChanges();
                }

                semGroupList.Add(semGroup);
            }

            return(semGroupList);
        }
Esempio n. 11
0
        public string ImportCourse(ScheduleCourse scheduleCourse)
        {
            string msg;

            _Logger.DebugFormat("Importiere Fach: {0}", scheduleCourse.Name);
            _report.AppendFormat("<h1>Erzeuge LV \"{0} ({1})\" - [{2}]</h1>", scheduleCourse.Name, scheduleCourse.ShortName,
                                 scheduleCourse.CourseId);
            _report.AppendLine();

            var db = new TimeTableDbContext();

            var organiser = db.Organisers.SingleOrDefault(s => s.Id == _orgId);
            var sem       = db.Semesters.SingleOrDefault(s => s.Id == _semId);

            long msStart = sw.ElapsedMilliseconds;
            var  course  = new Course
            {
                ExternalSource = "JSON",
                ExternalId     = scheduleCourse.CourseId,
                Organiser      = organiser,
                ShortName      = scheduleCourse.ShortName,
                Name           = scheduleCourse.Name,
                Description    = scheduleCourse.Description,
                Occurrence     = CreateDefaultOccurrence(scheduleCourse.SeatRestriction ?? 0),
                IsInternal     = true,
            };

            // Kurs sofort speichern, damit die ID gesichert ist
            db.Activities.Add(course);
            db.SaveChanges();
            long msEnd = sw.ElapsedMilliseconds;

            _Logger.DebugFormat("Dauer: {0}ms", msEnd - msStart);
            msStart = msEnd;

            _report.AppendLine("<h2>Bezeichnungen</h2>");
            _report.AppendLine("<table>");
            _report.AppendFormat("<tr><td>Name</td><td>{0}</td></tr>", course.Name);
            _report.AppendFormat("<tr><td>Kurzname</td><td>{0}</td></tr>", course.ShortName);
            _report.AppendFormat("<tr><td>Beschreibung</td><td>{0}</td></tr>", course.Description);
            _report.AppendLine("</table>");


            // jetzt die Gruppen
            foreach (var scheduleGroup in scheduleCourse.Groups)
            {
                // Fakultät ermitteln
                var org = db.Organisers.SingleOrDefault(x => x.ShortName.Equals(scheduleGroup.FacultyName));

                // Studiengang innerhalb der Fakultät ermitteln
                var curr = org.Curricula.SingleOrDefault(x => x.ShortName.Equals(scheduleGroup.CurriculumShortName));
                if (curr == null)
                {
                    curr = new TimeTable.Data.Curriculum
                    {
                        ShortName = scheduleGroup.CurriculumShortName,
                        Name      = scheduleGroup.CurriculumName,
                        Organiser = org
                    };
                    db.Curricula.Add(curr);
                    db.SaveChanges();
                }

                // Studiengruppe innerhalb des Studiengangs ermitteln
                var groupName = scheduleGroup.GroupName;

                // Sonderlocke FK 11
                // aus der LV-Nummer das Semester raussuchen

                /* OHI 20180720: wieder ausgebaut, weil Schnittstelle jetzt sauber befüllt ist
                 * if (org.ShortName.Equals("FK 11"))
                 * {
                 *  if (!string.IsNullOrEmpty(course.ShortName))
                 *  {
                 *      groupName = course.ShortName[1].ToString();
                 *
                 *  }
                 *  else
                 *  {
                 *      groupName = "#N.V.";
                 *  }
                 * }
                 */

                var currGroup = curr.CurriculumGroups.SingleOrDefault(x => x.Name.Equals(groupName));
                if (currGroup == null)
                {
                    currGroup = new CurriculumGroup
                    {
                        Curriculum     = curr,
                        Name           = groupName,
                        IsSubscribable = true,
                    };
                    db.CurriculumGroups.Add(currGroup);
                    db.SaveChanges();
                }

                // Kapazitätsgruppe innerhalb der Studiengruppe ermitteln
                CapacityGroup capGroup = null;
                if (string.IsNullOrEmpty(scheduleGroup.SubGroupName))
                {
                    capGroup = currGroup.CapacityGroups.SingleOrDefault(x => string.IsNullOrEmpty(x.Name));
                    if (capGroup == null)
                    {
                        capGroup = new CapacityGroup
                        {
                            CurriculumGroup = currGroup,
                            Name            = string.Empty,
                            InSS            = scheduleGroup.SemesterName.StartsWith("SS"),
                            InWS            = scheduleGroup.SemesterName.StartsWith("WS")
                        };
                        db.CapacityGroups.Add(capGroup);
                        db.SaveChanges();
                    }
                }
                else
                {
                    capGroup = currGroup.CapacityGroups.SingleOrDefault(x => !string.IsNullOrEmpty(x.Name) && x.Name.Equals(scheduleGroup.SubGroupName));
                    if (capGroup == null)
                    {
                        capGroup = new CapacityGroup
                        {
                            CurriculumGroup = currGroup,
                            Name            = scheduleGroup.SubGroupName,
                            InSS            = scheduleGroup.SemesterName.StartsWith("SS"),
                            InWS            = scheduleGroup.SemesterName.StartsWith("WS")
                        };
                        db.CapacityGroups.Add(capGroup);
                        db.SaveChanges();
                    }
                }

                // Semester ermitteln
                var semester = db.Semesters.SingleOrDefault(x => x.Name.Equals(scheduleGroup.SemesterName));

                if (semester.Id == sem.Id)
                {
                    // jetzt können wir die Semestergruppe ermitteln
                    var semGroup =
                        db.SemesterGroups.SingleOrDefault(x => x.Semester.Id == semester.Id &&
                                                          x.CapacityGroup.Id == capGroup.Id);
                    if (semGroup == null)
                    {
                        semGroup = new SemesterGroup
                        {
                            Semester      = semester,
                            CapacityGroup = capGroup,
                            IsAvailable   = false // zu Beginn nicht freigegeben
                        };
                        db.SemesterGroups.Add(semGroup);
                        db.SaveChanges();
                    }

                    course.SemesterGroups.Add(semGroup);
                    semGroup.Activities.Add(course);

                    // zu jeder Semestergruppe gibt es dann noch eine
                    // Gruppe für Platzverlosung
                    var occGroup =
                        course.Occurrence.Groups.SingleOrDefault(
                            gg => gg.SemesterGroups.Any(s => s.Id == semGroup.Id));

                    if (occGroup == null)
                    {
                        occGroup = new OccurrenceGroup
                        {
                            Capacity            = 0,
                            FitToCurriculumOnly = true,
                            Occurrence          = course.Occurrence
                        };
                        occGroup.SemesterGroups.Add(semGroup);
                        semGroup.OccurrenceGroups.Add(occGroup);
                        course.Occurrence.Groups.Add(occGroup);
                        db.OccurrenceGroups.Add(occGroup);
                    }

                    // NEU: Chapter und Topics
                    if (!string.IsNullOrEmpty(scheduleGroup.ChapterName) &&
                        !string.IsNullOrEmpty(scheduleGroup.TopicName))
                    {
                        var chapter = curr.Chapters.FirstOrDefault(x => x.Name.Equals(scheduleGroup.ChapterName));
                        if (chapter == null)
                        {
                            chapter = new CurriculumChapter
                            {
                                Curriculum = curr,
                                Name       = scheduleGroup.ChapterName
                            };
                            db.CurriculumChapters.Add(chapter);
                        }

                        var topic = chapter.Topics.FirstOrDefault(x => x.Name.Equals(scheduleGroup.TopicName));
                        if (topic == null)
                        {
                            topic = new CurriculumTopic
                            {
                                Chapter = chapter,
                                Name    = scheduleGroup.TopicName
                            };
                            db.CurriculumTopics.Add(topic);
                        }

                        var semTopic = db.SemesterTopics.FirstOrDefault(x =>
                                                                        x.Semester.Id == sem.Id && x.Topic.Id == topic.Id);

                        if (semTopic == null)
                        {
                            semTopic = new SemesterTopic
                            {
                                Semester = sem,
                                Topic    = topic,
                            };
                            db.SemesterTopics.Add(semTopic);
                        }

                        semTopic.Activities.Add(course);
                    }
                }
                // else => Semestergruppe wird nicht angelegt
            }

            db.SaveChanges();

            if (!course.SemesterGroups.Any())
            {
                _Logger.ErrorFormat("Kurs {0} ohne Gruppe", scheduleCourse.CourseId);
            }

            // zum Schluss die Termine
            _report.AppendLine("<h2>Neue Termine</h2>");
            _report.AppendLine("<table>");

            foreach (var scheduleDate in scheduleCourse.Dates)
            {
                // Der Tag
                var occDate = scheduleDate.Begin.Date;

                bool isVorlesung = true;
                foreach (var sd in _semester.Dates)
                {
                    // Wenn der Termin in eine vorlesungsfreie Zeit fällt, dann nicht importieren
                    if (sd.From.Date <= occDate.Date &&
                        occDate.Date <= sd.To.Date &&
                        sd.HasCourses == false)
                    {
                        isVorlesung = false;
                    }
                }

                if (isVorlesung)
                {
                    var occ = new ActivityDate
                    {
                        Begin      = scheduleDate.Begin,
                        End        = scheduleDate.End,
                        Activity   = course,
                        Occurrence = CreateDefaultOccurrence(),
                    };
                    _report.AppendLine("<tr>");
                    _report.AppendFormat("<td>{0}</td><td>{1}</td><td>{2}</td>", occ.Begin.ToShortDateString(), occ.Begin.ToShortTimeString(), occ.End.ToShortTimeString());

                    _report.AppendFormat("<td>");
                    foreach (var scheduleDateRoom in scheduleDate.Rooms)
                    {
                        _report.AppendFormat("<p>{0}", scheduleDateRoom.RoomNumber);
                        if (!string.IsNullOrEmpty(scheduleDateRoom.RoomNumber))
                        {
                            var room = db.Rooms.SingleOrDefault(r => r.Number.Equals(scheduleDateRoom.RoomNumber));
                            if (room == null)
                            {
                                room = new Room
                                {
                                    Number      = scheduleDateRoom.RoomNumber,
                                    Capacity    = 0,
                                    Description = string.Empty,
                                    Owner       = string.Empty,
                                };
                                db.Rooms.Add(room);
                                db.SaveChanges();

                                _numRooms++;
                                _report.AppendFormat(" !!!NEUER RAUM!!!");
                            }


                            var assignment = db.RoomAssignments.SingleOrDefault(x =>
                                                                                x.Room.Id == room.Id &&
                                                                                x.Organiser.Id == organiser.Id);
                            if (assignment == null)
                            {
                                assignment = new RoomAssignment
                                {
                                    Organiser = organiser,
                                    InternalNeedConfirmation = false, // offen für interne
                                    ExternalNeedConfirmation = true   // geschlossen für externe
                                };

                                room.Assignments.Add(assignment);
                                db.RoomAssignments.Add(assignment);
                                db.SaveChanges();
                            }

                            occ.Rooms.Add(room);
                            _report.AppendFormat("</p>");
                        }
                    }
                    _report.AppendFormat("</td>");

                    _report.AppendFormat("<td>");
                    foreach (var scheduleDateLecturer in scheduleDate.Lecturers)
                    {
                        _report.AppendFormat("<p>{0} ({1})", scheduleDateLecturer.Name, scheduleDateLecturer.ShortName);

                        var lecturer = organiser.Members.SingleOrDefault(l => l.ShortName.Equals(scheduleDateLecturer.ShortName));
                        if (lecturer == null)
                        {
                            lecturer = new OrganiserMember
                            {
                                ShortName   = scheduleDateLecturer.ShortName,
                                Name        = scheduleDateLecturer.Name,
                                Role        = String.Empty,
                                Description = String.Empty
                            };
                            organiser.Members.Add(lecturer);
                            db.Members.Add(lecturer);
                            db.SaveChanges();
                            _numLecturers++;
                            _report.AppendFormat(" !!!NEUER DOZENT!!!");
                        }

                        occ.Hosts.Add(lecturer);
                        _report.AppendFormat("</p>");
                    }
                    _report.AppendFormat("</td>");

                    db.ActivityDates.Add(occ);

                    _report.AppendLine();
                    _report.AppendLine("</tr>");
                }
            }

            _report.AppendLine("</table>");
            db.SaveChanges();

            msEnd = sw.ElapsedMilliseconds;
            _Logger.DebugFormat("Dauer {0}ms", msEnd - msStart);

            msg = $"Kurs {course.ShortName} mit Terminen importiert";

            return(msg);
        }
Esempio n. 12
0
 public CurriculumGroupModel(CurriculumGroup model) : base(model)
 {
     LoadFromModel(model);
 }