Пример #1
0
        /// <summary>
        /// Create bookmark
        /// </summary>
        /// <param name="bookmark"></param>
        /// <returns></returns>
        public async Task <BookmarkedCourse> CreateBookmark(BookmarkedCourse bookmark)
        {
            var existingBookmarks = await GetBookmarkedCoursesForUser(bookmark.User.UserId);

            if (existingBookmarks.Any(x => x.Course.CourseId == bookmark.Course.CourseId))
            {
                return(null);
            }

            var entity  = _mapper.Map <Enterprise.Entities.BookmarkedCourse>(bookmark);
            var results = await _bookmarkedCourseRepository.CreateBookmark(entity);

            return(_mapper.Map <BookmarkedCourse>(results));
        }
        /// <summary>
        /// Create bookmarks
        /// </summary>
        /// <returns></returns>
        private async Task EnsureBookmarkAsync()
        {
            var user = await _userRepository.GetUserByEmail("*****@*****.**");

            var bookmarks = await _bookmarkedCourseRepository.GetBookmarkedCoursesForUser(user.Id);

            if (bookmarks.Count == 0)
            {
                var course = await _courseRepository.GetCourseByCode("Illuminate Lms 101");

                var bookmark = new BookmarkedCourse
                {
                    User   = user,
                    Course = course
                };
                await _bookmarkedCourseRepository.CreateBookmark(bookmark);
            }
        }