예제 #1
0
        public ActionResult Upload(SemesterImportModel model)
        {
            string tempDir = GetTempPath(model.OrganiserId, model.SemesterId);

            // Speichern der Untis Dateien
            foreach (var attachment in model.Attachments)
            {
                if (attachment != null)
                {
                    var fileName = Path.GetFileName(attachment.FileName);

                    var tempFileName = Path.Combine(tempDir, fileName);

                    attachment.SaveAs(tempFileName);
                }
            }

            // Speichern der Config-Dateien
            model.AttachmentDays?.SaveAs(Path.Combine(tempDir, "configDays.txt"));
            model.AttachmentHours?.SaveAs(Path.Combine(tempDir, "configHours.txt"));
            model.AttachmentGroups?.SaveAs(Path.Combine(tempDir, "configGroups.txt"));

            // Dateien prüfen
            var reader = new FileReader();

            reader.ReadFiles(tempDir);

            var importer = new SemesterImport(reader.Context, model.SemesterId, model.OrganiserId);

            // Gruppen müssen existieren! => Fehler, wenn nicht
            importer.CheckGroups();

            // Räume sollten existieren => Warnung
            // Zuordnungen zu Räumen sollten existieren => Warnung
            importer.CheckRooms();

            // Dozenten sollten existieren => Warnung
            importer.CheckLecturers();

            importer.CheckCourses();

            importer.CheckRestriktions();

            reader.Context.AddErrorMessage("Zusammenfassung", string.Format("Von {0} Kursen werden {1} importiert",
                                                                            reader.Context.Kurse.Count, reader.Context.Kurse.Count(x => x.IsValid)), false);


            model.Context = reader.Context;

            return(View(model));
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="semId"></param>
        /// <param name="orgId"></param>
        /// <returns></returns>
        public string CheckConsistency(Guid semId, Guid orgId)
        {
            var db = new TimeTableDbContext();

            var tempDir = Path.GetTempPath();

            var semester = db.Semesters.SingleOrDefault(s => s.Id == semId);
            var org      = db.Organisers.SingleOrDefault(o => o.Id == orgId);

            if (semester != null && org != null)
            {
                tempDir = Path.Combine(tempDir, semester.Name);
                tempDir = Path.Combine(tempDir, org.ShortName);
            }


            var msg   = "Lese Dateien";
            var perc1 = 0;

            Clients.Caller.updateProgress(msg, perc1);

            FileReader reader = new FileReader();

            try
            {
                reader.ReadFiles(tempDir);

                var importer = new SemesterImport(reader.Context, semId, orgId);

                msg   = "prüfe Gruppen";
                perc1 = 25;
                Clients.Caller.updateProgress(msg, perc1);
                // Gruppen müssen existieren! => Fehler, wenn nicht
                importer.CheckGroups();

                msg   = "prüfe Räume";
                perc1 = 50;
                Clients.Caller.updateProgress(msg, perc1);
                // Räume sollten existieren => Warnung
                // Zuordnungen zu Räumen sollten existieren => Warnung
                importer.CheckRooms();

                msg   = "prüfe Dozenten";
                perc1 = 75;
                Clients.Caller.updateProgress(msg, perc1);
                // Dozenten sollten existieren => Warnung
                importer.CheckLecturers();
            }
            catch (Exception ex)
            {
                reader.Context.AddErrorMessage("Import", ex.Message, true);
            }


            msg   = "beendet";
            perc1 = 100;
            Clients.Caller.updateProgress(msg, perc1);


            if (reader.Context.ErrorMessages["Import"] == null)
            {
                return(null);
            }

            var sb = new StringBuilder();

            sb.Append("<tr>");
            sb.Append("<td>Import</td>");
            sb.Append("<td>");
            foreach (var message in reader.Context.ErrorMessages["Import"])
            {
                sb.AppendFormat("<div>{0}</li>", message);
            }
            sb.Append("</td>");
            sb.Append("</tr>");

            return(sb.ToString());
        }