Пример #1
0
        public async Task CreateAsync(string subjectName, string title, string description, string fileUri, string fileDescription, ExamType type, DateTime?open, DateTime?close)
        {
            var subject = await this.subjectRepository.All().FirstOrDefaultAsync(s => s.Name == subjectName);

            var exam = new Exam
            {
                Type        = type,
                Subject     = subject,
                Title       = title,
                Description = description,
                Open        = open,
                Close       = close,
            };

            if (fileUri != string.Empty)
            {
                exam.Files.Add(new File
                {
                    CloudinaryFileUri = fileUri,
                    FileDescription   = fileDescription,
                });
            }

            if (type.ToString() == "PresentExam")
            {
                exam.Students = this.studentRepository
                                .All()
                                .Where(s => s.StudentSubjects.FirstOrDefault(x => x.Subject.Name == subjectName) != null)
                                .ToHashSet <ApplicationUser>();
            }

            await this.examRepository.AddAsync(exam);

            await this.examRepository.SaveChangesAsync();
        }