コード例 #1
0
ファイル: PostService.cs プロジェクト: andyvauliln/BitDiamond
        public Operation <Post> ArchivePost(long id)
        => _auth.AuthorizeAccess(this.PermissionProfile <IPostService>(UserContext.CurrentUser()), () =>
        {
            var post = _query.GetPostById(id).ThrowIfNull("Invalid post");

            post.Status = PostStatus.Archived;
            return(_pcommand.Update(post));
        });
コード例 #2
0
        public Operation <Notification> ClearNotification(long notificationId)
        => _auth.AuthorizeAccess(UserContext.CurrentPPP(), () =>
        {
            var notification = _query.GetNotificationById(notificationId)
                               .ThrowIfNull("Notification not found")
                               .ThrowIf(_n => _n.Target.UserId != UserContext.CurrentUser().UserId, "Invalid notification found");

            notification.Seen = true;
            return(_pcommand.Update(notification));
        });
コード例 #3
0
        public Operation ModifySetting(string settingName, string settingValue)
        => _auth.AuthorizeAccess(UserContext.CurrentPPP(), () =>
        {
            var setting  = _query.GetSetting(settingName).ThrowIfNull($"Setting '{settingName}' does not exist");
            setting.Data = settingValue;

            _pcommand.Update(setting).Resolve();
        });
コード例 #4
0
        public Operation VerifyContext(string userId, string verificationContext, string token)
        => _authorizer.AuthorizeAccess(UserContext.CurrentProcessPermissionProfile(), () =>
        {
            var cv = _query.GetContextVerification(userId, verificationContext, token)
                     .ThrowIf(_cv => _cv == null || _cv.Verified, "verification token is invalid");

            cv.Verified = true;
            _pcommand.Update(cv).Resolve();
        });
コード例 #5
0
        public Operation <User> DeactivateUser(string targetUser)
        => _authorizer.AuthorizeAccess(UserContext.CurrentProcessPermissionProfile(), () =>
        {
            var user = _query.GetUserById(targetUser);
            if (user == null)
            {
                throw new Exception("user not found");
            }
            else if (user.Status == (int)AccountStatus.Blocked)
            {
                throw new Exception("user is already blocked");
            }
            else if (user.Status == (int)AccountStatus.Active)
            {
                //invalidate all userlogons
                var logons = _query.GetUserLogins(targetUser);
                logons.Where(_l => !_l.Invalidated).ForAll((cnt, next) =>
                {
                    next.Invalidated = true;
                    _pcommand.Update(next);
                });

                //deactivate the user
                user.Status = (int)AccountStatus.InActive;
                return(_pcommand.Update(user).Resolve());
            }
            else
            {
                return(user);
            }
        });
コード例 #6
0
        /// <summary>
        /// Does both upgrading and recycling
        /// </summary>
        /// <returns></returns>
        public Operation <BitLevel> Upgrade()
        => _authorizer.AuthorizeAccess(UserContext.CurrentProcessPermissionProfile(), () =>
        {
            var maxLevelSettings = _settingsManager.GetSetting(Constants.Settings_MaxBitLevel).Resolve();
            var maxLevel         = (int)maxLevelSettings.ParseData <long>();
            var targetUser       = UserContext.CurrentUser();
            var currentLevel     = _query.CurrentBitLevel(targetUser);

            if (currentLevel != null)
            {
                ConfirmUpgradeDonation().Resolve();
            }

            else
            {
                currentLevel = new BitLevel
                {
                    Level    = maxLevel,
                    Cycle    = 0,
                    Donation = new BlockChainTransaction {
                        Status = BlockChainTransactionStatus.Verified
                    }
                }
            };


            if (currentLevel.Donation.Status == BlockChainTransactionStatus.Unverified)
            {
                throw new Exception("Current level donnation is still unverified");
            }

            var myAddress = _query.GetActiveBitcoinAddress(targetUser)
                            .ThrowIfNull("You do not have a valid block chain transaction address yet.");

            if (currentLevel.Cycle == int.MaxValue && currentLevel.Level == maxLevel)
            {
                throw new Exception("You cannot upgrade past the maximum cycle");
            }

            var nextLevel = (currentLevel.Level + 1) % (maxLevel + 1);
            var nextCycle = nextLevel == 0 ? currentLevel.Cycle + 1 : currentLevel.Cycle;

            var nextUpgradeBeneficiary = NextUpgradeBeneficiary(nextLevel == 0 ? targetUser : currentLevel.Donation.Receiver.Owner, nextLevel, nextCycle).ThrowIfNull("Could not find a valid beneficiary");
            var beneficiaryAddress     = _query.GetActiveBitcoinAddress(nextUpgradeBeneficiary);

            var bl = new BitLevel
            {
                Level         = nextLevel,
                Cycle         = nextCycle,
                DonationCount = 0,
                SkipCount     = 0,
                UserId        = targetUser.UserId
            };
            _pcommand.Add(bl).Resolve();

            var donation = new BlockChainTransaction
            {
                Amount      = nextLevel == maxLevel ? 0 : GetUpgradeAmount(nextLevel + 1),
                LedgerCount = nextLevel == maxLevel ? int.MaxValue : 0,
                CreatedOn   = DateTime.Now,
                Sender      = myAddress,
                Receiver    = beneficiaryAddress,
                ContextType = Constants.TransactionContext_UpgradeBitLevel,
                ContextId   = bl.Id.ToString(),
                Status      = nextLevel == maxLevel ?
                              BlockChainTransactionStatus.Verified :
                              BlockChainTransactionStatus.Unverified
            };
            _pcommand.Add(donation).Resolve();

            bl.DonationId = donation.Id;
            _pcommand.Update(bl);

            bl.Donation = donation;

            //notify user
            _notifier.NotifyUser(new Notification
            {
                Type     = NotificationType.Success,
                TargetId = targetUser.UserId,
                Title    = "Congratulations!",
                Message  = $"Well done, {targetUser.UserId}!! You are now <strong>proudly</strong> at Cycle-{nextCycle} / Level-{nextLevel}, no easy feat!<br/>" +
                           @"Now you can receive even more donations from your downlines. 
                  <p>Remember though, that this is a race to the <strong class='text-primary'>top</strong>, and as such
                  you may miss the donations of any of your downlines who upgrades to levels higher than yours. So dont waste much time here, Upgrade as soon as you can!</p>"
            })
            .Resolve();

            return(bl);
        });