Exemplo n.º 1
0
        async Task VirtualVoteOptionAsync(ApplicationDbContext Context, NormalOption option, int value)
        {
            string  UserID = UserManager.GetUserId(User);
            Profile Voter  = await Context
                             .Profiles
                             .Include(p => p.Missions)
                             .Where(p => p.ProfileID == UserID)
                             .FirstOrDefaultAsync();

            if (Voter.VirtualCoins < value)
            {
                ErrorMessage = "餘額不足";
                return;
            }

            //消耗虛擬貨幣
            Voter.VirtualCoins -= value;
            CheckMissionVote(Voter);
            Context.Attach(Voter).State = EntityState.Modified;

            var Voting = await Context
                         .Votings
                         .Where(v => v.VotingID == option.VotingID)
                         .FirstOrDefaultAsync();

            Voting.TotalCoins           += value;
            Context.Attach(Voting).State = EntityState.Modified;

            var episode = await Context
                          .Episodes.Where(e => e.EpisodeID == Voting.EpisodeID)
                          .FirstOrDefaultAsync();

            var novel = await Context
                        .Novels
                        .Where(n => n.NovelID == episode.NovelID)
                        .FirstOrDefaultAsync();

            novel.MonthlyCoins         += value;
            novel.TotalCoins           += value;
            Context.Attach(novel).State = EntityState.Modified;

            var Involving = await Context.Involvings
                            .Where(i => i.NovelID == novel.NovelID)
                            .Where(i => i.InvolverID == Voter.ProfileID)
                            .FirstOrDefaultAsync();

            if (Involving != null)
            {
                Involving.Value                 = value;
                Involving.MonthlyValue         += value;
                Involving.TotalValue           += value;
                Involving.LastTime              = DateTime.Now;
                Context.Attach(Involving).State = EntityState.Modified;
            }
            else
            {
                Involving newInvolving = new Involving()
                {
                    Value        = value,
                    MonthlyValue = value,
                    TotalValue   = value,
                    LastTime     = DateTime.Now,
                    InvolverID   = UserID,
                    NovelID      = novel.NovelID
                };
                Context.Involvings.Add(newInvolving);
            }
            option.TotalCoins           += value;
            Context.Attach(option).State = EntityState.Modified;
            await Context.SaveChangesAsync();
        }
Exemplo n.º 2
0
        async Task VoteOptionAsync(ApplicationDbContext Context, NormalOption option, int value)
        {
            string  UserID = UserManager.GetUserId(User);
            Profile Voter  = await Context
                             .Profiles
                             .Include(p => p.Missions)
                             .Where(p => p.ProfileID == UserID)
                             .FirstOrDefaultAsync();

            Profile Creator = await Context
                              .Profiles
                              .Where(p => p.ProfileID == option.OwnerID)
                              .FirstOrDefaultAsync();

            if (Voter.RealCoins < value)
            {
                ErrorMessage = "餘額不足";
                return;
            }

            var Voting = await Context
                         .Votings
                         .Where(v => v.VotingID == option.VotingID)
                         .FirstOrDefaultAsync();

            Voting.TotalCoins           += value;
            Context.Attach(Voting).State = EntityState.Modified;

            //主要用來判斷月收入的來源
            if (Voting.Policy == Voting.PolicyType.Liberty)
            {
                Creator.MonthlyCoins += (decimal)(value * 0.6);//自由模式,作者得60%分潤
            }
            else
            {
                Creator.MonthlyCoins += (decimal)(value * 0.7);//平等模式,作者得70%分潤
            }
            Context.Attach(Creator).State = EntityState.Modified;
            //消耗實體貨幣
            Voter.RealCoins -= value;
            CheckMissionVote(Voter);
            Context.Attach(Voter).State = EntityState.Modified;

            var episode = await Context
                          .Episodes.Where(e => e.EpisodeID == Voting.EpisodeID)
                          .FirstOrDefaultAsync();

            var novel = await Context
                        .Novels
                        .Where(n => n.NovelID == episode.NovelID)
                        .FirstOrDefaultAsync();

            novel.MonthlyCoins         += value;
            novel.TotalCoins           += value;
            Context.Attach(novel).State = EntityState.Modified;

            var Involving = await Context.Involvings
                            .Where(i => i.NovelID == novel.NovelID)
                            .Where(i => i.InvolverID == Voter.ProfileID)
                            .FirstOrDefaultAsync();

            if (Involving != null)
            {
                Involving.Value                 = value;
                Involving.MonthlyValue         += value;
                Involving.TotalValue           += value;
                Involving.LastTime              = DateTime.Now;
                Context.Attach(Involving).State = EntityState.Modified;
            }
            else
            {
                Involving newInvolving = new Involving()
                {
                    Value        = value,
                    MonthlyValue = value,
                    TotalValue   = value,
                    LastTime     = DateTime.Now,
                    InvolverID   = UserID,
                    NovelID      = novel.NovelID
                };
                Context.Involvings.Add(newInvolving);
            }
            option.TotalCoins           += value;
            Context.Attach(option).State = EntityState.Modified;

            await Context.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostMonthlyInvolveAsync(string id)
        {
            ProfileID = id;
            int InvolveValue = 150;

            await LoadAsync(id);

            if (UserID == null)
            {
                return(Challenge());
            }

            Follow existingFollow = await Context.Follows
                                    .Where(f => f.ProfileID == ProfileID)
                                    .Where(f => f.FollowerID == UserID)
                                    .FirstOrDefaultAsync();

            if (existingFollow == null)
            {
                Follow newFollow = new Follow
                {
                    FollowerID           = UserID,
                    NovelMonthlyInvolver = true,
                    UpdateTime           = DateTime.Now,
                    ProfileID            = ProfileID
                };
                Context.Follows.Add(newFollow);
            }
            else
            {
                if (existingFollow.NovelMonthlyInvolver)
                {
                    StatusMessage = "已經Involve過了,如要繼續Involve,可以使用直接Involve的功能";
                    return(Page());
                }
                existingFollow.NovelMonthlyInvolver  = true;
                existingFollow.UpdateTime            = DateTime.Now;
                Context.Attach(existingFollow).State = EntityState.Modified;
            }

            Profile Creator = await Context.Profiles
                              .Where(p => p.ProfileID == ProfileID)
                              .FirstOrDefaultAsync();

            if (Involver.RealCoins < InvolveValue)
            {
                StatusMessage = "Error: 帳戶餘額不足";
                return(Page());
            }
            Creator.MonthlyCoins          += (decimal)(InvolveValue * 0.6);//創作者每月Involve,作者得60%分潤
            Context.Attach(Creator).State  = EntityState.Modified;
            Involver.RealCoins            -= InvolveValue;
            Context.Attach(Involver).State = EntityState.Modified;

            Involving ExistingInvolving = await Context.Involvings
                                          .Where(i => i.ProfileID == ProfileID)
                                          .Where(i => i.InvolverID == UserID)
                                          .FirstOrDefaultAsync();

            if (ExistingInvolving != null)
            {
                ExistingInvolving.Value                 = InvolveValue;
                ExistingInvolving.MonthlyValue         += InvolveValue;
                ExistingInvolving.TotalValue           += InvolveValue;
                ExistingInvolving.LastTime              = DateTime.Now;
                Context.Attach(ExistingInvolving).State = EntityState.Modified;
            }
            else
            {
                Involving newInvolving = new Involving()
                {
                    Value        = InvolveValue,
                    MonthlyValue = InvolveValue,
                    TotalValue   = InvolveValue,
                    LastTime     = DateTime.Now,
                    InvolverID   = UserID,
                    ProfileID    = ProfileID
                };
                Context.Involvings.Add(newInvolving);
            }

            await Context.SaveChangesAsync();

            StatusMessage = "每月Involve成功,感謝以實體行動鼓勵創作";
            return(Page());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostSingleInvolveAsync(string id)
        {
            ProfileID = id;
            await LoadAsync(ProfileID);

            if (UserID == null)
            {
                return(Challenge());
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (Profile == null)
            {
                return(NotFound());
            }

            Profile Involver = await Context.Profiles
                               .Where(p => p.ProfileID == UserID)
                               .FirstOrDefaultAsync();

            Profile Creator = Profile;

            if (Involver.RealCoins < Involving.Value)
            {
                ModelState.AddModelError(Involving.Value.ToString(), "帳戶餘額不足");
                return(Page());
            }
            Creator.MonthlyCoins          += (decimal)(Involving.Value * 0.5);//創作者直接贊助,作者得50%分潤
            Context.Attach(Creator).State  = EntityState.Modified;
            Involver.RealCoins            -= Involving.Value;
            Context.Attach(Involver).State = EntityState.Modified;

            Involving ExistingInvolving = await Context.Involvings
                                          .Where(i => i.ProfileID == ProfileID)
                                          .Where(i => i.InvolverID == UserID)
                                          .FirstOrDefaultAsync();

            if (ExistingInvolving != null)
            {
                ExistingInvolving.Value                 = Involving.Value;
                ExistingInvolving.MonthlyValue         += Involving.Value;
                ExistingInvolving.TotalValue           += Involving.Value;
                ExistingInvolving.LastTime              = DateTime.Now;
                Context.Attach(ExistingInvolving).State = EntityState.Modified;
            }
            else
            {
                Involving newInvolving = new Involving()
                {
                    Value        = Involving.Value,
                    MonthlyValue = Involving.Value,
                    TotalValue   = Involving.Value,
                    LastTime     = DateTime.Now,
                    InvolverID   = UserID,
                    ProfileID    = ProfileID
                };
                Context.Involvings.Add(newInvolving);
            }
            await Context.SaveChangesAsync();

            StatusMessage = "Involve成功,總共" + Involving.Value + " In幣,感謝以實體行動鼓勵創作";
            return(Page());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            ArticleID = id;
            await LoadAsync(ArticleID);

            if (UserID == null)
            {
                return(Challenge());
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (Article == null)
            {
                return(NotFound());
            }

            Profile Involver = await Context.Profiles
                               .Where(p => p.ProfileID == UserID)
                               .FirstOrDefaultAsync();

            Profile Creator = await Context.Profiles
                              .Where(p => p.ProfileID == Article.ProfileID)
                              .FirstOrDefaultAsync();

            if (Involver.RealCoins < Involving.Value)
            {
                ModelState.AddModelError(Involving.Value.ToString(), "帳戶餘額不足");
                return(Page());
            }
            Creator.MonthlyCoins          += (decimal)(Involving.Value * 0.5);//文章直接贊助,作者得50%分潤
            Context.Attach(Creator).State  = EntityState.Modified;
            Involver.RealCoins            -= Involving.Value;
            Context.Attach(Involver).State = EntityState.Modified;

            Article.MonthlyCoins         += Involving.Value;
            Article.TotalCoins           += Involving.Value;
            Context.Attach(Article).State = EntityState.Modified;

            Involving ExistingInvolving = await Context.Involvings
                                          .Where(i => i.ArticleID == ArticleID)
                                          .Where(i => i.InvolverID == UserID)
                                          .FirstOrDefaultAsync();

            if (ExistingInvolving != null)
            {
                ExistingInvolving.Value                 = Involving.Value;
                ExistingInvolving.MonthlyValue         += Involving.Value;
                ExistingInvolving.TotalValue           += Involving.Value;
                ExistingInvolving.LastTime              = DateTime.Now;
                Context.Attach(ExistingInvolving).State = EntityState.Modified;
            }
            else
            {
                Involving newInvolving = new Involving()
                {
                    Value        = Involving.Value,
                    MonthlyValue = Involving.Value,
                    TotalValue   = Involving.Value,
                    LastTime     = DateTime.Now,
                    InvolverID   = UserID,
                    ArticleID    = ArticleID
                };
                Context.Involvings.Add(newInvolving);
            }
            await Context.SaveChangesAsync();

            return(RedirectToPage("/Articles/Details", "OnGet", new { id = Article.ArticleID }));
        }