Пример #1
0
        public CourseModel AddCourse(string code, string fullName, Guid authorId, Guid facultyId, string universityUrl, string url, string studyGroupUrl)
        {
            var codeStandardized     = _stringStandardizationService.StandardizeSearchText(code);
            var fullNameStandardized = _stringStandardizationService.StandardizeSearchText(fullName);

            var course = new CourseModel(Guid.NewGuid(), code, codeStandardized, fullName, fullNameStandardized, authorId, facultyId, universityUrl, url, studyGroupUrl);

            All.Add(course);

            return(course);
        }
        private Guid CreateCourse(string?code, string fullName, Guid studyGroupId, Guid authorId, string universityUrl, string url, string studyGroupUrl)
        {
            var course = new CourseModel(
                Guid.NewGuid(),
                code,
                code == null ? null : _stringStandardizationService.StandardizeSearchText(code),
                fullName,
                _stringStandardizationService.StandardizeSearchText(fullName),
                authorId,
                studyGroupId,
                universityUrl,
                url,
                studyGroupUrl);

            _uniwikiContext.Add(course);

            return(course.Id);
        }
Пример #3
0
 public IEnumerable <UniversityModel> SearchUniversities(string text)
 {
     return(GetUniversities().Where(u =>
                                    _stringStandardizationService.StandardizeSearchText(u.ShortName).Contains(text) ||
                                    _stringStandardizationService.StandardizeSearchText(u.LongName).Contains(text)));
 }
Пример #4
0
        protected override Task <GetSearchResultsResponseDto> ExecuteAsync(GetSearchResultsRequestDto request, RequestContext context)
        {
            // Get search text
            var searchText = _stringStandardizationService.StandardizeSearchText(request.SearchedText);

            // Log the search text
            _logger.LogInformation("Searching for text: '{Text}', standardized: '{StandardizedText}'", request.SearchedText, searchText);

            // Which should be found
            FoundCourseDto[] courseDtos;

            // Recent courses for the user
            RecentCourseDto[] recentCourseDtos = new RecentCourseDto[0];

            // Find the recent courses if the user is authenticated and did not type any text
            if (context.IsAuthenticated && string.IsNullOrWhiteSpace(searchText))
            {
                // TODO: Check efficiency of this - how many calls are made?
                // TODO: Fix
                recentCourseDtos =
                    _uniwikiContext
                    .CourseVisits
                    .Include(v => v.Course)
                    .Where(v => v.ProfileId == context.UserId !.Value)
                    .OrderByDescending(v => v.VisitDateTime)
                    .Select(v => v.Course) // This might cause a problem
                    .Distinct()
                    .ToRecentCourseDto()
                    .ToArray();
            }

            // Check if the user selected a study group
            if (request.StudyGroupId != null)
            {
                // Search just amongst the selected study group
                var coursesFromStudyGroup = _uniwikiContext
                                            .Courses
                                            .Include(c => c.StudyGroup)
                                            .ThenInclude(g => g.University)
                                            .Where(c => c.StudyGroupId.Equals(request.StudyGroupId));

                // find the courses
                var courses = FindCourses(coursesFromStudyGroup, searchText);

                courseDtos = courses.ToFoundCourses().ToArray();
            }
            else // User did not select a study group
            {
                // If the user did not type any text
                if (string.IsNullOrWhiteSpace(searchText))
                {
                    // Return empty results
                    courseDtos = new FoundCourseDto[0];
                }
                else // The user typed some text
                {
                    // Find the courses
                    courseDtos = FindCourses(_uniwikiContext.Courses, searchText).ToFoundCourses().ToArray();
                }
            }

            // Create the response
            var response = new GetSearchResultsResponseDto(recentCourseDtos, courseDtos);

            return(Task.FromResult(response));
        }