Exemplo n.º 1
0
 public static async Task <ResultsItem> DeleteUserCoinsAsync(List <CryptoCoin> coins, PegaUser user)
 {
     if (coins.Any(x => !IsValidDBRequest(user, x.PortfolioId, validatePortfolio: true).IsSuccess))
     {
         return(ResultsItem.Error(Lang.PortfolioNotFound));
     }
     return(await CryptoRepository.DeleteUserCoinAsync(coins));
 }
Exemplo n.º 2
0
 public static ResultsPair <Portfolio> UpdatePortfolio(int portfolioId, string portfolioName, Types.PortfolioDisplayType displayType, bool isDefault, PegaUser user)
 {
     if (!IsValidDBRequest(user, portfolioId, validatePortfolio: true).IsSuccess)
     {
         return(ResultsPair.CreateError <Portfolio>(Lang.PortfolioNotFound));
     }
     return(CryptoRepository.UpdatePortfolio(portfolioId, portfolioName, displayType, isDefault));
 }
        public CryptoControllerTest(ContextFixture contextFixture)
        {
            var cryptoRepository        = new CryptoRepository(contextFixture.ApiContext);
            var cryptoService           = new CryptoService(cryptoRepository);
            var coinMarketCapApiService = new CoinMarketCapApiService(cryptoRepository, contextFixture.Configuration);

            _cryptoController = new CryptoController(cryptoService, coinMarketCapApiService);
        }
Exemplo n.º 4
0
        public WalletControllerTest(ContextFixture contextFixture)
        {
            var walletRepository        = new WalletRepository(contextFixture.ApiContext);
            var cryptoRepository        = new CryptoRepository(contextFixture.ApiContext);
            var emailEmailService       = new EmailService();
            var coinMarketCapApiService = new WalletOperationsService(emailEmailService);

            _walletController = new WalletController(walletRepository, cryptoRepository, coinMarketCapApiService);
        }
Exemplo n.º 5
0
        public static ResultsItem DeleteAPI(int apiId, PegaUser user)
        {
            var validateRequest = IsValidDBRequest(user, apiId, validateAPI: true);

            if (!validateRequest.IsSuccess)
            {
                return(validateRequest);
            }

            return(CryptoRepository.DeleteAPI(apiId));
        }
Exemplo n.º 6
0
        public static async Task <ResultsPair <Portfolio> > InsertNewPortfolio(PegaUser user, string portfolioName, Types.PortfolioDisplayType displayType, bool isDefault)
        {
            var validateRequest = IsValidDBRequest(user, 0);

            if (!validateRequest.IsSuccess)
            {
                return(ResultsPair.CreateError <Portfolio>(validateRequest.Message));
            }

            return(await CryptoRepository.InsertNewPortfolio(user.UserId, portfolioName, displayType, isDefault));
        }
Exemplo n.º 7
0
        public static async Task <ResultsItem> UpdateUserCoinAsync(CryptoCoin coin, PegaUser user)
        {
            var validateRequest = IsValidDBRequest(user, coin.PortfolioId, validatePortfolio: true);

            if (!validateRequest.IsSuccess)
            {
                return(validateRequest);
            }

            return(await CryptoRepository.UpdateUserCoinAsync(coin));
        }
Exemplo n.º 8
0
        public static ResultsItem InsertNewAPI(ExchangeApiInfo exchangeApiInfo, PegaUser user)
        {
            var validateRequest = IsValidDBRequest(user, 0);

            if (!validateRequest.IsSuccess)
            {
                return(validateRequest);
            }

            return(CryptoRepository.InsertNewAPI(exchangeApiInfo, user));
        }
Exemplo n.º 9
0
        public static async Task <ResultsItem> DeleteAllUserCoinByExchangeAsync(int portfolioId, Types.Exchanges exchange, PegaUser user)
        {
            var validateRequest = IsValidDBRequest(user, portfolioId, validatePortfolio: true);

            if (!validateRequest.IsSuccess)
            {
                return(validateRequest);
            }

            return(await CryptoRepository.DeleteAllUserCoinByExchangeAsync(portfolioId, exchange));
        }
Exemplo n.º 10
0
        public static async Task <ResultsItem> DeletePortfolio(int portfolioId, PegaUser user)
        {
            var validateRequest = IsValidDBRequest(user, portfolioId, validatePortfolio: true);

            if (!validateRequest.IsSuccess)
            {
                return(validateRequest);
            }

            ResultsItem deleteResult = await CryptoRepository.DeletePortfolio(portfolioId);

            // Since we're deleting the only portfolio we have, create a new default one.
            if (user.Portfolios.Count == 1)
            {
                await InsertNewPortfolio(user, "Default", Types.PortfolioDisplayType.Private, true);
            }

            return(deleteResult);
        }
Exemplo n.º 11
0
        public static async Task <ResultsItem> InsertCoinsToUserPortfolioAsync(List <CryptoCoin> coins, PegaUser user, int?portfolioId = null)
        {
            // Validation: Do not allow symbol to end in -USD.
            if (coins.Any(x => x.Symbol.ToUpperInvariant().Contains("-USD")))
            {
                if (coins.Count == 1)
                {
                    return(ResultsItem.Error("The coin symbol must not end in -USD. It should be USD-. For example: USD-ETH, USD-XRP."));
                }
                coins = coins.Where(x => !x.Symbol.ToUpperInvariant().Contains("-USD")).ToList();
            }

            if (portfolioId != null)
            {
                coins.ForEach(x => x.PortfolioId = portfolioId.Value);
            }
            if (coins.Any(x => !IsValidDBRequest(user, x.PortfolioId, validatePortfolio: true).IsSuccess))
            {
                return(ResultsItem.Error(Lang.PortfolioNotFound));
            }

            return(await CryptoRepository.InsertCoinsToUserPortfolioAsync(coins));
        }
Exemplo n.º 12
0
 public static async Task <List <CryptoCoin> > GetAllUserCoinsByPortfolioIdAsync(int portfolioId)
 {
     // Make sure controller has !user.HasPortfolio check
     return(await CryptoRepository.GetAllUserCoinsByPortfolioIdAsync(portfolioId));
 }
Exemplo n.º 13
0
        public static async Task <CryptoCoin> GetSingleCoinByUser(long coinId, PegaUser user)
        {
            CryptoCoin coin = await CryptoRepository.GetSingleCoinByUser(coinId);

            return(!IsValidDBRequest(user, coin.PortfolioId, validatePortfolio: true, validateDemoUser: false).IsSuccess ? null : coin);
        }
Exemplo n.º 14
0
 public static async Task <List <Portfolio> > GetAllUserPortfolioAsync(PegaUser user)
 {
     return(await CryptoRepository.GetAllUserPortfolioAsync(user));
 }
Exemplo n.º 15
0
        public CoinMarketCapApiServiceTest(ContextFixture contextFixture)
        {
            var cryptoRepository = new CryptoRepository(contextFixture.ApiContext);

            _coinMarketCapApiService = new CoinMarketCapApiService(cryptoRepository, contextFixture.Configuration);
        }
Exemplo n.º 16
0
 public static async Task <List <ExchangeApiInfo> > GetAllUserExchangeAPIAsync(int userId)
 {
     return(await CryptoRepository.GetAllUserExchangeAPIAsync(userId));
 }
Exemplo n.º 17
0
 public static List <OfficialCoin> GetAllOfficialCoins() => CryptoRepository.GetAllOfficialCoins();
Exemplo n.º 18
0
 public static async Task <ResultsPair <Portfolio> > ResetAllUserTrades(PegaUser user)
 {
     return(await CryptoRepository.ResetAllUserTrades(user));
 }