public void DeleteTutoringRelationship(string userId, string subjectId) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", userId).WithValue("subjectId", subjectId); string query = $@"MATCH (u:User)-[r:TUTORING]->(s:Subject) WHERE u.UserID=$userId AND s.SubjectID=$subjectId DELETE r"; var result = session.Run(query, parameters); } }
public Subject FindSubjectBySubjectCode(string subjectCode) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("subjectCode", subjectCode); string query = $@"MATCH (node:Subject) WHERE node.SubjectCode = $subjectCode RETURN node"; var result = session.Run(query, parameters); return(result.SingleOrDefault().Map <Subject>()); } }
public IEnumerable <Subject> GetSubjectsStudentHasPassed(string userID) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", userID); string query = $@"MATCH(n: User) -[r: ENROLLED_TO]->(s: Subject) WHERE n.UserID = $userId AND r.Grade > 1 RETURN s"; var result = session.Run(query, parameters); return(result.Map <Subject>()); } }
public IEnumerable <Subject> GetSubjectsStudentIsTutoring(string userId) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", userId); string query = $@"MATCH (n:User)-[:TUTORING]->(s:Subject) WHERE n.UserID=$userId RETURN s"; var result = session.Run(query, parameters); return(result.Map <Subject>()); } }
public Student CreateUserStudent(Student student) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithEntity("newNode", student); string query = $@"CREATE (node :User:Student $newNode ) RETURN node"; var result = session.Run(query, parameters); var stud = result.Single().Map <Student>(); return(stud); } }
public void CreateTeachesRelationshipWithCourseIDs(Guid teacherID, Guid courseID) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("teacherId", teacherID.ToString()) .WithValue("courseId", courseID.ToString()); string query = @"MATCH (teacher :Teacher { TeacherID: $teacherId}) MATCH (course :Course { CourseID: $courseId }) MERGE (teacher)-[:TEACHES]->(course)"; var result = session.Run(query, parameters); } }
public void AnonymizeStudentUser(string userID) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", userID); string query = $@"MATCH (n:User:Student) WHERE n.UserID = $userId SET n.InstagramName = 0, n.Email = 0, n.FirstName = 0, n.NeptunCode = 0, n.IsDisabled = 1, n.LastName = 0, n.GenderType = 2,n.MessengerName = 0,n.Password = 0"; var result = session.Run(query, parameters); } }
public void CreateAttendsToRelationShipWithCourse(Guid userID, Guid courseID) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", userID.ToString()) .WithValue("courseId", courseID.ToString()); string query = @"MATCH (stud :Student { UserID: $userId}) MATCH (course :Course { CourseID: $courseId }) MERGE (stud)-[:ATTENDS]->(course)"; var result = session.Run(query, parameters); } }
public void CreateBelongsToRelationshipToSubject(Guid courseID, Guid subjectID) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("courseId", courseID.ToString()) .WithValue("subjectId", subjectID.ToString()); string query = @"MATCH (course :Course { CourseID: $courseId }) MATCH (subject :Subject { SubjectID: $subjectId }) MERGE (course)-[:BELONGS_TO]->(subject)"; var result = session.Run(query, parameters); } }
public void UpdateUserDisabledPropertyByUserId(string ID, bool isDisabled) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", ID) .WithValue("isDisabled", isDisabled); string query = @"MATCH(n: User) WHERE n.UserID = $userId SET n.IsDisabled = $isDisabled"; var result = session.Run(query, parameters); } }
//creates public Course CreateCourseBelongingToSubject(Course course, string subjectCode) { var parameters = new Neo4jParameters().WithValue("subjectCode", subjectCode); string courseLiteralMap = course.GetCypherFormattedNodeParameters(); using (var session = Neo4jDriver.Session()) { string query = $@"MATCH (sub:Subject {{SubjectCode: $subjectCode }}) MERGE (sub)<-[r: BELONGS_TO]-(c: Course {{" + courseLiteralMap + @"}) RETURN c"; var result = session.Run(query, parameters); return(result.Single().Map <Course>()); } }
public void CreateEnrolledToRelationShipWithSubject(Guid userID, Guid subjectID, string semester) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", userID.ToString()) .WithValue("subjectId", subjectID.ToString()) .WithValue("semester", semester); string query = @"MATCH (stud:Student { UserID: $userId}) MATCH (subj: Subject { SubjectID: $subjectId}) MERGE (stud)-[r: ENROLLED_TO {Semester: $semester}]->(subj)"; var result = session.Run(query, parameters); } }
public User FindUserById(string userID) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userID", userID); string query = $@"MATCH (node:User) WHERE node.UserID = $userID RETURN node"; var result = session.Run(query, parameters); var resultList = result.ToList(); if (resultList.Count() != 1) { return(null); } return(resultList.Single().Map <User>()); } }
public Subject GetSubjectById(string subjectId) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("subjectId", subjectId); string query = $@"MATCH (node:Subject) WHERE node.SubjectID = $subjectId RETURN node"; var result = session.Run(query, parameters); var res = result.ToList(); if (res.Count == 0) { throw new NodeNotExistsException("Subject with given id does not exists"); } return(res.SingleOrDefault().Map <Subject>()); } }
public Student FindStudentByUserID(string userID) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", userID); string query = $@"MATCH (node:Student) WHERE node.UserID = $userId RETURN node"; var result = session.Run(query, parameters); var resultList = result.ToList(); if (resultList.Count == 0) { return(null); } return(resultList.Single().Map <Student>()); } }
public IEnumerable <Student> GetStudentsEnrolledToSubject(string subjectID) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("subjectId", subjectID); string query = $@"MATCH (s:Student)-[:ENROLLED_TO]->(sub:Subject) WHERE sub.SubjectID = $subjectId RETURN s"; var result = session.Run(query, parameters); var resultList = result.ToList(); if (resultList.Count == 0) { return(new List <Student>()); } return(resultList.Map <Student>()); } }
//public User FindUserByUserNameAndPassword(string username, string password) //{ // using (var session = Neo4jDriver.Session()) // { // var parameters = new Neo4jParameters().WithValue("username", username) // .WithValue("password", password); // string query = $@"MATCH (node:User) WHERE node.UserName = $username AND node.Password= $password RETURN node"; // var result = session.Run(query, parameters); // var resultList = result.ToList(); // if (resultList.Count() == 0) // { // return null; // } // return resultList.Single().Map<User>(); // } //} public List <string> GetUserLabelsByUserID(string userID) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", userID); string query = $@"MATCH (n:User) WHERE n.UserID = $userId UNWIND( labels(n)) as labels RETURN distinct labels"; var result = session.Run(query, parameters); var labels = result.Select(record => record[0].As <string>()).ToList(); return(labels); } }
public void CreateTeachesRelationshipWithCourseParams(string subjectCode, string courseCode, string semester, string teacherName) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("teacherName", teacherName) .WithValue("subjectCode", subjectCode) .WithValue("courseCode", courseCode) .WithValue("semester", semester); string query = @"MATCH (sub:Subject {SubjectCode:$subjectCode })<-[BELONGS_TO]- (course: Course { CourseCode: $courseCode, Semester:$semester}) MATCH (teacher: Teacher { Name:$teacherName}) MERGE (teacher)-[r: TEACHES]->(course)"; var result = session.Run(query, parameters); } }
public IEnumerable <Student> GetStudentsTutoringSubjectByID(string subjectId) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("subjectId", subjectId); string query = $@"MATCH (u:User)-[r:TUTORING]->(s:Subject) WHERE s.SubjectID=$subjectId return u"; var result = session.Run(query, parameters); var resultList = result.ToList(); if (resultList.Count == 0) { return(new List <Student>()); } return(resultList.Map <Student>()); } }
public override void Delete(User user, string ID) { using (var session = Neo4jDriver.Session()) { if (ID == null) { var param = new Neo4jParameters().WithValue("userName", user.UserName); string queryName = $@"MATCH (node:User) WHERE node.UserName =$userID DETACH DELETE node"; session.Run(queryName, param); } var parameters = new Neo4jParameters().WithValue("userID", ID); string query = $@"MATCH (node:User) WHERE node.UserID =$userID DETACH DELETE node"; session.Run(query, parameters); return; } }
public int GetStudentSemesterCount(string userId) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", userId); string query = $@"MATCH (u1:Student)-[r:ENROLLED_TO]->(:Subject) WHERE u1.UserID = $userId RETURN count(distinct r.Semester) as cnt"; var result = session.Run(query, parameters); var resultList = result.ToList(); if (resultList.Count == 0) { return(0); } return(resultList.Single().Map <int>()); } }
public IEnumerable <Student> GetStudentsCompletedSubjectWithGrade(string subjectID, int completedWithGrade) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("subjectId", subjectID).WithValue("grade", completedWithGrade); string query = @"MATCH (u2:Student)-[r:ENROLLED_TO]->(s:Subject) WHERE s.SubjectID =$subjectId AND r.Grade = $grade RETURN u2"; var result = session.Run(query, parameters); var resultList = result.ToList(); if (resultList.Count == 0) { return(new List <Student>()); } return(resultList.Map <Student>()); } }
public Subject UpdateSubject(Subject subject) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("subjectId", subject.SubjectID).WithEntity("props", subject); string query = $@"MATCH (n:Subject) WHERE n.SubjectID=$subjectId SET n += $props RETURN n"; var result = session.Run(query, parameters); var summary = result.Summary; if (summary.Notifications.Select(x => x.Description).Contains("Error")) { throw new NodeNotExistsException("Node to be updated does not exists."); } return(result.SingleOrDefault().Map <Subject>()); } }
public IEnumerable <Student> GetStudentsAttendedToSubject(string subjectID, string semester) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("subjectID", subjectID).WithValue("semester", semester); string query = $@"MATCH (stud:Student)-[r:ENROLLED_TO]->(sub:Subject) WHERE sub.SubjectID= $subjectID AND r.Semester = $semester RETURN stud"; var result = session.Run(query); var resultList = result.ToList(); if (resultList.Count == 0) { return(null); } var students = result.Map <Student>(); return(students); } }
public double GetStudentGradeAverage(string userId) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", userId); string query = $@"MATCH (u1:Student)-[r:ENROLLED_TO]->(:Subject) WHERE u1.UserID=$userId AND r.Grade is not null RETURN avg(distinct r.Grade) as avg"; var result = session.Run(query, parameters); var resultList = result.ToList(); if (resultList.Count == 0) { return(0.0); } return(resultList.Single().Map <double>()); } }
public IEnumerable <CourseCodeSubjectNameProjection> FindLabourCoursesWithSubjectStudentCurrentlyEnrolledTo(string userid, string currentSemester) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", userid) .WithValue("semester", currentSemester); string query = $@"MATCH (u:User)-[r:ATTENDS]->(c:Course) MATCH (c)-[:BELONGS_TO]->(s:Subject) WHERE u.UserID = $userId AND c.Semester = $semester AND (c.CourseType=1 OR c.CourseType=2) RETURN c.CourseID as CourseID, c.CourseCode +' - '+ s.Name+' ('+s.SubjectCode+')' as CourseCodeWithSubjectName"; var result = session.Run(query, parameters); return(result.Map((string CourseID, string CourseCodeWithSubjectName) => new CourseCodeSubjectNameProjection { CourseID = CourseID, CourseCodeWithSubjectName = CourseCodeWithSubjectName }).ToList()); } }
public void UpdateStudent(Student student) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", student.UserID) .WithValue("firstName", student.FirstName) .WithValue("lastName", student.LastName) .WithValue("email", student.Email) .WithValue("messenger", student.MessengerName) .WithValue("instagram", student.InstagramName) .WithValue("neptun", student.NeptunCode); string query = @"MATCH(n: User) WHERE n.UserID = $userId SET n.FirstName = $firstName,n.LastName = $lastName, n.Email =$email, n.MessengerName = $messenger, n.InstagramName = $instagram, n.NeptunCode=$neptun"; var result = session.Run(query, parameters); } }
public CourseIDSubjectIDProjection GetCourseWithSubject(string courseCode, string subjectCode, string semester) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("courseCode", courseCode) .WithValue("subjectCode", subjectCode) .WithValue("semester", semester); string query = @" MATCH (course:Course)-[r:BELONGS_TO]->(sub:Subject) WHERE course.Semester=$semester and course.CourseCode=$courseCode and sub.SubjectCode=$subjectCode RETURN course, sub "; var result = session.Run(query, parameters); var s = result.Single().Map((Course course, Subject subject) => new CourseIDSubjectIDProjection { CourseID = Guid.Parse(course.CourseID), SubjectID = Guid.Parse(subject.SubjectID) }); return(s); } }
public IEnumerable <Student> GetStudentsAttendingToCourseInCurrentSemester(string userId, string searchCourseId, string currentSemester) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("userId", userId) .WithValue("courseId", searchCourseId) .WithValue("semester", currentSemester); string query = $@"MATCH (u1:Student)-[:ATTENDS]->(c1:Course)<-[:ATTENDS]-(u2:Student) WHERE u1.UserID = $userId AND c1.Semester = $semester AND c1.CourseID = $courseId RETURN u2"; var result = session.Run(query, parameters); var resultList = result.ToList(); if (resultList.Count == 0) { return(new List <Student>()); } return(resultList.Map <Student>()); } }
public IEnumerable <Student> GetStudentsGoodInDiscipline(int goodInSubjecType, double betterThanAvg) { using (var session = Neo4jDriver.Session()) { var parameters = new Neo4jParameters().WithValue("discipline", goodInSubjecType) .WithValue("avgParam", betterThanAvg); string query = $@"MATCH (s:Student)-[r:ENROLLED_TO]->(sub:Subject) WHERE r.Grade IS NOT NULL AND sub.SubjectType =$discipline WITH avg(r.Grade) as avg, s as stud WHERE avg > $avgParam RETURN stud"; var result = session.Run(query, parameters); var resultList = result.ToList(); if (resultList.Count == 0) { return(new List <Student>()); } return(resultList.Map <Student>()); } }