public async Task <IReadOnlyCollection <SocialMediaImage> > FetchInstagramImages(Guid chapterId) { ChapterLinks links = await _chapterRepository.GetChapterLinks(chapterId); if (links == null) { throw new OdkNotFoundException(); } if (string.IsNullOrEmpty(links.InstagramName)) { return(new SocialMediaImage[0]); } IInstaApi api = await OpenApi(); PaginationParameters paginationParameters = PaginationParameters.MaxPagesToLoad(1); IResult <InstaMediaList> media = await api.GetUserMediaAsync(links.InstagramName, paginationParameters); return(media.Value .OrderByDescending(x => x.DeviceTimeStamp) .Where(x => x.Images.Count > 0) .Select(x => new SocialMediaImage { Caption = x.Caption.Text, ImageUrl = x.Images.OrderBy(img => img.Width).First().URI, Url = $"https://www.instagram.com/p/{x.Code}" }) .ToArray()); }
public async Task UpdateChapterLinks(Guid currentMemberId, Guid chapterId, UpdateChapterLinks links) { await AssertMemberIsChapterAdmin(currentMemberId, chapterId); ChapterLinks update = new ChapterLinks(chapterId, links.Facebook, links.Instagram, links.Twitter, 0); await _chapterRepository.UpdateChapterLinks(update); _cacheService.RemoveVersionedItem <ChapterLinks>(chapterId); }
public static ChapterLinkListToken ChapterLinkEntity2LinkListToken(this ChapterLinks entity) { return(new ChapterLinkListToken { name = entity.LinkText , url = entity.LinkHref , index = entity.Ordinal , kind = Utils.ParseEnum <CourseEnums.eChapterLinkKind>(entity.LinkType.ToString()) }); }
//chapter videos public static LinkListDto ChapterLinkEntity2ListDTO(this ChapterLinks entity) { return(new LinkListDto { id = entity.Id , ChapterId = entity.CourseChapterId , name = entity.LinkText , index = entity.Ordinal }); }
private async Task <ChapterLinks> GetChapterLinks(Guid chapterId) { ChapterLinks links = await _chapterRepository.GetChapterLinks(chapterId); if (links == null) { throw new OdkNotFoundException(); } return(links); }
public static ChapterLinkEditDTO ChapterLinkEntity2LinkEditDTO(this ChapterLinks entity) { return(new ChapterLinkEditDTO { LinkId = entity.Id , ChapterId = entity.CourseChapterId , Title = entity.LinkText , LinkHref = entity.LinkHref , OrderIndex = entity.Ordinal , Kind = Utils.ParseEnum <CourseEnums.eChapterLinkKind>(entity.LinkType.ToString()) // ,KindName = Utils.ParseEnum<CourseEnums.eChapterLinkKind>(entity.LinkType.ToString()).ToString() }); }
public async Task UpdateChapterLinks(ChapterLinks links) { int count = await Context .Select <ChapterLinks>() .Where(x => x.ChapterId).EqualTo(links.ChapterId) .CountAsync(); if (count > 0) { await Context .Update <ChapterLinks>() .Set(x => x.FacebookName, links.FacebookName) .Set(x => x.InstagramName, links.InstagramName) .Set(x => x.TwitterName, links.TwitterName) .Where(x => x.ChapterId).EqualTo(links.ChapterId) .ExecuteAsync(); } else { await Context .Insert(links) .ExecuteAsync(); } }
public static void UpdateChapterLinkEntityOrderIndex(this ChapterLinks entity, int index) { entity.Ordinal = index; entity.LastModified = DateTime.Now; }
public static void UpdateChapterLinkEntity(this ChapterLinks entity, ChapterLinkEditDTO dto) { entity.LinkText = dto.Title.TrimString(); entity.LinkHref = dto.LinkHref.FormatToFullUri(); entity.LastModified = DateTime.Now; }