public async Task <ActionResult> EditAsync(int animeid, int AnimeNum = -1)
        {
            try
            {
                if (_DBServices.HasAnimeID(animeid))
                {
                    //订阅动画
                    if (animeid != -1 && AnimeNum == -1)
                    {
                        var UID  = _userManager.GetUserId(HttpContext.User);
                        var info = await _DBServices.GetFirstAsync <AnimeUserInfo>(animeinfo => animeinfo.Users.Id == UID && animeinfo.SubAnime.AnimeID == animeid);

                        if (info == null)
                        {
                            var Anime = await _DBServices.GetFirstAsync <Anime>(anime => anime.AnimeID == animeid);

                            var User = await _userManager.GetUserAsync(HttpContext.User);

                            await _DBServices.AddAsync(new AnimeUserInfo
                            {
                                NowAnimeNum = 0,
                                SubAnime    = Anime,
                                Users       = User
                            });

                            List <string> json = new List <string> {
                                "true", "订阅成功"
                            };
                            return(Json(json));
                        }
                        else
                        {
                            List <string> json = new List <string> {
                                "false", "您已经定阅过"
                            };
                            return(Json(json));
                        }
                    }
                    //更新集数
                    if (AnimeNum != -1 && animeid != -1)
                    {
                        // 对传送过来的动画集数做检查
                        if (1 > AnimeNum)
                        {
                            return(new JsonResult("Error"));
                        }
                        var UID  = _userManager.GetUserId(HttpContext.User);
                        var info = await _DBServices.GetFirstAsync <AnimeUserInfo>(animeinfo => animeinfo.Users.Id == UID && animeinfo.SubAnime.AnimeID == animeid);

                        if (info == null)
                        {
                            return(Json(new List <string> {
                                "false", "没有订阅动画,请先订阅动画"
                            }));
                        }
                        info.NowAnimeNum = AnimeNum;
                        await _DBServices.UpdateAsync(info);

                        return(Json(new List <string> {
                            "true", "更改成功"
                        }));
                    }
                }
                return(Json("Error"));
            }
            catch
            {
                return(Json("Error"));
            }
        }
Beispiel #2
0
        public async Task <ActionResult> DetailsAsync(int id = -1)
        {
            //从数据库中读取数据
            if (!_DBServices.HasAnimeID(id))
            {
                return(NotFound());
            }
            var key = new KEY {
                Key = CacheKey.Anime_One(id).ToCharArray()
            };

            if (!_DBServices.GetDate(key, out Anime Anime))
            {
                Anime = await _DBServices.GetDateOneAsync <Anime>(db =>
                                                                  db.Where(a => a.AnimeID == id)
                                                                  .Include(a => a.Souce)
                                                                  .Include(a => a.Tags)
                                                                  .Include(a => a.AnimeComms));

                _DBServices.SetCache(key, Anime);
            }
            key = new KEY {
                Key = CacheKey.Blog_One_ByAnimeID(id).ToCharArray()
            };
            if (!_DBServices.GetDate(key, out ICollection <Blog> blogs))
            {
                blogs = await _DBServices.GetDateToListAsync <Blog>(db => db.Where(b => b.AnimeID == id).OrderByDescending(a => a.Time).Take(10));

                _DBServices.SetCache(key, blogs);
            }

            //初始化数据
            var userAnimeNumber          = 0;                               //动画观看集数
            var IsSignIn                 = false;                           //用户是否登录
            var IsSub                    = false;                           //用户是否订阅某动画
            var IsShowEdit               = false;                           //用户是否可以编辑
            ICollection <AnimeMemo> memo = new List <AnimeMemo>();          //用户写下的MEMO
            //未登录也可以显示:
            ICollection <Blog>       blog        = blogs.GetListDate();     //用户对该动画的长评短评
            ICollection <AnimeTag>   animeTags   = new List <AnimeTag>();   //动画的标签
            ICollection <AnimeSouce> animeSouces = new List <AnimeSouce>(); //动画的播放源
            ICollection <AnimeComm>  animeComms  = new List <AnimeComm>();  //动画的评论

            //var SubNum = 0;                                             //用户订阅量(暂时用不到呢)

            animeTags   = Anime.Tags;
            animeSouces = Anime.Souce;
            animeComms  = Anime.AnimeComms;
            if (Anime.AnimeNumUpdata())//计算动画集数
            {
                //需要更新动画信息
                _DBServices.SetCache(key, Anime);//全部的数据读取好之后,缓存一下
                await _DBServices.UpdateAsync(Anime);
            }
            //动画集数列表的相关计算
            AnimeNumberInfo animeNumberInfo = Anime.AnimeNumPage();

            if (!(IsSignIn = _signInManager.IsSignedIn(HttpContext.User))) //如果没登陆,后面的就不需要处理了
            {
                return(View(
                           viewName: "Bangumi_OneAnime",
                           model: new Bangumi_OneAnime
                {
                    Anime = Anime,
                    UserAnimeNumber = userAnimeNumber,
                    Memos = memo,
                    IsSub = IsSub,
                    IsSignIn = IsSignIn,
                    IsShowEdit = IsShowEdit,
                    Page = animeNumberInfo
                }
                           ));
            }
            //如果没有登陆,返回Null
            var userID = _userManager.GetUserId(HttpContext.User);

            //尝试读取缓存
            key = new KEY {
                Key = CacheKey.Anime_User_Info(userID, id).ToCharArray()
            };
            if (!_DBServices.GetDate(key, out AnimeUserInfo Infos))
            {
                Infos = await _DBServices.GetDateOneAsync <AnimeUserInfo>(db => db.Where(info => info.Users.Id == userID && info.SubAnime.AnimeID == id)
                                                                          .Include(info => info.Memos));

                _DBServices.SetCache(key, Infos);
            }
            if (Infos != null)//没有订阅
            {
                IsSub           = true;
                memo            = Infos.Memos;
                userAnimeNumber = Infos.NowAnimeNum;
            }
            //检查权限
            var EditAnime = await _authorizationService.AuthorizeAsync(HttpContext.User, Final.Yuri_Yuri4);

            IsShowEdit = EditAnime.Succeeded;

            return(View(
                       viewName: "Bangumi_OneAnime",
                       model: new Bangumi_OneAnime
            {
                Anime = Anime,
                UserAnimeNumber = userAnimeNumber,
                Memos = memo,
                IsSub = IsSub,
                IsSignIn = IsSignIn,
                IsShowEdit = IsShowEdit,
                Page = animeNumberInfo
            }
                       ));
        }