コード例 #1
0
        public void DeleteLabs(int id)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                var labs =
                    repositoriesContainer.LabsRepository.GetBy(
                        new Query<Labs>(e => e.Id == id).Include(e => e.StudentLabMarks));

                var deleteFiles =
                        repositoriesContainer.AttachmentRepository.GetAll(
                            new Query<Attachment>(e => e.PathName == labs.Attachments)).ToList();

                var studentLabMarks =
                    repositoriesContainer.RepositoryFor<StudentLabMark>()
                        .GetAll(new Query<StudentLabMark>(e => e.LabId == id))
                        .ToList();

                foreach (var attachment in deleteFiles)
                {
                    FilesManagementService.DeleteFileAttachment(attachment);
                }

                foreach (var mark in studentLabMarks)
                {
                    repositoriesContainer.RepositoryFor<StudentLabMark>().Delete(mark);
                }

                repositoriesContainer.ApplyChanges();

                repositoriesContainer.LabsRepository.Delete(labs);

                repositoriesContainer.ApplyChanges();
            }
        }
コード例 #2
0
        private int GetRemainingTime(int testId, int questionId, int userId)
        {
            var test = GetTest(testId);
            TestPassResult testPassResult = GetTestPassResult(testId, userId);

            double seconds = 0;

            if (test.SetTimeForAllTest)
            {
                seconds = (test.TimeForCompleting * 60) - (DateTime.UtcNow - testPassResult.StartTime).TotalSeconds;
            }
            else
            {
                if (testPassResult.Comment == questionId.ToString())
                {
                    seconds = test.TimeForCompleting - ((DateTime.UtcNow.Ticks - testPassResult.StartTime.Ticks) / TimeSpan.TicksPerSecond);
                }
                else
                {
                    seconds = test.TimeForCompleting;
                    testPassResult.StartTime = DateTime.UtcNow;
                    testPassResult.Comment = questionId.ToString();
                }

                using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
                {
                    repositoriesContainer.RepositoryFor<TestPassResult>().Save(testPassResult);
                    repositoriesContainer.ApplyChanges();
                }
            }

            return seconds > 0 ? (int)seconds : 0;
        }
コード例 #3
0
        public Question SaveQuestion(Question question)
        {
            CheckForTestIsNotLocked(question.TestId);

            ValidateQuestion(question);

            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.QuestionsRepository.Save(question);
                Question existingQuestion = GetQuestion(question.Id);
                var answersToDelete = existingQuestion.Answers.Where(a => question.Answers.All(answer => answer.Id != a.Id));

                // TODO: Resolve problem (items are saved only first time)
                foreach (Answer answer in question.Answers)
                {
                    answer.QuestionId = question.Id;
                }

                repositoriesContainer.RepositoryFor<Answer>().Save(question.Answers);
                repositoriesContainer.RepositoryFor<Answer>().Delete(answersToDelete);

                repositoriesContainer.ApplyChanges();
                return question;
            }
        }
コード例 #4
0
 public void Save(Student student)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         repositoriesContainer.StudentsRepository.SaveStudent(student);
         repositoriesContainer.ApplyChanges();
     }
 }
コード例 #5
0
 public void DeleteGroup(int id)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         var group = repositoriesContainer.GroupsRepository.GetBy(new Query<Group>().AddFilterClause(g => g.Id == id));
         repositoriesContainer.GroupsRepository.Delete(group);
         repositoriesContainer.ApplyChanges();
     }
 }
コード例 #6
0
        public BugLog SaveBugLog(BugLog bugLog)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.BugLogsRepository.Save(bugLog);
                repositoriesContainer.ApplyChanges();
            }

            return bugLog;
        }
コード例 #7
0
 public Group AddGroup(Group group)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         repositoriesContainer.GroupsRepository.Save(group);
         repositoriesContainer.ApplyChanges();
     }
     new GroupSearchMethod().AddToIndex(group);
     return group;
 }
コード例 #8
0
        public UserMessages SaveUserMessages(UserMessages userMessages)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.MessageRepository.SaveUserMessages(userMessages);
                repositoriesContainer.ApplyChanges();
            }

            return userMessages;
        }
コード例 #9
0
        public Group UpdateGroup(Group group)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.GroupsRepository.Save(group);
                repositoriesContainer.ApplyChanges();
            }

            return group;
        }
コード例 #10
0
 public Test SaveTest(Test test)
 {
     CheckForTestIsNotLocked(test.Id);
     ValidateTest(test);
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         repositoriesContainer.TestsRepository.Save(test);
         repositoriesContainer.ApplyChanges();
         return test;
     }
 }
コード例 #11
0
 public ActionResult EditObject(string name, string path)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         var data = repositoriesContainer.RepositoryFor<ScoObjects>().GetBy(new Query<ScoObjects>(e => e.Path == path));
         data.Name = name;
         repositoriesContainer.RepositoryFor<ScoObjects>().Save(data);
         repositoriesContainer.ApplyChanges();
     }
     return Json(name, JsonRequestBehavior.AllowGet);
 }
コード例 #12
0
        public void UpdateStudent(Student student)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.StudentsRepository.Save(student);
	            var user = repositoriesContainer.UsersRepository.GetBy(new Query<User>(e => e.Id == student.User.Id));
	            user.UserName = student.User.UserName;
	            user.Avatar = student.User.Avatar;
				repositoriesContainer.UsersRepository.Save(user);
                repositoriesContainer.ApplyChanges();
            }
        }
コード例 #13
0
        public void DeleteTest(int id)
        {
            CheckForTestIsNotLocked(id);
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                Test testToDelete = repositoriesContainer.TestsRepository.GetBy(
                    new Query<Test>(test => test.Id == id));

                repositoriesContainer.TestsRepository.Delete(testToDelete);
                repositoriesContainer.ApplyChanges();
            }
        }
コード例 #14
0
        public void DeleteBug(int bugId)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                var bug =
                    repositoriesContainer.BugsRepository.GetBy(
                        new Query<Bug>().AddFilterClause(u => u.Id == bugId));
                repositoriesContainer.BugsRepository.DeleteBug(bug);
                repositoriesContainer.ApplyChanges();
            }

            ClearBugLogs(bugId);
        }
コード例 #15
0
        public void DeleteFileAttachment(Attachment attachment)
        {
            var filePath = _storageRoot + attachment.PathName + "//" + attachment.FileName;

            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.AttachmentRepository.Delete(attachment);
                repositoriesContainer.ApplyChanges();
            }

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
        }
コード例 #16
0
        public bool DeleteLecturer(int id)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                var lecturer = repositoriesContainer.LecturerRepository.GetBy(
                     new Query<Lecturer>(e => e.Id == id).Include(e => e.SubjectLecturers));

                if (lecturer != null && lecturer.SubjectLecturers != null)
                {
                    var subjects = lecturer.SubjectLecturers.ToList();
                    repositoriesContainer.RepositoryFor<SubjectLecturer>().Delete(subjects);
                    repositoriesContainer.ApplyChanges();
                }
            }
            new LecturerSearchMethod().DeleteIndex(id);
            return UserManagementService.DeleteUser(id);
        }
コード例 #17
0
        public Lecturer UpdateLecturer(Lecturer lecturer)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.LecturerRepository.Save(lecturer);
                var user = repositoriesContainer.UsersRepository.GetBy(new Query <User>(e => e.Id == lecturer.User.Id));
                user.Avatar       = lecturer.User.Avatar;
                user.SkypeContact = lecturer.User.SkypeContact;
                user.Email        = lecturer.User.Email;
                user.About        = lecturer.User.About;
                user.Phone        = lecturer.User.Phone;
                repositoriesContainer.UsersRepository.Save(user);
                repositoriesContainer.ApplyChanges();
            }

            return(lecturer);
        }
コード例 #18
0
        public bool DeleteLecturer(int id)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                var lecturer = repositoriesContainer.LecturerRepository.GetBy(
                    new Query <Lecturer>(e => e.Id == id).Include(e => e.SubjectLecturers));

                if (lecturer != null && lecturer.SubjectLecturers != null)
                {
                    var subjects = lecturer.SubjectLecturers.ToList();
                    repositoriesContainer.RepositoryFor <SubjectLecturer>().Delete(subjects);
                    repositoriesContainer.ApplyChanges();
                }
            }

            return(UserManagementService.DeleteUser(id));
        }
コード例 #19
0
        public Concept SaveConcept(Concept concept, IList <Attachment> attachments)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                //attachments = ProcessWordAttachmentsIfExist(attachments);
                if (!string.IsNullOrEmpty(concept.Container))
                {
                    var deleteFiles =
                        repositoriesContainer.AttachmentRepository.GetAll(
                            new Query <Attachment>(e => e.PathName == concept.Container)).ToList().Where(e => attachments.All(x => x.Id != e.Id)).ToList();

                    foreach (var attachment in deleteFiles)
                    {
                        FilesManagementService.DeleteFileAttachment(attachment);
                    }
                }
                else
                {
                    concept.Container = GetGuidFileName();
                }

                FilesManagementService.SaveFiles(attachments.Where(e => e.Id == 0), concept.Container);

                foreach (var attachment in attachments)
                {
                    if (attachment.Id == 0)
                    {
                        attachment.PathName = concept.Container;

                        repositoriesContainer.AttachmentRepository.Save(attachment);
                    }
                }
                concept.Published = attachments.Any();
                Concept source = null;
                if (concept.Id != 0)
                {
                    source = GetById(concept.Id);
                }
                repositoriesContainer.ConceptRepository.Save(concept);
                repositoriesContainer.ApplyChanges();
                BindNeighborConcept(concept, source, repositoriesContainer);
                TryPublishParent(concept.ParentId, repositoriesContainer);
                return(concept);
            }
        }
コード例 #20
0
        public void DeleteLection(Lectures lectures)
        {
            using var repositoriesContainer = new LmPlatformRepositoriesContainer();

            var lectModel =
                repositoriesContainer.LecturesRepository.GetBy(new Query <Lectures>(e => e.Id == lectures.Id));
            var deleteFiles =
                repositoriesContainer.AttachmentRepository.GetAll(
                    new Query <Attachment>(e => e.PathName == lectModel.Attachments)).ToList();

            foreach (var attachment in deleteFiles)
            {
                FilesManagementService.DeleteFileAttachment(attachment);
            }

            repositoriesContainer.SubjectRepository.DeleteLection(lectures);
            repositoriesContainer.ApplyChanges();
        }
コード例 #21
0
        public Concept CreateRootConcept(string name, int authorId, int subjectId)
        {
            using var repositoriesContainer = new LmPlatformRepositoriesContainer();
            var author =
                repositoriesContainer.UsersRepository.GetBy(
                    new Query <User>().AddFilterClause(u => u.Id == authorId));
            var subject =
                repositoriesContainer.SubjectRepository.GetBy(
                    new Query <Subject>().AddFilterClause(s => s.Id == subjectId));
            var concept = new Concept(name, author, subject, true, false);

            repositoriesContainer.ConceptRepository.Save(concept);
            repositoriesContainer.ApplyChanges();
            InitBaseChildrens(concept, repositoriesContainer);
            return(repositoriesContainer.ConceptRepository.GetBy
                       (new Query <Concept>()
                       .AddFilterClause(c => c.Id == concept.Id)));
        }
コード例 #22
0
        public void UpdateStudent(Student student)
        {
            using var repositoriesContainer = new LmPlatformRepositoriesContainer();
            repositoriesContainer.StudentsRepository.Save(student);
            var user = repositoriesContainer.UsersRepository.GetBy(new Query <User>(e => e.Id == student.User.Id));

            user.UserName     = student.User.UserName;
            user.Avatar       = student.User.Avatar;
            user.About        = student.User.About;
            user.SkypeContact = student.User.SkypeContact;
            user.Phone        = student.User.Phone;
            user.Email        = student.User.Email;
            repositoriesContainer.UsersRepository.Save(user);
            repositoriesContainer.ApplyChanges();
            new StudentSearchMethod().UpdateIndex(student);

            UpdateSubGroup(repositoriesContainer, student);
        }
コード例 #23
0
        public Practical SavePractical(Practical practical, IList <Attachment> attachments, int userId)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                if (!string.IsNullOrEmpty(practical.Attachments))
                {
                    var deleteFiles =
                        repositoriesContainer.AttachmentRepository.GetAll(
                            new Query <Attachment>(e => e.PathName == practical.Attachments)).ToList()
                        .Where(e => attachments.All(x => x.Id != e.Id)).ToList();

                    foreach (var attachment in deleteFiles)
                    {
                        FilesManagementService.DeleteFileAttachment(attachment);
                    }
                }
                else
                {
                    practical.Attachments = GetGuidFileName();
                }

                FilesManagementService.SaveFiles(attachments.Where(e => e.Id == 0), practical.Attachments);

                foreach (var attachment in attachments)
                {
                    if (attachment.Id == 0)
                    {
                        attachment.PathName = practical.Attachments;
                        repositoriesContainer.AttachmentRepository.Save(attachment);
                    }
                }

                repositoriesContainer.PracticalRepository.Save(practical);
                repositoriesContainer.ApplyChanges();

                if (practical.IsNew &&
                    practical.Subject.SubjectModules.Any(m => m.Module.ModuleType == ModuleType.Practical))
                {
                    ConceptManagementService.AttachFolderToLabSection(practical.Theme, userId, practical.SubjectId);
                }
            }

            return(practical);
        }
コード例 #24
0
        public Lectures SaveLectures(Lectures lectures, IList <Attachment> attachments, int userId)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                if (!string.IsNullOrEmpty(lectures.Attachments))
                {
                    var deleteFiles =
                        repositoriesContainer.AttachmentRepository.GetAll(
                            new Query <Attachment>(e => e.PathName == lectures.Attachments)).ToList()
                        .Where(e => attachments.All(x => x.Id != e.Id)).ToList();

                    foreach (var attachment in deleteFiles)
                    {
                        FilesManagementService.DeleteFileAttachment(attachment);
                    }
                }
                else
                {
                    lectures.Attachments = GetGuidFileName();
                }

                FilesManagementService.SaveFiles(attachments.Where(e => e.Id == 0), lectures.Attachments);

                foreach (var attachment in attachments)
                {
                    if (attachment.Id == 0)
                    {
                        attachment.PathName = lectures.Attachments;
                        repositoriesContainer.AttachmentRepository.Save(attachment);
                    }
                }

                repositoriesContainer.LecturesRepository.Save(lectures);
                repositoriesContainer.ApplyChanges();

                if (lectures.IsNew &&
                    lectures.Subject.SubjectModules.Any(s => s.Module.ModuleType == ModuleType.Lectures))
                {
                    ConceptManagementService.AttachFolderToLectSection(lectures.Theme, userId, lectures.SubjectId);
                }
            }

            return(lectures);
        }
コード例 #25
0
        public Concept AttachSiblings(int sourceId, int rightId, int leftId)
        {
            using var repositoriesContainer = new LmPlatformRepositoriesContainer();
            var concept       = repositoriesContainer.ConceptRepository.GetById(sourceId);
            var right         = repositoriesContainer.ConceptRepository.GetById(rightId);
            var left          = repositoriesContainer.ConceptRepository.GetById(leftId);
            var currentPrevId = concept.PrevConcept.GetValueOrDefault();
            var currentNextId = concept.NextConcept.GetValueOrDefault();

            concept.NextConcept = rightId > 0 ? rightId : (int?)null;
            concept.PrevConcept = leftId > 0 ? leftId : (int?)null;
            repositoriesContainer.ConceptRepository.Save(concept);
            if (right != null)
            {
                right.PrevConcept = concept.Id;
                repositoriesContainer.ConceptRepository.Save(right);
            }

            if (left != null)
            {
                left.NextConcept = concept.Id;
                repositoriesContainer.ConceptRepository.Save(left);
            }

            var currentPrev = repositoriesContainer.ConceptRepository.GetById(currentPrevId);
            var currentNext = repositoriesContainer.ConceptRepository.GetById(currentNextId);

            if (currentPrev != null)
            {
                currentPrev.NextConcept = currentNext?.Id;
                repositoriesContainer.ConceptRepository.Save(currentPrev);
            }

            if (currentNext != null)
            {
                currentNext.PrevConcept = currentPrev?.Id;
                repositoriesContainer.ConceptRepository.Save(currentNext);
            }

            repositoriesContainer.ApplyChanges();

            return(concept);
        }
コード例 #26
0
        private void ResetSiblings(int?prevConcept, int?nextConcept,
                                   LmPlatformRepositoriesContainer repositoriesContainer)
        {
            if (prevConcept.HasValue)
            {
                var prevItem = GetById(prevConcept.Value);
                prevItem.NextConcept = nextConcept.HasValue ? nextConcept.Value : (int?)null;
                repositoriesContainer.ConceptRepository.Save(prevItem);
            }

            if (nextConcept.HasValue)
            {
                var nextItem = GetById(nextConcept.Value);
                nextItem.PrevConcept = prevConcept.HasValue ? prevConcept.Value : (int?)null;
                repositoriesContainer.ConceptRepository.Save(nextItem);
            }

            repositoriesContainer.ApplyChanges();
        }
コード例 #27
0
ファイル: TestPassingService.cs プロジェクト: ze3331/lmsystem
        private void StartNewTest(int testId, int userId)
        {
            Test test = GetTest(testId);

            int questionsCount = test.CountOfQuestions > test.Questions.Count
                ? test.Questions.Count
                : test.CountOfQuestions;

            var random = new Random(DateTime.Now.Millisecond);
            IEnumerable <Question> includedQuestions = test.Questions.OrderBy(t => random.Next()).Take(questionsCount);

            var answersTemplate = new List <AnswerOnTestQuestion>();

            int counter = 1;

            foreach (Question includedQuestion in includedQuestions)
            {
                answersTemplate.Add(new AnswerOnTestQuestion
                {
                    QuestionId = includedQuestion.Id,
                    TestId     = testId,
                    UserId     = userId,
                    Number     = counter++
                });
            }

            TestPassResult testPassResult = GetTestPassResult(testId, userId) ?? new TestPassResult
            {
                TestId    = testId,
                StudentId = userId
            };

            testPassResult.StartTime = DateTime.UtcNow;

            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.RepositoryFor <AnswerOnTestQuestion>().Save(answersTemplate);
                repositoriesContainer.RepositoryFor <TestPassResult>().Save(testPassResult);
                repositoriesContainer.ApplyChanges();
            }
        }
コード例 #28
0
        public bool DeleteUser(int id)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                var query = new Query <User>().AddFilterClause(u => u.Id == id).Include(u => u.ProjectUsers);
                var user  = repositoriesContainer.UsersRepository.GetBy(query);

                repositoriesContainer.MessageRepository.DeleteUserMessages(user.Id);

                var projects = user.ProjectUsers.DistinctBy(e => e.ProjectId).Select(e => e.ProjectId);
                foreach (var projectId in projects)
                {
                    ProjectManagementService.DeleteUserFromProject(id, projectId);
                }

                var result = AccountManagementService.DeleteAccount(user.UserName);
                repositoriesContainer.ApplyChanges();

                return(result);
            }
        }
コード例 #29
0
        public Message SaveMessage(Message message)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.MessageRepository.Save(message);

                if (message.Attachments != null)
                {
                    FilesManagementService.SaveFiles(message.Attachments, message.AttachmentsPath.ToString());

                    foreach (var attach in message.Attachments)
                    {
                        repositoriesContainer.AttachmentRepository.Save(attach);
                    }
                }

                repositoriesContainer.ApplyChanges();
            }

            return(message);
        }
コード例 #30
0
        public void CopyQuestionsToTest(int testId, int[] questionsIds)
        {
            CheckForTestIsNotLocked(testId);
            using var repositoriesContainer = new LmPlatformRepositoriesContainer();
            var query = new Query <Question>(question => questionsIds.Contains(question.Id));

            query.Include(question => question.Answers);
            var questionsToCopy = repositoriesContainer.QuestionsRepository.GetAll(query);

            var copiedQuestions = new List <Question>();

            foreach (var questionToCopy in questionsToCopy)
            {
                var copiedQuestion = questionToCopy.Clone() as Question;
                copiedQuestion.TestId = testId;
                copiedQuestions.Add(copiedQuestion);
            }

            repositoriesContainer.QuestionsRepository.Save(copiedQuestions);
            repositoriesContainer.ApplyChanges();
        }
コード例 #31
0
        public Message SaveMessage(Message message)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.MessageRepository.Save(message);

                if (message.Attachments != null)
                {
                    FilesManagementService.SaveFiles(message.Attachments, message.AttachmentsPath.ToString());

                    foreach (var attach in message.Attachments)
                    {
                        repositoriesContainer.AttachmentRepository.Save(attach);
                    }
                }

                repositoriesContainer.ApplyChanges();
            }

            return message;
        }
コード例 #32
0
        public UserLabFiles SaveUserLabFiles(UserLabFiles userLabFiles, IList <Attachment> attachments)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                if (!string.IsNullOrEmpty(userLabFiles.Attachments))
                {
                    var deleteFiles =
                        repositoriesContainer.AttachmentRepository.GetAll(
                            new Query <Attachment>(e => e.PathName == userLabFiles.Attachments)).ToList()
                        .Where(e => attachments.All(x => x.Id != e.Id)).ToList();

                    foreach (var attachment in deleteFiles)
                    {
                        FilesManagementService.DeleteFileAttachment(attachment);
                    }
                }
                else
                {
                    userLabFiles.Attachments = GetGuidFileName();
                }

                FilesManagementService.SaveFiles(attachments.Where(e => e.Id == 0), userLabFiles.Attachments);

                foreach (var attachment in attachments)
                {
                    if (attachment.Id == 0)
                    {
                        attachment.PathName = userLabFiles.Attachments;
                        repositoriesContainer.AttachmentRepository.Save(attachment);
                    }
                }

                repositoriesContainer.RepositoryFor <UserLabFiles>().Save(userLabFiles);
                repositoriesContainer.ApplyChanges();
            }

            return(userLabFiles);
        }
コード例 #33
0
        public void UnlockTest(int[] studentIds, int testId, bool unlock)
        {
            using var repositoriesContainer = new LmPlatformRepositoriesContainer();
            var savedTestUnlocks = repositoriesContainer.TestUnlocksRepository.GetAll(new
                                                                                      Query <TestUnlock>()
                                                                                      .AddFilterClause(testUnlock =>
                                                                                                       studentIds.Contains(testUnlock.StudentId) && testUnlock.TestId == testId))
                                   .ToList();

            repositoriesContainer.TestUnlocksRepository.Delete(savedTestUnlocks);
            if (unlock)
            {
                var testUnlocks = studentIds.Select(studentId => new TestUnlock
                {
                    StudentId = studentId,
                    TestId    = testId
                });

                repositoriesContainer.TestUnlocksRepository.Save(testUnlocks);
            }

            repositoriesContainer.ApplyChanges();
        }
コード例 #34
0
        public void СonfirmationStudent(int studentId)
        {
            using var repositoriesContainer = new LmPlatformRepositoriesContainer();
            var student = GetStudent(studentId);

            student.Confirmed = true;

            UpdateStudent(student);

            var subjects = repositoriesContainer.SubjectRepository.GetSubjects(student.GroupId)
                           .Where(e => !e.IsArchive);

            foreach (var subject in subjects)
            {
                if (!subject.SubjectGroups.Any(e => e.SubjectStudents.Any(x => x.StudentId == student.Id)))
                {
                    var firstOrDefault = subject.SubjectGroups.FirstOrDefault(e => e.GroupId == student.GroupId);
                    if (firstOrDefault != null)
                    {
                        var subjectGroupId = firstOrDefault.Id;

                        var modelFirstSubGroup = repositoriesContainer.SubGroupRepository.GetBy(
                            new Query <SubGroup>(e => e.SubjectGroupId == subjectGroupId && e.Name == "first"));

                        var subjectStudent = new SubjectStudent
                        {
                            StudentId      = studentId,
                            SubGroupId     = modelFirstSubGroup.Id,
                            SubjectGroupId = subjectGroupId
                        };
                        repositoriesContainer.RepositoryFor <SubjectStudent>().Save(subjectStudent);
                        repositoriesContainer.ApplyChanges();
                    }
                }
            }
        }
コード例 #35
0
        public ActionResult LoadObject(string name, HttpPostedFileBase file)
        {
            var guid = Guid.NewGuid().ToString();

            file.SaveAs(ScoFilePath + "\\" + guid + ".zip");

            using (ZipFile zip = ZipFile.Read(ScoFilePath + "\\" + guid + ".zip"))
            {
                Directory.CreateDirectory(ScoFilePath + "\\" + guid);
                zip.ExtractAll(ScoFilePath + "\\" + guid, ExtractExistingFileAction.OverwriteSilently);
            }

            if (!System.IO.File.Exists(ScoFilePath + "\\" + guid + "\\imsmanifest.xml"))
            {
                return(Json(new
                {
                    error = "Загруженный файл не является объектом SCORM"
                }));
            }

            System.IO.File.Delete(ScoFilePath + "\\" + guid + ".zip");

            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.RepositoryFor <ScoObjects>().Save(new ScoObjects()
                {
                    Name      = name,
                    Path      = guid,
                    Enabled   = false,
                    IsDeleted = false
                });
                repositoriesContainer.ApplyChanges();
            }

            return(Json(name, JsonRequestBehavior.AllowGet));
        }
コード例 #36
0
 public void UpdateProject(Project project)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         repositoriesContainer.ProjectsRepository.Save(project);
         repositoriesContainer.ApplyChanges();
     }
 }
コード例 #37
0
        public Project SaveProject(Project project)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.ProjectsRepository.Save(project);
                repositoriesContainer.ApplyChanges();
            }

            return project;
        }
コード例 #38
0
 public void SaveComment(ProjectComment comment)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         repositoriesContainer.ProjectCommentsRepository.Save(comment);
         repositoriesContainer.ApplyChanges();
     }
 }
コード例 #39
0
 //public void AssingRole(int userId, int projectId, int roleId)
 public void AssingRole(ProjectUser projectUser)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         repositoriesContainer.ProjectUsersRepository.Save(projectUser);
         repositoriesContainer.ApplyChanges();
     }
 }
コード例 #40
0
 public ActionResult UpdateObjects(bool enable, string path)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         var data = repositoriesContainer.RepositoryFor<ScoObjects>().GetBy(new Query<ScoObjects>(e => e.Path == path));
         data.Enabled = enable;
         repositoriesContainer.RepositoryFor<ScoObjects>().Save(data);
         repositoriesContainer.ApplyChanges();
     }
     return Json(enable, JsonRequestBehavior.AllowGet);
 }
コード例 #41
0
        public void CopyQuestionsToTest(int testId, int[] questionsIds)
        {
            CheckForTestIsNotLocked(testId);
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                var query = new Query<Question>(question => questionsIds.Contains(question.Id));
                query.Include(question => question.Answers);
                var questionsToCopy = repositoriesContainer.QuestionsRepository.GetAll(query);

                var copiedQuestions = new List<Question>();
                foreach (var questionToCopy in questionsToCopy)
                {
                    var copiedQuestion = questionToCopy.Clone() as Question;
                    copiedQuestion.TestId = testId;
                    copiedQuestions.Add(copiedQuestion);
                }
                   
                repositoriesContainer.QuestionsRepository.Save(copiedQuestions);
                repositoriesContainer.ApplyChanges();
            }
        }
コード例 #42
0
 private void SaveAnswerOnTestQuestion(AnswerOnTestQuestion answerOnTestQuestion)
 {
     using var repositoriesContainer = new LmPlatformRepositoriesContainer();
     repositoriesContainer.RepositoryFor <AnswerOnTestQuestion>().Save(answerOnTestQuestion);
     repositoriesContainer.ApplyChanges();
 }
コード例 #43
0
 public Lecturer UpdateLecturer(Lecturer lecturer)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         repositoriesContainer.LecturerRepository.Save(lecturer);
         var user = repositoriesContainer.UsersRepository.GetBy(new Query<User>(e => e.Id == lecturer.User.Id));
         user.Avatar = lecturer.User.Avatar;
         user.SkypeContact = lecturer.User.SkypeContact;
         user.Email = lecturer.User.Email;
         user.About = lecturer.User.About;
         user.Phone = lecturer.User.Phone;
         repositoriesContainer.UsersRepository.Save(user);
         repositoriesContainer.ApplyChanges();
     }
     new LecturerSearchMethod().UpdateIndex(lecturer);
     return lecturer;
 }
コード例 #44
0
 public Lecturer Save(Lecturer lecturer)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         repositoriesContainer.LecturerRepository.SaveLecturer(lecturer);
         repositoriesContainer.ApplyChanges();
     }
     return lecturer;
 }
コード例 #45
0
        public ActionResult LoadObject(string name, HttpPostedFileBase file)
        {
            var guid = Guid.NewGuid().ToString();
            file.SaveAs(ScoFilePath + "\\" + guid + ".zip");

            using (ZipFile zip = ZipFile.Read(ScoFilePath + "\\" + guid + ".zip"))
            {
                Directory.CreateDirectory(ScoFilePath + "\\" + guid);
                zip.ExtractAll(ScoFilePath + "\\" + guid, ExtractExistingFileAction.OverwriteSilently);
            }

            if (!System.IO.File.Exists(ScoFilePath + "\\" + guid + "\\imsmanifest.xml"))
            {
                return Json(new
                {
                    error = "Загруженный файл не является объектом SCORM"
                });
            }

            System.IO.File.Delete(ScoFilePath + "\\" + guid + ".zip");

            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.RepositoryFor<ScoObjects>().Save(new ScoObjects()
                {
                    Name = name,
                    Path = guid,
                    Enabled = false,
                    IsDeleted = false
                });
                repositoriesContainer.ApplyChanges();
            }

            return Json(name, JsonRequestBehavior.AllowGet);
        }
コード例 #46
0
 public UserMessages SetRead(int userMessageId)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         var message = repositoriesContainer.MessageRepository.GetUserMessage(userMessageId);
         message.IsRead = true;
         repositoriesContainer.ApplyChanges();
         return message;
     }
 }
コード例 #47
0
 public void DeleteProjectUser(int projectUserId)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         var projectUser = repositoriesContainer.ProjectUsersRepository.GetBy(new Query<ProjectUser>().AddFilterClause(u => u.Id == projectUserId));
         repositoriesContainer.ProjectUsersRepository.DeleteProjectUser(projectUser);
         repositoriesContainer.ApplyChanges();
     }
 }
コード例 #48
0
        public void DeleteQuestion(int id)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                Question questionToDelete = repositoriesContainer.QuestionsRepository.GetBy(
                    new Query<Question>(question => question.Id == id));

                CheckForTestIsNotLocked(questionToDelete.TestId);

                repositoriesContainer.QuestionsRepository.Delete(questionToDelete);
                repositoriesContainer.ApplyChanges();
            }
        }
コード例 #49
0
 //public void AssingRole(int userId, int projectId, int roleId)
 public void AssingRole(ProjectUser projectUser)
 {
     using var repositoriesContainer = new LmPlatformRepositoriesContainer();
     repositoriesContainer.ProjectUsersRepository.Save(projectUser);
     repositoriesContainer.ApplyChanges();
 }
コード例 #50
0
 public bool DeleteMessage(int messageId, int userId)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         var result = repositoriesContainer.MessageRepository.DeleteMessage(messageId, userId);
         repositoriesContainer.ApplyChanges();
         return result;
     }
 }
コード例 #51
0
 public void SaveComment(ProjectComment comment)
 {
     using var repositoriesContainer = new LmPlatformRepositoriesContainer();
     repositoriesContainer.ProjectCommentsRepository.Save(comment);
     repositoriesContainer.ApplyChanges();
 }