Beispiel #1
0
        public async Task <IEnumerable <FilmProductionRating> > GetUserFilmProductionsAsync(string username, WatchingStatus status, int page, string userId)
        {
            int filmProductionsPerPage = 100;

            return(await _userFilmProductionsRepository.GetUserFilmProductionsAsync(username, userId, status, page *filmProductionsPerPage - 100, filmProductionsPerPage));
        }
Beispiel #2
0
        public async Task <IEnumerable <FilmProductionRating> > GetUserFilmProductionsAsync(string username, string userId, WatchingStatus status, int from, int to)
        {
            int?lastId = null;

            try
            {
                lastId = await _mySerialListDBContext.WatchingFilmProductionStatuses
                         .Include(w => w.User)
                         .Where(u => u.User.UserName == username)
                         .Where(u => u.WatchingStatus == status)
                         .OrderBy(u => u.Id)
                         .Select(u => u.Id)
                         .LastOrDefaultAsync();
            }
            catch { }

            IAsyncEnumerable <WatchingFilmProductionStatus> i = _mySerialListDBContext.WatchingFilmProductionStatuses
                                                                .Include(w => w.User)
                                                                .Include(w => w.FilmProduction)
                                                                .ThenInclude(w => w.Reviews)
                                                                .Include(w => w.FilmProduction)
                                                                .ThenInclude(f => f.Episodes)
                                                                .Where(u => u.User.UserName == username)
                                                                .Where(u => u.WatchingStatus == status)
                                                                .OrderBy(u => u.Id)
                                                                .Skip(from)
                                                                .Take(to)
                                                                .ToAsyncEnumerable();

            return(await i.Select(u => new FilmProductionRating
            {
                FilmProductionId = u.FilmProductionId,
                Poster = u.FilmProduction.Poster,
                Rating = Average(u.FilmProduction),
                Title = u.FilmProduction.Title,
                Released = u.FilmProduction.Released,
                Genre = u.FilmProduction.Genre,
                IsSeries = u.FilmProduction.IsSeries,
                Plot = u.FilmProduction.Plot,
                Votes = u.FilmProduction.Reviews?.Count() ?? 1,
                Seasons = u.FilmProduction.Episodes.Any() ? (int?)u.FilmProduction.Episodes.OrderByDescending(k => k.Season).Select(s => s.Season).FirstOrDefault() : null,
                Last = u.Id == lastId.Value,
                MyRating = u.FilmProduction.Reviews.Where(r => r.User.UserName == username).Select(r => r.Grade).FirstOrDefault(),
                TotalEpisodes = u.FilmProduction.Episodes.Any() ? u.FilmProduction.Episodes.Count() : 0,
                WatchedEpisodes = u.FilmProduction.IsSeries ? u.Episodes : 0,
                CurrentUserItem = userId != null ? userId == u.UserId : false
            }).ToList());
        }
Beispiel #3
0
 public async Task <ActionResult <IEnumerable <FilmProductionRating> > > GetFilmProductionsAsync(string username, int page = 1, WatchingStatus status = WatchingStatus.Current)
 {
     return(Ok(await _userFilmProductionsService.GetUserFilmProductionsAsync(username, status, page, User.Identity.Name)));
 }
Beispiel #4
0
        /// <summary>
        /// 显示用户收视进度列表。
        /// </summary>
        /// <param name="watchingListCollection"></param>
        /// <returns></returns>
        public static async Task PopulateWatchingListAsync(ObservableCollection <WatchingStatus> watchingListCollection)
        {
            try
            {
                //从文件反序列化
                var PreWatchings = JsonConvert.DeserializeObject <List <WatchingStatus> >(await FileHelper.ReadFromCacheFileAsync("JsonCache\\home"));
                if (PreWatchings != null)
                {
                    foreach (var sub in PreWatchings)
                    {
                        // 将Collection中没有的添加进去
                        if (watchingListCollection.Where(e => e.subject_id == sub.subject_id).Count() == 0)
                        {
                            watchingListCollection.Add(sub);
                        }
                    }
                }
                //else
                //{
                //    watchingListCollection.Clear();
                //}

                var watchingList = await BangumiHttpWrapper.GetWatchingListAsync(OAuthHelper.MyToken.UserId);

                var deletedItems = new List <WatchingStatus>(); //标记要删除的条目
                foreach (var sub in watchingListCollection)
                {
                    //根据最新的进度删除原有条目
                    if (watchingList.Where(e => e.SubjectId == sub.subject_id).Count() == 0)
                    {
                        deletedItems.Add(sub);
                    }
                }
                foreach (var item in deletedItems) //删除条目
                {
                    watchingListCollection.Remove(item);
                }

                foreach (var watching in watchingList)
                {
                    //若在看含有原来没有的条目则新增,之后再细化
                    var item = watchingListCollection.Where(e => e.subject_id == watching.SubjectId).FirstOrDefault();
                    if (item == null)
                    {
                        WatchingStatus watchingStatus = new WatchingStatus();
                        watchingStatus.name        = watching.Subject.Name;
                        watchingStatus.name_cn     = watching.Subject.NameCn;
                        watchingStatus.image       = watching.Subject.Images.Common;
                        watchingStatus.subject_id  = watching.SubjectId;
                        watchingStatus.url         = watching.Subject.Url;
                        watchingStatus.ep_color    = "Gray";
                        watchingStatus.lasttouch   = 0;
                        watchingStatus.watched_eps = watching.EpStatus.ToString();
                        watchingStatus.eps_count   = watching.Subject.EpsCount.ToString();

                        watchingListCollection.Add(watchingStatus);
                    }
                }
                foreach (var watching in watchingList)
                {
                    var item = watchingListCollection.Where(e => e.subject_id == watching.SubjectId).FirstOrDefault();
                    if (item != null)
                    {
                        item.isUpdating = true;
                        // 首次更新
                        if (item.lasttouch == 0)
                        {
                            // 获取EP详细信息
                            var subject = await BangumiHttpWrapper.GetSubjectEpsAsync(item.subject_id.ToString());

                            var progress = await BangumiHttpWrapper.GetProgressesAsync(OAuthHelper.MyToken.UserId, OAuthHelper.MyToken.Token, item.subject_id.ToString());

                            item.eps = new List <SimpleEp>();
                            foreach (var ep in subject.Eps.OrderBy(c => c.Type))
                            {
                                SimpleEp simpleEp = new SimpleEp();
                                simpleEp.id     = ep.Id;
                                simpleEp.sort   = ep.Sort;
                                simpleEp.status = ep.Status;
                                simpleEp.type   = ep.Type;
                                simpleEp.name   = ep.NameCn == "" ? ep.Name : ep.NameCn;
                                item.eps.Add(simpleEp);
                            }
                            if (item.eps.Where(e => e.status == "NA").Count() == 0)
                            {
                                item.eps_count = "全" + item.eps.Count + "话";
                            }
                            else
                            {
                                item.eps_count = "更新到第" + (item.eps.Count - item.eps.Where(e => e.status == "NA").Count()) + "话";
                            }
                            if (progress != null)
                            {
                                item.next_ep     = progress.Eps.Count + 1;
                                item.watched_eps = "看到第" + progress.Eps.Count + "话";
                                if (progress.Eps.Count < (item.eps.Count - item.eps.Where(e => e.status == "NA").Count()))
                                {
                                    item.ep_color = "#d26585";
                                }
                                else
                                {
                                    item.ep_color = "Gray";
                                }
                                foreach (var ep in item.eps) //用户观看状态
                                {
                                    foreach (var p in progress.Eps)
                                    {
                                        if (p.Id == ep.id)
                                        {
                                            ep.status = p.Status.CnName;
                                            progress.Eps.Remove(p);
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                item.next_ep     = 1;
                                item.watched_eps = "尚未观看";
                                item.ep_color    = "#d26585";
                            }
                            item.lasttouch = watching.LastTouch;
                        }
                        else
                        {
                            // 对条目有 修改 或 当天更新 或 未知更新星期 的进行更新
                            if (item.lasttouch != watching.LastTouch || watching.Subject.AirWeekday == GetDayOfWeek() + 1 || watching.Subject.AirWeekday == 0)
                            {
                                var subject = await BangumiHttpWrapper.GetSubjectEpsAsync(item.subject_id.ToString());

                                item.eps.Clear();
                                foreach (var ep in subject.Eps)
                                {
                                    SimpleEp simpleEp = new SimpleEp();
                                    simpleEp.id     = ep.Id;
                                    simpleEp.sort   = ep.Sort;
                                    simpleEp.status = ep.Status;
                                    simpleEp.type   = ep.Type;
                                    simpleEp.name   = ep.NameCn == "" ? ep.Name : ep.NameCn;
                                    item.eps.Add(simpleEp);
                                }
                                if (item.eps.Where(e => e.status == "NA").Count() == 0)
                                {
                                    item.eps_count = "全" + item.eps.Count + "话";
                                }
                                else
                                {
                                    item.eps_count = "更新到第" + (item.eps.Count - item.eps.Where(e => e.status == "NA").Count()) + "话";
                                }

                                var progress = await BangumiHttpWrapper.GetProgressesAsync(OAuthHelper.MyToken.UserId, OAuthHelper.MyToken.Token, item.subject_id.ToString());

                                if (progress != null)
                                {
                                    if (item.eps.Count == progress.Eps.Count)
                                    {
                                        item.next_ep = 0;
                                    }
                                    else
                                    {
                                        item.next_ep = progress.Eps.Count + 1;
                                    }
                                    item.watched_eps = "看到第" + progress.Eps.Count + "话";
                                    if (progress.Eps.Count < (item.eps.Count - item.eps.Where(e => e.status == "NA").Count()))
                                    {
                                        item.ep_color = "#d26585";
                                    }
                                    else
                                    {
                                        item.ep_color = "Gray";
                                    }
                                    foreach (var ep in item.eps) //用户观看状态
                                    {
                                        foreach (var p in progress.Eps)
                                        {
                                            if (p.Id == ep.id)
                                            {
                                                ep.status = p.Status.CnName;
                                                progress.Eps.Remove(p);
                                                break;
                                            }
                                            else
                                            {
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    item.next_ep     = 1;
                                    item.watched_eps = "尚未观看";
                                    item.ep_color    = "#d26585";
                                }

                                item.lasttouch = watching.LastTouch;
                            }
                        }
                        item.isUpdating = false;
                    }
                }
            }
            catch (Exception e)
            {
                foreach (var item in watchingListCollection.Where(i => i.isUpdating == true))
                {
                    item.isUpdating = false;
                }
                Debug.WriteLine("显示用户收视进度列表失败。");
                Debug.WriteLine(e.Message);
                throw e;
            }
        }