Ejemplo n.º 1
0
        public void TestMethod1()
        {
            var r  = BitCycle.Create(1, 0);
            var r2 = r.Increment(4);

            Console.WriteLine(r2);
        }
Ejemplo n.º 2
0
        public Operation <BitLevel> Demote(string userRef, int units, string haxh)
        => _authorizer.AuthorizeAccess(this.PermissionProfile(UserContext.CurrentUser()), () =>
        {
            Haxher.IsValidHash(haxh).ThrowIf(_v => !_v, "Access Denied");

            var @ref       = _refQuery.GetReferalNode(userRef);
            var targetUser = new User {
                EntityId = @ref.UserId
            };
            var currentLevel = _query.CurrentBitLevel(targetUser).ThrowIfNull("User has not begun cycling");
            var newLevel     = BitCycle.Create(currentLevel.Cycle, currentLevel.Level).Decrement(units);

            currentLevel.Cycle = newLevel.Cycle;
            currentLevel.Level = newLevel.Level;
            _pcommand.Update(currentLevel);

            currentLevel.Donation.Amount = GetUpgradeAmount(newLevel.Level + 1);
            _pcommand.Update(currentLevel.Donation);

            //move all current donnors to the next available beneficiary
            _query.GetDonorLevels(targetUser)
            .Where(_lvl => newLevel > new BitCycle {
                Cycle = _lvl.Cycle, Level = _lvl.Level
            })
            .Select(_lvl =>
            {
                var nextLevel = new BitCycle {
                    Cycle = _lvl.Cycle, Level = _lvl.Level
                }.Increment(1);
                var beneficiary = NextUpgradeBeneficiary(targetUser, nextLevel.Level, nextLevel.Cycle);
                var address     = _query.GetActiveBitcoinAddress(beneficiary);

                _lvl.Donation.ReceiverId = address.Id;

                return(_pcommand.Update(_lvl.Donation));
            })
            .ThrowIf(_ops => !_ops.Any(_op => _op.Succeeded), "failed to reassign some donors");

            return(currentLevel);
        });
Ejemplo n.º 3
0
        public Operation <BitLevel> Promote(string userRef, int units, string securityHash)
        => _authorizer.AuthorizeAccess(this.PermissionProfile(UserContext.CurrentUser()), () =>
        {
            //verify the securityHash
            Haxher.IsValidHash(securityHash).ThrowIf(_v => !_v, "Access Denied");

            //do promotion logic here
            var @ref       = _refQuery.GetReferalNode(userRef);
            var targetUser = new User {
                EntityId = @ref.UserId
            };
            var currentLevel = _query.CurrentBitLevel(targetUser);
            var newLevel     = BitCycle.Create(currentLevel.Cycle, currentLevel.Level).Increment(units);
            var beneficiary  = NextUpgradeBeneficiary(new User {
                UserId = currentLevel.Donation.Receiver.OwnerId
            }, newLevel.Level, newLevel.Cycle)
                               .ThrowIfNull("could not find a suitable beneficiary");

            var beneficiaryAddress = _query.GetActiveBitcoinAddress(beneficiary);
            var targetUserAddress  = _query.GetActiveBitcoinAddress(targetUser);

            //close off the old level
            currentLevel.Donation.Amount = 0;
            currentLevel.Donation.Status = BlockChainTransactionStatus.Verified;
            _pcommand.Update(currentLevel.Donation);

            var bl = new BitLevel
            {
                Level         = newLevel.Level,
                Cycle         = newLevel.Cycle,
                DonationCount = 0,
                SkipCount     = 0,
                UserId        = @ref.UserId
            };
            _pcommand.Add(bl).Resolve();

            var maxLevelSettings = _settingsManager.GetSetting(Constants.Settings_MaxBitLevel).Resolve();
            var maxLevel         = (int)maxLevelSettings.ParseData <long>();

            var donation = new BlockChainTransaction
            {
                Amount      = newLevel.Level == maxLevel ? 0 : GetUpgradeAmount(newLevel.Level + 1),
                LedgerCount = newLevel.Level == maxLevel ? int.MaxValue : 0,
                CreatedOn   = DateTime.Now,
                Sender      = targetUserAddress,
                Receiver    = beneficiaryAddress,
                ContextType = Constants.TransactionContext_UpgradeBitLevel,
                ContextId   = bl.Id.ToString(),
                Status      = newLevel.Level == 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-{newLevel.Cycle} / Level-{newLevel.Level}, 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);
        });