public List<MetroContract_Comment> GetTraktCommentsForAnime(int animeID, int maxRecords) { List<MetroContract_Comment> comments = new List<MetroContract_Comment>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { Trakt_FriendRepository repFriends = new Trakt_FriendRepository(); List<TraktV2Comment> commentsTemp = TraktTVHelper.GetShowCommentsV2(session, animeID); if (commentsTemp == null || commentsTemp.Count == 0) return comments; int cnt = 0; foreach (TraktV2Comment sht in commentsTemp) { MetroContract_Comment comment = new MetroContract_Comment(); Trakt_Friend traktFriend = repFriends.GetByUsername(session, sht.user.username); // user details Contract_Trakt_User user = new Contract_Trakt_User(); if (traktFriend == null) comment.UserID = 0; else comment.UserID = traktFriend.Trakt_FriendID; comment.UserName = sht.user.username; // shout details comment.CommentText = sht.comment; comment.IsSpoiler = sht.spoiler; comment.CommentDate = sht.CreatedAtDate; //shout.ImageURL = sht.user.avatar; comment.CommentType = (int)WhatPeopleAreSayingType.TraktComment; comment.Source = "Trakt"; cnt++; comments.Add(comment); if (cnt == maxRecords) break; } if (comments.Count > 0) { List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>(); sortCriteria.Add(new SortPropOrFieldAndDirection("ShoutDate", false, SortType.eDateTime)); comments = Sorting.MultiSort<MetroContract_Comment>(comments, sortCriteria); } } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return comments; }
public List<MetroContract_Comment> GetAniDBRecommendationsForAnime(int animeID, int maxRecords) { List<MetroContract_Comment> contracts = new List<MetroContract_Comment>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { AniDB_RecommendationRepository repBA = new AniDB_RecommendationRepository(); int cnt = 0; foreach (AniDB_Recommendation rec in repBA.GetByAnimeID(session, animeID)) { MetroContract_Comment shout = new MetroContract_Comment(); shout.UserID = rec.UserID; shout.UserName = ""; // shout details shout.CommentText = rec.RecommendationText; shout.IsSpoiler = false; shout.CommentDate = null; shout.ImageURL = string.Empty; AniDBRecommendationType recType = (AniDBRecommendationType)rec.RecommendationType; switch (recType) { case AniDBRecommendationType.ForFans: shout.CommentType = (int)WhatPeopleAreSayingType.AniDBForFans; break; case AniDBRecommendationType.MustSee: shout.CommentType = (int)WhatPeopleAreSayingType.AniDBMustSee; break; case AniDBRecommendationType.Recommended: shout.CommentType = (int)WhatPeopleAreSayingType.AniDBRecommendation; break; } shout.Source = "AniDB"; cnt++; contracts.Add(shout); if (cnt == maxRecords) break; } return contracts; } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return contracts; } }
public List<MetroContract_Comment> GetTraktCommentsForAnime(int animeID, int maxRecords) { List<MetroContract_Comment> comments = new List<MetroContract_Comment>(); try { using (var session = DatabaseFactory.SessionFactory.OpenSession()) { List<TraktV2Comment> commentsTemp = TraktTVHelper.GetShowCommentsV2(session, animeID); if (commentsTemp == null || commentsTemp.Count == 0) return comments; int cnt = 0; foreach (TraktV2Comment sht in commentsTemp) { MetroContract_Comment comment = new MetroContract_Comment(); Trakt_Friend traktFriend = RepoFactory.Trakt_Friend.GetByUsername(session, sht.user.username); // user details Contract_Trakt_User user = new Contract_Trakt_User(); if (traktFriend == null) comment.UserID = 0; else comment.UserID = traktFriend.Trakt_FriendID; comment.UserName = sht.user.username; // shout details comment.CommentText = sht.comment; comment.IsSpoiler = sht.spoiler; comment.CommentDate = sht.CreatedAtDate; //shout.ImageURL = sht.user.avatar; comment.CommentType = (int) WhatPeopleAreSayingType.TraktComment; comment.Source = "Trakt"; cnt++; comments.Add(comment); if (cnt == maxRecords) break; } comments = comments.OrderBy(a => a.CommentDate).ToList(); } } catch (Exception ex) { logger.Error( ex,ex.ToString()); } return comments; }