Ejemplo n.º 1
0
        public void AddExamsWithAnswer()
        {
            var dbContext = new ApplicationDbContext();
            var semesters = dbContext.Semesters.ToList();

            foreach (var semester in semesters)
            {
                var dir = new DirectoryInfo(
                    $@"D:\Projects\Zanis.Ostad\Zanis.Ostad.Web\wwwroot\Files\{semester.Code}\soalbajavab");
                if (!dir.Exists)
                {
                    continue;
                }
                foreach (var fileInfo in dir.GetFiles())
                {
                    var matches     = Regex.Matches(fileInfo.Name, "[0-9]+");
                    var lessonCodes =
                        matches.Select(x => x.Value).Where(x => x.Length == 7).ToList();
                    if (dbContext.ExamSampleFiles.Any(x => fileInfo.FullName.Replace("\\", "/").Contains(x.FilePath)))
                    {
                        continue;
                    }
                    var exam = new ExamSampleFile
                    {
                        Type       = ExamSampleFileType.ExamWithAnswer,
                        SemesterId = semester.Id,
                        FilePath   = $"/Files/{semester.Code}/soalbajavab/" + fileInfo.Name
                    };
                    if (dbContext.ExamSampleFiles.Any(x => x.FilePath == exam.FilePath))
                    {
                        continue;
                    }
                    dbContext.ExamSampleFiles.Add(exam);
                    dbContext.SaveChanges();
                    var lessons = dbContext.Lessons.Where(x => lessonCodes.Contains(x.LessonCode)).ToList();
                    foreach (var lesson in lessons)
                    {
                        dbContext.LessonExamMappings.Add(new LessonExamMapping
                        {
                            LessonId         = lesson.Id,
                            ExamSampleFileId = exam.Id
                        });
                    }
                }

                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public void AddAnatomicalAnswers()
        {
            var dbContext = new ApplicationDbContext();

            dbContext.Database.Migrate();
            var semesters = dbContext.Semesters.ToList();

            foreach (var semester in semesters)
            {
                var dir = new DirectoryInfo(
                    $@"E:\WorkAndLife\Projects\Zanis.Ostad\Zanis.Ostad.Web\wwwroot\Files\{semester.Code}\tashrihi");
                foreach (var fileInfo in dir.GetFiles())
                {
                    var matches     = Regex.Matches(fileInfo.Name, "[0-9]+");
                    var lessonCodes =
                        matches.Select(x => x.Value).Where(x => x.Length == 7).ToList();
                    if (dbContext.ExamSampleFiles.Any(x =>
                                                      fileInfo.FullName.ToLower().Replace("\\", "/").Replace("p", "").Contains(x.FilePath)))
                    {
                        continue;
                    }
                    var exam = new ExamSampleFile()
                    {
                        SemesterId = semester.Id,
                        FilePath   = $"/Files/{semester.Code}/tashrihi/" + fileInfo.Name,
                        Type       = ExamSampleFileType.AnatomicalAnswer
                    };
                    if (dbContext.ExamSampleFiles.Any(x => fileInfo.FullName.Replace("\\", "/").Contains(x.FilePath)))
                    {
                        continue;
                    }
                    dbContext.ExamSampleFiles.Add(exam);
                    dbContext.SaveChanges();
                    var lessons = dbContext.Lessons.Where(x => lessonCodes.Contains(x.LessonCode)).ToList();
                    foreach (var lesson in lessons)
                    {
                        dbContext.LessonExamMappings.Add(new LessonExamMapping()
                        {
                            LessonId         = lesson.Id,
                            ExamSampleFileId = exam.Id
                        });
                    }
                }

                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public void AddTestsAnswers()
        {
            var dbContext = new ApplicationDbContext();
            var semesters = dbContext.Semesters.ToList();

            foreach (var semester in semesters)
            {
                var dir = new DirectoryInfo(
                    $@"E:\WorkAndLife\Projects\Zanis.Ostad\Zanis.Ostad.Web\wwwroot\Files\{semester.Code}\test");
                foreach (var fileInfo in dir.GetFiles())
                {
                    var lessonCodes = fileInfo.Name.Replace(fileInfo.Extension, "").Split("-").ToList();
                    if (dbContext.ExamSampleFiles.Any(x =>
                                                      fileInfo.FullName.ToLower().Replace("\\", "/").Replace("p", "").Contains(x.FilePath)))
                    {
                        continue;
                    }
                    var exam = new ExamSampleFile
                    {
                        SemesterId = semester.Id,
                        FilePath   = $"/Files/{semester.Code}/test/" + fileInfo.Name,
                        Type       = ExamSampleFileType.TestAnswer
                    };
                    if (dbContext.ExamSampleFiles.Any(x => fileInfo.FullName.Replace("\\", "/").Contains(x.FilePath)))
                    {
                        continue;
                    }
                    dbContext.ExamSampleFiles.Add(exam);
                    dbContext.SaveChanges();
                    var lessons = dbContext.Lessons.Where(x => lessonCodes.Contains(x.LessonCode)).ToList();
                    foreach (var lesson in lessons)
                    {
                        dbContext.LessonExamMappings.Add(new LessonExamMapping()
                        {
                            LessonId         = lesson.Id,
                            ExamSampleFileId = exam.Id
                        });
                    }
                }
                dbContext.SaveChanges();
            }
        }