Exemple #1
0
        public static async Task <decimal> CornPrice(BitcornContext dbContext)
        {
            var cornPrice = dbContext.Price.FirstOrDefault(p => p.Symbol == "CORN");

            try
            {
                if (cornPrice == null)
                {
                    var price = new Price();
                    price.Symbol      = "CORN";
                    price.LatestPrice = (await ProbitApi.GetCornPriceAsync(dbContext));
                    dbContext.Price.Add(price);
                    await dbContext.SaveAsync();

                    return(price.LatestPrice);
                }

                cornPrice.LatestPrice = (await ProbitApi.GetCornPriceAsync(dbContext));
                await dbContext.SaveAsync();
            }
            catch (Exception e)
            {
                await BITCORNLogger.LogError(dbContext, e, null);
            }
            return(cornPrice.LatestPrice);
        }
        public static async Task <SubscriptionResponse> Subscribe(BitcornContext dbContext, User user, SubRequest subRequest)
        {
            try
            {
                //try to find subscription
                var subInfo = await dbContext.Subscription.FirstOrDefaultAsync(s => s.Name.ToLower() == subRequest.SubscriptionName.ToLower());

                //initialize response object
                var output = new SubscriptionResponse();
                if (subInfo != null)
                {
                    output.RequestedSubscriptionInfo = subInfo;
                    //try to find subscription tier info
                    var requestedTierInfo = await dbContext.SubscriptionTier.FirstOrDefaultAsync(t => t.SubscriptionId == subInfo.SubscriptionId && t.Tier == subRequest.Tier);

                    output.RequestedSubscriptionTier = requestedTierInfo;
                    //if tier was found, attempt to process the subscription
                    if (requestedTierInfo != null)
                    {
                        return(await ProcessSubscription(dbContext, output, subRequest, subInfo, requestedTierInfo, user));
                    }
                    else
                    {
                        //this subscription cannot be executed, fill out the response object
                        await PopuplateUserResponse(dbContext, subRequest, output, user);
                    }
                }
                else
                {
                    //this subscription cannot be executed, fill out the response object
                    await PopuplateUserResponse(dbContext, subRequest, output, user);
                }

                return(output);
            }
            catch (Exception e)
            {
                await BITCORNLogger.LogError(dbContext, e, null);

                throw e;
            }
        }
Exemple #3
0
        public static async Task UpdateReferralSync(BitcornContext dbContext, PlatformId platformId)
        {
            var user = BitcornUtils.GetUserForPlatform(platformId, dbContext).FirstOrDefault();

            try
            {
                if (user != null && user.UserId != 0)
                {
                    if (user.IsBanned)
                    {
                        return;
                    }
                    if (!UserLockCollection.Lock(user.UserId))
                    {
                        throw new Exception("User is locked");
                    }

                    var userReferral = await dbContext.UserReferral.FirstOrDefaultAsync(u => u.UserId == user.UserId);

                    if (userReferral != null && userReferral.SyncDate == null)
                    {
                        var referrer = await
                                       dbContext.Referrer.FirstOrDefaultAsync(r => r.ReferralId == userReferral.ReferralId);

                        if (referrer != null && (referrer.YtdTotal < 600 || (referrer.ETag != null && referrer.Key != null)))
                        {
                            var referralPayoutTotal = await ReferralUtils.TotalReward(dbContext, referrer);

                            var referrerUser = await dbContext.User.FirstOrDefaultAsync(u => u.UserId == referrer.UserId);

                            if (referrerUser.IsBanned)
                            {
                                if (user != null)
                                {
                                    UserLockCollection.Release(user.UserId);
                                }
                                return;
                            }
                            var referreeReward = await TxUtils.SendFromBitcornhub(user, referrer.Amount, "BITCORNfarms", "Recruit social sync", dbContext);

                            var referrerReward = await TxUtils.SendFromBitcornhub(referrerUser, referralPayoutTotal, "BITCORNfarms", "Social sync", dbContext);

                            if (referrerReward && referreeReward)
                            {
                                userReferral.SyncDate = DateTime.Now;
                                await UpdateYtdTotal(dbContext, referrer, referralPayoutTotal);
                                await LogReferralTx(dbContext, referrer.UserId, referralPayoutTotal, "Social Sync");
                                await LogReferralTx(dbContext, user.UserId, referralPayoutTotal, "Recruit social Sync");

                                var userStat = await dbContext.UserStat.FirstOrDefaultAsync(s => s.UserId == referrer.UserId);

                                userStat.TotalReferralRewardsCorn += referralPayoutTotal;
                                userStat.TotalReferralRewardsUsdt += (referralPayoutTotal * (await ProbitApi.GetCornPriceAsync(dbContext)));
                                await ReferralUtils.BonusPayout(dbContext, userReferral, referrer, user, referrerUser, userStat);
                            }
                        }
                    }

                    await dbContext.SaveAsync();
                }
            }
            catch (Exception e)
            {
                await BITCORNLogger.LogError(dbContext, e, null);

                throw;
            }
            finally
            {
                if (user != null)
                {
                    UserLockCollection.Release(user.UserId);
                }
            }
        }