Exemplo n.º 1
0
        public async Task <ActionResult> DetailsAsync(string id)
        {
            var Image = await _DBService.GetFirstAsync <FileImages>(img => img.ImageID.Contains(id));

            if (Image == null)
            {
                return(StatusCode((int)HttpStatusCode.NotFound));
            }
            else
            {
                var ReadUser = Image.ReadUsers;
                if (string.IsNullOrEmpty(ReadUser) || string.IsNullOrWhiteSpace(ReadUser))
                {
                    // 公开权限的图片
                    byte[] Data = await System.IO.File.ReadAllBytesAsync(Image.ImagePath);

                    return(File(Data, MediaTypeNames.Image.Jpeg));
                }
                else
                {
                    var UserID            = _userManager.GetUserId(HttpContext.User);
                    HashSet <string> Read = new HashSet <string>(ReadUser.Split(','));
                    if (Read.Contains(UserID))
                    {
                        byte[] Data = await System.IO.File.ReadAllBytesAsync(Image.ImagePath);

                        return(File(Data, MediaTypeNames.Image.Jpeg));
                    }
                    else
                    {
                        return(StatusCode((int)HttpStatusCode.Forbidden));
                    }
                }
            }
        }
Exemplo n.º 2
0
        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"));
            }
        }