public GetCourseResponseDto(string?focusedPostType, PostViewModel[] posts, FilterPostTypeDto[] filterPostTypes, Guid courseId, string?[] newPostPostTypes, bool canFetchMore, RecentCourseDto recentCourse, string courseLongName, string courseUniversityAndFaculty) { FocusedPostType = focusedPostType; Posts = posts.ToList(); FilterPostTypes = filterPostTypes; CourseId = courseId; NewPostPostTypes = newPostPostTypes; CanFetchMore = canFetchMore; RecentCourse = recentCourse; CourseLongName = courseLongName; CourseUniversityAndFaculty = courseUniversityAndFaculty; }
public async Task SetRecentCourse(RecentCourseDto course) { // Get recent courses first var recentCourses = (await GetRecentCourses()).ToList(); // Remove the course in case its there already. Use Url for mapping the courses, that is better for recentCourses.RemoveAll( c => c.UniversityUrl == course.UniversityUrl && c.StudyGroupUrl == course.StudyGroupUrl && c.CourseUrl == course.CourseUrl); // Add to recent courses again recentCourses.Add(course); // Take only the last X elements var recentCoursesArray = recentCourses.TakeLast(Constants.NumberOrRecentCourses).ToArray(); // Serialize courses var serializedRecentCourses = JsonConvert.SerializeObject(recentCoursesArray); // Save it to the storage await _localStorageService.SetItemAsync(RecentCoursesKey, serializedRecentCourses); }
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)); }