Example #1
0
        public async Task <PaytopiaPaymentModel> GetPayment(int id)
        {
            PaytopiaPaymentModel item;
            string  currencySymbol;
            dynamic refCurrency;

            Entity.Pool refPool;

            using (var context = DataContextFactory.CreateReadOnlyContext())
            {
                item = await context.PaytopiaPayments
                       .AsNoTracking()
                       .Where(x => x.Id == id)
                       .Select(payment => new PaytopiaPaymentModel
                {
                    Id            = payment.Id,
                    Type          = payment.PaytopiaItem.Type,
                    CurrencyId    = payment.PaytopiaItem.CurrencyId,
                    Amount        = payment.Amount,
                    Status        = payment.Status,
                    UserName      = payment.User.UserName,
                    IsAnonymous   = payment.IsAnonymous,
                    Begins        = payment.Begins,
                    Ends          = payment.Ends,
                    Timestamp     = payment.Timestamp,
                    TransferId    = payment.TransferId,
                    RefundId      = payment.RefundId,
                    ReferenceCode = payment.ReferenceCode,
                    ReferenceId   = payment.ReferenceId,
                    RefundReason  = payment.RefundReason,
                    RequestData   = payment.RequestData,
                }).FirstOrDefaultNoLockAsync().ConfigureAwait(false);
            }

            using (var exchangeContext = ExchangeDataContextFactory.CreateReadOnlyContext())
            {
                currencySymbol = await exchangeContext.Currency.Where(c => c.Id == item.CurrencyId).Select(c => c.Symbol).FirstOrDefaultNoLockAsync();

                refCurrency = await exchangeContext.Currency.Where(c => c.Id == item.ReferenceId).Select(c => new {
                    Name     = c.Name,
                    AlgoType = c.Info.AlgoType,
                    Symbol   = c.Symbol
                }).FirstOrDefaultNoLockAsync();
            }

            using (var poolContext = PoolDataContextFactory.CreateContext())
            {
                refPool = await poolContext.Pool.Where(p => p.IsEnabled && p.Id == item.ReferenceId).FirstOrDefaultNoLockAsync();
            }

            item.Symbol = currencySymbol;

            if (item.ReferenceId > 0)
            {
                if (item.Type == PaytopiaItemType.FeaturedCurrency || item.Type == PaytopiaItemType.LottoSlot || item.Type == PaytopiaItemType.RewardSlot || item.Type == PaytopiaItemType.TipSlot)
                {
                    if (refCurrency != null)
                    {
                        item.ReferenceName   = refCurrency.Name;
                        item.ReferenceAlgo   = refCurrency.AlgoType;
                        item.ReferenceSymbol = refCurrency.Symbol;
                    }
                }
                else if (item.Type == PaytopiaItemType.FeaturedPool || item.Type == PaytopiaItemType.PoolListing)
                {
                    if (refPool != null)
                    {
                        item.ReferenceName   = refPool.Name;
                        item.ReferenceAlgo   = refPool.AlgoType;
                        item.ReferenceSymbol = refPool.Symbol;
                    }
                }
            }

            return(item);
        }
Example #2
0
        public async Task <IServiceResult> SyncUser(string userId)
        {
            try
            {
                if (string.IsNullOrEmpty(userId))
                {
                    return(new ServiceResult(false));
                }

                using (var hubContext = DataContextFactory.CreateContext())
                    using (var poolContext = PoolDataContextFactory.CreateContext())
                        using (var exchangeContext = ExchangeDataContextFactory.CreateContext())
                        {
                            var hubUser = await hubContext.Users.FirstOrDefaultAsync(x => x.Id == userId).ConfigureAwait(false);

                            if (hubUser == null)
                            {
                                return(new ServiceResult(false));
                            }

                            var exchangeUser =
                                await exchangeContext.Users.FirstOrDefaultAsync(x => x.Id == new Guid(userId)).ConfigureAwait(false);

                            if (exchangeUser == null)
                            {
                                exchangeUser = new Entity.User {
                                    Id = new Guid(userId)
                                };
                                exchangeContext.Users.Add(exchangeUser);
                            }

                            var poolUser = await poolContext.User.FirstOrDefaultAsync(x => x.Id == new Guid(userId)).ConfigureAwait(false);

                            if (poolUser == null)
                            {
                                poolUser = new Entity.PoolUser {
                                    Id = new Guid(userId), IsEnabled = true
                                };
                                poolContext.User.Add(poolUser);
                            }

                            // Exchange user
                            exchangeUser.ChatHandle                       = hubUser.ChatHandle;
                            exchangeUser.DisableExchangeNotify            = hubUser.DisableExchangeNotify;
                            exchangeUser.DisableFaucetNotify              = hubUser.DisableFaucetNotify;
                            exchangeUser.DisableMarketplaceNotify         = hubUser.DisableMarketplaceNotify;
                            exchangeUser.DisablePoolNotify                = hubUser.DisablePoolNotify;
                            exchangeUser.DisableRewards                   = hubUser.DisableRewards;
                            exchangeUser.DisableTipNotify                 = hubUser.DisableTipNotify;
                            exchangeUser.DisableWithdrawEmailConfirmation = hubUser.DisableWithdrawEmailConfirmation;
                            exchangeUser.Email                      = hubUser.Email;
                            exchangeUser.IsDisabled                 = hubUser.IsDisabled;
                            exchangeUser.MiningHandle               = hubUser.MiningHandle;
                            exchangeUser.Referrer                   = hubUser.Referrer;
                            exchangeUser.RegisterDate               = hubUser.RegisterDate;
                            exchangeUser.TrustRating                = hubUser.TrustRating;
                            exchangeUser.UserName                   = hubUser.UserName;
                            exchangeUser.IsUnsafeWithdrawEnabled    = hubUser.IsUnsafeWithdrawEnabled;
                            exchangeUser.IsApiUnsafeWithdrawEnabled = hubUser.IsApiUnsafeWithdrawEnabled;
                            exchangeUser.VerificationLevel          = hubUser.VerificationLevel;

                            // Pool user
                            poolUser.UserName             = hubUser.UserName;
                            poolUser.MiningHandle         = hubUser.MiningHandle;
                            poolUser.DisableNotifications = hubUser.DisablePoolNotify;

                            await poolContext.SaveChangesAsync().ConfigureAwait(false);

                            await exchangeContext.SaveChangesAsync().ConfigureAwait(false);

                            return(new ServiceResult(true));
                        }
            }
            catch (Exception)
            {
                return(new ServiceResult(false));
            }
        }
Example #3
0
        private async Task ProcessPaytopiaItems()
        {
            try
            {
                var now            = DateTime.UtcNow;
                var beginingOfWeek = now.StartOfWeek(DayOfWeek.Monday);
                var endOfWeek      = beginingOfWeek.AddDays(7);
                var featuredItems  = new List <FeaturedInfo>();
                using (var context = DataContextFactory.CreateContext())
                {
                    featuredItems = await context.PaytopiaPayments
                                    .Where(x => x.Begins >= beginingOfWeek && x.Ends <= endOfWeek && (x.PaytopiaItem.Type == PaytopiaItemType.FeaturedCurrency || x.PaytopiaItem.Type == PaytopiaItemType.FeaturedPool))
                                    .Select(x => new FeaturedInfo
                    {
                        Id         = x.ReferenceId,
                        Type       = x.PaytopiaItem.Type,
                        ExpireTime = x.Ends
                    }).ToListNoLockAsync();
                }

                if (!featuredItems.Any())
                {
                    return;
                }

                // update currencies
                using (var context = ExchangeDataContextFactory.CreateContext())
                {
                    var currencyIds = featuredItems.Where(x => x.Type == PaytopiaItemType.FeaturedCurrency).Select(x => x.Id).ToList();
                    var currencies  = await context.Currency.Where(x => currencyIds.Contains(x.Id)).ToListNoLockAsync();

                    foreach (var currency in currencies)
                    {
                        var featureExpireTime = featuredItems.First(x => x.Type == PaytopiaItemType.FeaturedCurrency && x.Id == currency.Id).ExpireTime;
                        if (featureExpireTime != currency.FeaturedExpires)
                        {
                            currency.FeaturedExpires = featureExpireTime;
                        }
                    }
                    await context.SaveChangesAsync();
                }

                // update pools
                using (var context = PoolDataContextFactory.CreateContext())
                {
                    var poolIds = featuredItems.Where(x => x.Type == PaytopiaItemType.FeaturedPool).Select(x => x.Id).ToList();
                    var pools   = await context.Pool.Where(x => poolIds.Contains(x.Id)).ToListNoLockAsync();

                    foreach (var pool in pools)
                    {
                        var featureExpireTime = featuredItems.First(x => x.Type == PaytopiaItemType.FeaturedPool && x.Id == pool.Id).ExpireTime;
                        if (featureExpireTime != pool.FeaturedExpires)
                        {
                            pool.FeaturedExpires = featureExpireTime;
                        }
                    }
                    await context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                Log.Exception("[ProcessPaytopiaItems] - An exception occurred processing Paytopia items.", ex);
            }
        }