public List <SubjectNews> GetNewsByLector(int id) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); var subjects = repositoriesContainer.RepositoryFor <SubjectLecturer>() .GetAll(new Query <SubjectLecturer>(e => e.LecturerId == id)).Select( e => e.SubjectId).ToList(); var subjectsData = repositoriesContainer.RepositoryFor <SubjectLecturer>() .GetAll(new Query <SubjectLecturer>(e => e.LecturerId == id).Include(e => e.Subject)).ToList(); var news = repositoriesContainer.RepositoryFor <SubjectNews>().GetAll( new Query <SubjectNews>(e => subjects.Contains(e.SubjectId) && !e.Disabled)).ToList(); foreach (var subjectNewse in news) { subjectNewse.Subject = new Subject { Name = subjectsData.FirstOrDefault(e => e.SubjectId == subjectNewse.SubjectId).Subject.Name } } ; return(news); }
public void DeletePracticals(int id) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { var practicals = repositoriesContainer.PracticalRepository.GetBy( new Query <Practical>(e => e.Id == id).Include(e => e.StudentPracticalMarks)); var deleteFiles = repositoriesContainer.AttachmentRepository.GetAll( new Query <Attachment>(e => e.PathName == practicals.Attachments)).ToList(); var studentPracticalsMarks = repositoriesContainer.RepositoryFor <StudentPracticalMark>() .GetAll(new Query <StudentPracticalMark>(e => e.PracticalId == id)) .ToList(); foreach (var attachment in deleteFiles) { FilesManagementService.DeleteFileAttachment(attachment); } foreach (var mark in studentPracticalsMarks) { repositoriesContainer.RepositoryFor <StudentPracticalMark>().Delete(mark); } repositoriesContainer.ApplyChanges(); repositoriesContainer.PracticalRepository.Delete(practicals); repositoriesContainer.ApplyChanges(); } }
public void DeleteLabsVisitingDate(int id) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { var dateModelmarks = repositoriesContainer.RepositoryFor <ScheduleProtectionLabMark>() .GetAll(new Query <ScheduleProtectionLabMark>(e => e.ScheduleProtectionLabId == id)) .ToList(); foreach (var labsVisitMark in dateModelmarks) { repositoriesContainer.RepositoryFor <ScheduleProtectionLabMark>().Delete(labsVisitMark); } repositoriesContainer.ApplyChanges(); var dateModel = repositoriesContainer.RepositoryFor <ScheduleProtectionLabs>() .GetBy(new Query <ScheduleProtectionLabs>(e => e.Id == id)); repositoriesContainer.RepositoryFor <ScheduleProtectionLabs>().Delete(dateModel); repositoriesContainer.ApplyChanges(); } }
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(); }
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; } }
private int CloseTest(IEnumerable <AnswerOnTestQuestion> testAnswers, int userId) { int testId = testAnswers.First().TestId; TestPassResult testPassResult = GetTestPassResult(testId, userId); int points = GetResultPoints(testAnswers); testPassResult.Points = points; using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { repositoriesContainer.RepositoryFor <AnswerOnTestQuestion>().Delete(testAnswers); repositoriesContainer.RepositoryFor <TestPassResult>().Save(testPassResult); var savedTestUnlock = repositoriesContainer.TestUnlocksRepository.GetAll(new Query <TestUnlock>() .AddFilterClause(testUnlock => testUnlock.StudentId == userId && testUnlock.TestId == testId)) .SingleOrDefault(); if (!GetTest(testId).ForSelfStudy&& savedTestUnlock != null) { repositoriesContainer.TestUnlocksRepository.Delete(savedTestUnlock); } repositoriesContainer.ApplyChanges(); } return(points); }
public Question SaveQuestion(Question question) { CheckForTestIsNotLocked(question.TestId); ValidateQuestion(question); using var repositoriesContainer = new LmPlatformRepositoriesContainer(); repositoriesContainer.QuestionsRepository.Save(question); var 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 (var answer in question.Answers) { answer.QuestionId = question.Id; } repositoriesContainer.RepositoryFor <Answer>().Save(question.Answers); repositoriesContainer.RepositoryFor <Answer>().Delete(answersToDelete); repositoriesContainer.ApplyChanges(); return(question); }
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(); } }
private Tuple <int, int> CloseTest(IEnumerable <AnswerOnTestQuestion> testAnswers, int userId) { var testId = testAnswers.First().TestId; var testPassResult = GetTestPassResult(testId, userId); var points = GetResultPoints(testAnswers); var percent = GetPoints(testAnswers); testPassResult.Points = points; testPassResult.Percent = percent; using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { foreach (var answer in testAnswers) { answer.TestEnded = true; repositoriesContainer.RepositoryFor <AnswerOnTestQuestion>().Save(answer); } repositoriesContainer.RepositoryFor <TestPassResult>().Save(testPassResult); var savedTestUnlock = repositoriesContainer.TestUnlocksRepository.GetAll(new Query <TestUnlock>() .AddFilterClause(testUnlock => testUnlock.StudentId == userId && testUnlock.TestId == testId)) .SingleOrDefault(); if (!GetTest(testId).ForSelfStudy&& savedTestUnlock != null) { repositoriesContainer.TestUnlocksRepository.Delete(savedTestUnlock); } repositoriesContainer.ApplyChanges(); } return(new Tuple <int, int>(points, percent)); }
public bool DeleteUser(int id) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); var query = new Query <User>().AddFilterClause(u => u.Id == id).Include(u => u.ProjectUsers).Include(u => u.Student); 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); } if (user.Student != null) { var acp = user.Student.AssignedCourseProjects.Select(e => e.CourseProjectId); foreach (var acpId in acp) { CPManagementService.DeleteUserFromAcpProject(id, acpId); } var subjects = repositoriesContainer.RepositoryFor <SubjectStudent>() .GetAll(new Query <SubjectStudent>(e => e.StudentId == id)); foreach (var subjectS in subjects) { repositoriesContainer.RepositoryFor <SubjectStudent>().Delete(subjectS); } var diplomas = Context.AssignedDiplomProjects.Where(e => e.StudentId == id).ToList(); var diplomasRessList = Context.DiplomPercentagesResults.Where(e => e.StudentId == id).ToList(); foreach (var diploma in diplomas) { Context.AssignedDiplomProjects.Remove(diploma); Context.SaveChanges(); } foreach (var diplomasRes in diplomasRessList) { Context.DiplomPercentagesResults.Remove(diplomasRes); Context.SaveChanges(); } } CPManagementService.DeletePercenageAndVisitStatsForUser(id); repositoriesContainer.ApplyChanges(); var result = AccountManagementService.DeleteAccount(user.UserName); repositoriesContainer.ApplyChanges(); return(result); }
public void UpdateTinCanObject(bool enable, int id) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); var data = repositoriesContainer.RepositoryFor <TinCanObjects>().GetBy(new Query <TinCanObjects>(e => e.Id == id)); data.Enabled = enable; repositoriesContainer.RepositoryFor <TinCanObjects>().Save(data); repositoriesContainer.ApplyChanges(); }
public void UpdateUserLabFile(string userFileId, bool isReceived) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); var id = int.Parse(userFileId); var userFile = repositoriesContainer.RepositoryFor <UserLabFiles>() .GetBy(new Query <UserLabFiles>(e => e.Id == id)); userFile.IsReceived = isReceived; repositoriesContainer.RepositoryFor <UserLabFiles>().Save(userFile); }
public void EditTinCanObject(string name, string path) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); var data = repositoriesContainer.RepositoryFor <TinCanObjects>().GetBy(new Query <TinCanObjects>(e => e.Path == path)); data.Name = name; repositoriesContainer.RepositoryFor <TinCanObjects>().Save(data); repositoriesContainer.ApplyChanges(); }
public void DeleteTinCanObject(int id) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); var data = repositoriesContainer.RepositoryFor <TinCanObjects>().GetBy(new Query <TinCanObjects>(e => e.Id == id)); data.IsDeleted = true; repositoriesContainer.RepositoryFor <TinCanObjects>().Save(data); repositoriesContainer.ApplyChanges(); }
public void DeleteUserLabFile(int id) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { var model = repositoriesContainer.RepositoryFor <UserLabFiles>().GetBy(new Query <UserLabFiles>(e => e.Id == id)); repositoriesContainer.RepositoryFor <UserLabFiles>().Delete(model); repositoriesContainer.ApplyChanges(); } }
public void DisjoinOwnerLector(int subjectId, int lectorId) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); var relation = repositoriesContainer.RepositoryFor <SubjectLecturer>().GetBy( new Query <SubjectLecturer>(e => e.Owner.HasValue == false && e.LecturerId == lectorId && e.SubjectId == subjectId)); repositoriesContainer.RepositoryFor <SubjectLecturer>().Delete(relation); repositoriesContainer.ApplyChanges(); }
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)); }
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)); }
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); }
public List <UserLabFiles> GetUserLabFiles(int userId, int subjectId) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { if (userId == 0) { return(repositoriesContainer.RepositoryFor <UserLabFiles>().GetAll(new Query <UserLabFiles>(e => e.SubjectId == subjectId)).ToList()); } return(repositoriesContainer.RepositoryFor <UserLabFiles>().GetAll(new Query <UserLabFiles>(e => e.UserId == userId && e.SubjectId == subjectId)).ToList()); } }
private void StartNewTest(int testId, int userId) { var test = GetTest(testId); var questionsCount = test.CountOfQuestions > test.Questions.Count ? test.Questions.Count : test.CountOfQuestions; IEnumerable <Question> includedQuestions = null; if (test.ForNN) { includedQuestions = test.Questions.OrderBy(t => t.ConceptId).ThenBy(a => a.Id).ToList(); } else { var random = new Random(DateTime.Now.Millisecond); includedQuestions = test.Questions.OrderBy(t => random.Next()).Take(questionsCount); } var answersTemplate = new List <AnswerOnTestQuestion>(); var counter = 1; foreach (var includedQuestion in includedQuestions) { answersTemplate.Add(new AnswerOnTestQuestion { QuestionId = includedQuestion.Id, TestId = testId, UserId = userId, Number = counter++ }); } var testPassResult = GetTestPassResult(testId, userId) ?? new TestPassResult { TestId = testId, StudentId = userId }; testPassResult.StartTime = DateTime.UtcNow; using var repositoriesContainer = new LmPlatformRepositoriesContainer(); var toDelete = repositoriesContainer.RepositoryFor <AnswerOnTestQuestion>() .GetAll(new Query <AnswerOnTestQuestion>(x => x.TestId == testId && x.UserId == userId)); repositoriesContainer.RepositoryFor <AnswerOnTestQuestion>().Delete(toDelete); repositoriesContainer.RepositoryFor <AnswerOnTestQuestion>().Save(answersTemplate); repositoriesContainer.RepositoryFor <TestPassResult>().Save(testPassResult); repositoriesContainer.ApplyChanges(); }
public void UnConfirmationStudent(int studentId) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); var student = GetStudent(studentId); student.Confirmed = false; 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 subjectStudent = firstOrDefault.SubjectStudents.FirstOrDefault(e => e.StudentId == studentId); repositoriesContainer.RepositoryFor <SubjectStudent>().Delete(subjectStudent); repositoriesContainer.ApplyChanges(); } } } }
public void SavePracticalVisitingData(List <ScheduleProtectionPracticalMark> protectionPracticalMarks) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); repositoriesContainer.RepositoryFor <ScheduleProtectionPracticalMark>().Save(protectionPracticalMarks); repositoriesContainer.ApplyChanges(); }
public ActionResult GetObjects() { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { return(Json(repositoriesContainer.RepositoryFor <ScoObjects>().GetAll(new Query <ScoObjects>(e => !e.IsDeleted)).ToList(), JsonRequestBehavior.AllowGet)); } }
public void SavePracticalMarks(List <StudentPracticalMark> studentPracticalMarks) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); repositoriesContainer.RepositoryFor <StudentPracticalMark>().Save(studentPracticalMarks); repositoriesContainer.ApplyChanges(); }
public void DeleteNonReceivedUserFiles(int groupId) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); var studentsIds = repositoriesContainer.RepositoryFor <Student>() .GetAll(new Query <Student>(e => e.GroupId == groupId)).Select(x => x.User.Id).ToList(); foreach (var studentId in studentsIds) { var model = repositoriesContainer.RepositoryFor <UserLabFiles>() .GetAll(new Query <UserLabFiles>(e => e.UserId == studentId && !e.IsReceived)); repositoriesContainer.RepositoryFor <UserLabFiles>().Delete(model); } repositoriesContainer.ApplyChanges(); }
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); }
public void SaveScheduleProtectionPracticalDate(ScheduleProtectionPractical scheduleProtectionPractical) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); repositoriesContainer.RepositoryFor <ScheduleProtectionPractical>().Save(scheduleProtectionPractical); repositoriesContainer.ApplyChanges(); }
public void SaveStudentLabsMark(StudentLabMark studentLabMark) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); repositoriesContainer.RepositoryFor <StudentLabMark>().Save(studentLabMark); repositoriesContainer.ApplyChanges(); }
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; }
public void SaveMarksCalendarData(List <LecturesVisitMark> lecturesVisitMarks) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); repositoriesContainer.RepositoryFor <LecturesVisitMark>().Save(lecturesVisitMarks); repositoriesContainer.ApplyChanges(); }
public void SaveLabsVisitingData(ScheduleProtectionLabMark protectionLabMarks) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); repositoriesContainer.RepositoryFor <ScheduleProtectionLabMark>().Save(protectionLabMarks); repositoriesContainer.ApplyChanges(); }
public List <Lecturer> GetJoinedLector(int subjectId, int owner) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); return(repositoriesContainer.RepositoryFor <SubjectLecturer>().GetAll( new Query <SubjectLecturer>(e => e.SubjectId == subjectId && e.Owner == owner) .Include(e => e.Lecturer)).Select(e => e.Lecturer).ToList()); }
public ActionResult GetObjects() { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { return Json(repositoriesContainer.RepositoryFor<ScoObjects>().GetAll(new Query<ScoObjects>(e => !e.IsDeleted)).ToList(), JsonRequestBehavior.AllowGet); } }
public UserLabFiles GetUserLabFile(int id) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { return(repositoriesContainer.RepositoryFor <UserLabFiles>().GetBy(new Query <UserLabFiles>(e => e.Id == id))); } }
public void CheckForTestIsNotLocked(int testId) { var testsQuery = new Query<Test>(test => test.Id == testId) .Include(t => t.TestUnlocks); var answersQuery = new Query<AnswerOnTestQuestion>(a => a.TestId == testId); using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { if (repositoriesContainer.TestsRepository.GetBy(testsQuery).TestUnlocks.Count > 0 || repositoriesContainer.RepositoryFor<AnswerOnTestQuestion>().GetAll(answersQuery).Count() != 0) { throw new InvalidDataException("Тест не может быть изменён, т.к. доступен для прохождения"); } } }
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); }
public SubGroup GetSubGroup(int subGroupId) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { return repositoriesContainer.RepositoryFor<SubGroup>().GetBy(new Query<SubGroup>(e => e.Id == subGroupId) .Include(e => e.SubjectStudents.Select(x => x.Student.ScheduleProtectionLabMarks)).Include(e => e.SubjectGroup.Group)); } }
public UserLabFiles GetUserLabFile(int id) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { return repositoriesContainer.RepositoryFor<UserLabFiles>().GetBy(new Query<UserLabFiles>(e => e.Id == id)); } }
private int CloseTest(IEnumerable<AnswerOnTestQuestion> testAnswers, int userId) { int testId = testAnswers.First().TestId; TestPassResult testPassResult = GetTestPassResult(testId, userId); int points = GetResultPoints(testAnswers); testPassResult.Points = points; using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { repositoriesContainer.RepositoryFor<AnswerOnTestQuestion>().Delete(testAnswers); repositoriesContainer.RepositoryFor<TestPassResult>().Save(testPassResult); var savedTestUnlock = repositoriesContainer.TestUnlocksRepository.GetAll(new Query<TestUnlock>() .AddFilterClause(testUnlock => testUnlock.StudentId == userId && testUnlock.TestId == testId)) .SingleOrDefault(); if (!GetTest(testId).ForSelfStudy && savedTestUnlock != null) { repositoriesContainer.TestUnlocksRepository.Delete(savedTestUnlock); } repositoriesContainer.ApplyChanges(); } return points; }
private TestPassResult GetTestPassResult(int testId, int userId) { TestPassResult result; using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { result = repositoriesContainer.RepositoryFor<TestPassResult>().GetBy( new Query<TestPassResult>(res => res.TestId == testId && res.StudentId == userId)); } return result; }
/// <summary> /// Return records for current test or create /// </summary> private IEnumerable<PassedQuestionResult> GetControlItems(int testId, int userId) { List<AnswerOnTestQuestion> testAnswers; using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { IRepositoryBase<AnswerOnTestQuestion> repository = repositoriesContainer.RepositoryFor<AnswerOnTestQuestion>(); testAnswers = repository.GetAll( new Query<AnswerOnTestQuestion>( testAnswer => testAnswer.TestId == testId && testAnswer.UserId == userId)).ToList(); } if (!testAnswers.Any()) { return new PassedQuestionResult[0]; } return testAnswers.Select(GetQuestionStatus); }
public void SaveScheduleProtectionLabsDate(int subGroupId, DateTime date) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { repositoriesContainer.RepositoryFor<ScheduleProtectionLabs>().Save(new ScheduleProtectionLabs { SuGroupId = subGroupId, Date = date, Id = 0 }); repositoriesContainer.ApplyChanges(); } }
public void SavePracticalVisitingData(List<ScheduleProtectionPracticalMark> protectionPracticalMarks) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { repositoriesContainer.RepositoryFor<ScheduleProtectionPracticalMark>().Save(protectionPracticalMarks); repositoriesContainer.ApplyChanges(); } }
public void SavePracticalMarks(List<StudentPracticalMark> studentPracticalMarks) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { repositoriesContainer.RepositoryFor<StudentPracticalMark>().Save(studentPracticalMarks); repositoriesContainer.ApplyChanges(); } }
public void SaveMarksCalendarData(List<LecturesVisitMark> lecturesVisitMarks) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { repositoriesContainer.RepositoryFor<LecturesVisitMark>().Save(lecturesVisitMarks); repositoriesContainer.ApplyChanges(); } }
public void SaveDateLectures(int subjectId, DateTime date) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { repositoriesContainer.RepositoryFor<LecturesScheduleVisiting>().Save(new LecturesScheduleVisiting { Date = date, SubjectId = subjectId }); repositoriesContainer.ApplyChanges(); } }
public bool IsWorkingSubject(int userId, int subjectId) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { var subjectlect = repositoriesContainer.RepositoryFor<SubjectLecturer>() .GetAll(new Query<SubjectLecturer>(e => e.LecturerId == userId && e.SubjectId == subjectId)) .ToList(); return subjectlect.Any(); } }
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); }
public void SaveScheduleProtectionPracticalDate(ScheduleProtectionPractical scheduleProtectionPractical) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { repositoriesContainer.RepositoryFor<ScheduleProtectionPractical>().Save(scheduleProtectionPractical); repositoriesContainer.ApplyChanges(); } }
public void DeleteUserLabFile(int id) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { var model = repositoriesContainer.RepositoryFor<UserLabFiles>().GetBy(new Query<UserLabFiles>(e => e.Id == id)); repositoriesContainer.RepositoryFor<UserLabFiles>().Delete(model); repositoriesContainer.ApplyChanges(); } }
public void SaveStudentLabsMark(List<StudentLabMark> studentLabMark) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { repositoriesContainer.RepositoryFor<StudentLabMark>().Save(studentLabMark); repositoriesContainer.ApplyChanges(); } }
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(); } }
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; }
/// <summary> /// Return records for current test or create /// </summary> private List<AnswerOnTestQuestion> GetAnswersForTest(int testId, int userId) { List<AnswerOnTestQuestion> testAnswers; using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { IRepositoryBase<AnswerOnTestQuestion> repository = repositoriesContainer.RepositoryFor<AnswerOnTestQuestion>(); testAnswers = repository.GetAll( new Query<AnswerOnTestQuestion>( testAnswer => testAnswer.TestId == testId && testAnswer.UserId == userId)).ToList(); } if (!testAnswers.Any()) { StartNewTest(testId, userId); return GetAnswersForTest(testId, userId); } return testAnswers; }
public void DeleteLabsVisitingDate(int id) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { var dateModelmarks = repositoriesContainer.RepositoryFor<ScheduleProtectionLabMark>() .GetAll(new Query<ScheduleProtectionLabMark>(e => e.ScheduleProtectionLabId == id)) .ToList(); foreach (var labsVisitMark in dateModelmarks) { repositoriesContainer.RepositoryFor<ScheduleProtectionLabMark>().Delete(labsVisitMark); } repositoriesContainer.ApplyChanges(); var dateModel = repositoriesContainer.RepositoryFor<ScheduleProtectionLabs>() .GetBy(new Query<ScheduleProtectionLabs>(e => e.Id == id)); repositoriesContainer.RepositoryFor<ScheduleProtectionLabs>().Delete(dateModel); repositoriesContainer.ApplyChanges(); } }
public IPageableList<UserMessages> GetUserMessagesPageable(int userId, bool? incoming = null, string searchString = null, IPageInfo pageInfo = null, IEnumerable<ISortCriteria> sortCriterias = null) { var query = new PageableQuery<UserMessages>(pageInfo); if (!incoming.HasValue) { query.AddFilterClause(e => e.AuthorId == userId || e.Recipient.Id == userId); } else { if (incoming.Value) { query.AddFilterClause(e => e.Recipient.Id == userId); } else { query.AddFilterClause(e => e.AuthorId == userId); } } query.Include(e => e.Message.Attachments).Include(e => e.Recipient) .Include(e => e.Author.Lecturer).Include(e => e.Author.Student); if (!string.IsNullOrEmpty(searchString)) { query.AddFilterClause( e => e.Message.Text.ToLower().StartsWith(searchString) || e.Message.Text.ToLower().Contains(searchString)); } query.OrderBy(sortCriterias); using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { var userMessages = repositoriesContainer.RepositoryFor<UserMessages>().GetPageableBy(query); return userMessages; } }
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); }
public List<LecturesScheduleVisiting> GetScheduleVisitings(Query<LecturesScheduleVisiting> query) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { return repositoriesContainer.RepositoryFor<LecturesScheduleVisiting>() .GetAll(query.Include(e => e.LecturesVisitMarks.Select(x => x.Student.User))) .ToList(); } }
public List<UserLabFiles> GetUserLabFiles(int userId, int subjectId) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { if (userId == 0) { return repositoriesContainer.RepositoryFor<UserLabFiles>().GetAll(new Query<UserLabFiles>(e => e.SubjectId == subjectId)).ToList(); } return repositoriesContainer.RepositoryFor<UserLabFiles>().GetAll(new Query<UserLabFiles>(e => e.UserId == userId && e.SubjectId == subjectId)).ToList(); } }