Пример #1
0
        public static async Task <ResultsItem> CreateBBThread(LocalCommunity.BBThread thread, LocalAccount.PegaUser user)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    thread.Message = thread.Message.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM });
                    thread.UserId  = user.UserId;

                    BBThreads serviceMessageThread = thread.Adapt <BBThreads>();
                    serviceMessageThread.CreateDate = DateTime.Now;
                    serviceMessageThread.UserId     = user.UserId;
                    serviceMessageThread.Message    = serviceMessageThread.Message.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM });
                    serviceMessageThread.Title      = serviceMessageThread.Title.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM });

                    db.BBThreads.Add(serviceMessageThread);
                    await db.SaveChangesAsync();

                    return(ResultsItem.Success("Successfully created a new thread"));
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { $"User:{user.Username}" }, ex);
                return(ResultsItem.Error($"Unable to create a new thread. {ex.Message}"));
            }
        }
Пример #2
0
        public static async Task <ResultsItem> DeleteBBThread(int threadId, LocalAccount.PegaUser user)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    BBThreads serviceThread = db.BBThreads.FirstOrDefault(x => x.ThreadId == threadId);
                    if (serviceThread == null)
                    {
                        return(ResultsItem.Error("This thread was not found or has already been deleted."));
                    }
                    if (serviceThread.UserId != user.UserId)
                    {
                        return(ResultsItem.Error("This thread belongs to another user."));
                    }

                    db.Remove(serviceThread);
                    await db.SaveChangesAsync();

                    return(ResultsItem.Success("Successfully deleted this thread. Please refresh the page to see changes."));
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { $"User:{user.Username}" }, ex);
                return(ResultsItem.Error($"Unable to delete this thread. {ex.Message}"));
            }
        }
Пример #3
0
        public static async Task <ResultsPair <LocalCoins.Portfolio> > InsertNewPortfolio(int userId, string portfolioName, Types.PortfolioDisplayType displayType, bool isDefault)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    Portfolios portfolio = new Portfolios
                    {
                        UserId      = userId,
                        Name        = portfolioName.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM }),
                        DisplayType = (short)displayType,
                        IsDefault   = isDefault
                    };

                    db.Portfolios.Add(portfolio);
                    await db.SaveChangesAsync();

                    return(ResultsPair.Create(ResultsItem.Success("Successfully created a new portfolio."), portfolio.Adapt <LocalCoins.Portfolio>()));
                }
            }
            catch (Exception ex)
            {
                return(ResultsPair.CreateError <LocalCoins.Portfolio>($"Unable to create a new portfolio. {ex.Message}"));
            }
        }
Пример #4
0
        public static async Task <ResultsItem> CreateBBComment(LocalCommunity.BBComment comment, LocalAccount.PegaUser user)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    comment.Message.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM });

                    BBComments serviceComment = comment.Adapt <BBComments>();
                    serviceComment.CreateDate = DateTime.Now;
                    serviceComment.UserId     = user.UserId;
                    serviceComment.Message    = serviceComment.Message.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM });

                    db.BBComments.Add(serviceComment);
                    await db.SaveChangesAsync();

                    return(ResultsItem.Success("Successfully posted a new comment."));
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { $"User:{user.Username}" }, ex);
                return(ResultsItem.Error($"Unable to create a comment. {ex.Message}"));
            }
        }
Пример #5
0
        public static async Task <ResultsItem> UpdateUserCoinAsync(LocalCoins.CryptoCoin coin)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    Coins serviceCoin = db.Coins.FirstOrDefault(x => x.CoinId == coin.CoinId);
                    if (serviceCoin == null)
                    {
                        return(ResultsItem.Error("This coin was not found."));
                    }

                    serviceCoin.Shares                = coin.Shares;
                    serviceCoin.CoinCurrency          = (short)coin.CoinCurrency;
                    serviceCoin.PricePerUnit          = coin.PricePerUnit;
                    serviceCoin.TotalPricePaidUsd     = coin.TotalPricePaidUSD;
                    serviceCoin.Exchange              = (short)coin.Exchange;
                    serviceCoin.OrderType             = (short)coin.OrderType;
                    serviceCoin.OrderDate             = coin.OrderDate;
                    serviceCoin.SoldCoinCurrency      = (short)coin.SoldCoinCurrency;
                    serviceCoin.SoldPricePerUnit      = coin.SoldPricePerUnit;
                    serviceCoin.TotalSoldPricePaidUsd = coin.TotalSoldPricePaidUSD;

                    db.Update(serviceCoin);
                    await db.SaveChangesAsync();
                }

                return(ResultsItem.Success("Successfully updated coin."));
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { "UpdateUserCoinAsync", $"coinId:{coin.CoinId},portfolioId:{coin.PortfolioId}" }, ex);
                return(ResultsItem.Error($"Unable to updated coin. {ex.Message}"));
            }
        }
Пример #6
0
        public static async Task <ResultsPair <LocalCoins.Portfolio> > ResetAllUserTrades(PegaUser user)
        {
            ResultsPair <LocalCoins.Portfolio> generateError(string error)
            {
                return(ResultsPair.CreateError <LocalCoins.Portfolio>(error));
            }

            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    var portfolios = db.Portfolios.Where(x => user.Portfolios.Any(p => p.PortfolioId == x.PortfolioId));
                    db.Portfolios.RemoveRange(portfolios);

                    await db.SaveChangesAsync();

                    var insertPortfolioResult = await InsertNewPortfolio(user.UserId, "Default", Types.PortfolioDisplayType.Public, true);

                    if (insertPortfolioResult.Result.IsSuccess)
                    {
                        insertPortfolioResult.Result.Message = "Successfully reset all of your trades.";
                        return(insertPortfolioResult);
                    }

                    return(generateError("An error occured during the reset process. Please re-login and try again."));
                }
            }
            catch (Exception ex)
            {
                return(generateError($"An error occured during the reset process. Please re-login and try again. Error: {ex.Message}"));
            }
        }
Пример #7
0
        private static async Task <ResultsPair <LocalAccount.PTUserInfo> > CreateNewPTUserInfo(LocalAccount.PegaUser user)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    PTUserInfo ptUserInfo = new PTUserInfo
                    {
                        UserId                 = user.UserId,
                        SubscriptionLevel      = (byte)SubscriptionLevel.Free,
                        SubscriptionExpireDate = null
                    };

                    db.PTUserInfo.Add(ptUserInfo);
                    await db.SaveChangesAsync();

                    LocalAccount.PTUserInfo localSubscription = ptUserInfo.Adapt <LocalAccount.PTUserInfo>();

                    return(ResultsPair.Create(ResultsItem.Success("Successfully created a new subscription."), localSubscription));
                }
            }
            catch (Exception ex)
            {
                return(ResultsPair.CreateError <LocalAccount.PTUserInfo>($"Unable to create a new PTUserInfo: {ex.Message}"));
            }
        }
Пример #8
0
        public static async Task <ResultsItem> DeleteAllUserCoinByExchangeAsync(int portfolioId, Types.Exchanges exchange)
        {
            try
            {
                int exchangeId = (int)exchange;
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    var coins = db.Coins.Where(x => x.PortfolioId == portfolioId && x.Exchange == exchangeId);
                    db.Coins.RemoveRange(coins);

                    await db.SaveChangesAsync();
                }

                return(ResultsItem.Success("Successfully deleted all coins by exchange."));
            }
            catch (Exception ex)
            {
                return(ResultsItem.Error($"Unable to delete all coins. {ex.Message}"));
            }
        }
Пример #9
0
        public static async Task <ResultsItem> DeleteUserCoinAsync(List <LocalCoins.CryptoCoin> coins)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    List <Coins> serviceCoins = coins.Select(x => new Coins {
                        CoinId = x.CoinId
                    }).ToList();

                    db.RemoveRange(serviceCoins);
                    await db.SaveChangesAsync();
                }

                return(ResultsItem.Success("Successfully deleted coin."));
            }
            catch (Exception ex)
            {
                return(ResultsItem.Error($"Unable to delete coin. {ex.Message}"));
            }
        }
Пример #10
0
        public static async Task <ResultsItem> DeletePortfolio(int portfolioId)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    Portfolios portfolio = db.Portfolios.FirstOrDefault(x => x.PortfolioId == portfolioId);
                    if (portfolio != null)
                    {
                        db.Portfolios.Remove(portfolio);
                        await db.SaveChangesAsync();
                    }
                }

                return(ResultsItem.Success("Successfully deleted portfolio."));
            }
            catch (Exception ex)
            {
                return(ResultsItem.Error($"Unable to delete portfolio. {ex.Message}"));
            }
        }
Пример #11
0
        public static async Task <ResultsItem> InsertCoinsToUserPortfolioAsync(List <LocalCoins.CryptoCoin> coins)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    List <Coins> serviceCoins = coins.Where(x => x.Symbol.Length < 10).Select(x => new Coins
                    {
                        CoinId            = x.CoinId,
                        Symbol            = x.Symbol.Clean(new [] { Types.CleanInputType.Letters, Types.CleanInputType.Digits, Types.CleanInputType.Dash }),
                        Shares            = x.Shares,
                        OrderDate         = x.OrderDate,
                        CoinCurrency      = (short)x.CoinCurrency,
                        PricePerUnit      = x.PricePerUnit,
                        TotalPricePaidUsd = x.TotalPricePaidUSD,
                        OrderType         = (short)x.OrderType,
                        //Notes = x.Notes,
                        Exchange              = (short)x.Exchange,
                        PortfolioId           = x.PortfolioId,
                        SoldCoinCurrency      = (short)x.SoldCoinCurrency,
                        SoldPricePerUnit      = x.SoldPricePerUnit,
                        TotalSoldPricePaidUsd = x.TotalSoldPricePaidUSD,
                    }).ToList();

                    db.AddRange(serviceCoins);
                    await db.SaveChangesAsync();
                }

                return(ResultsItem.Success("Successfully added all the coins to your portfolio."));
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { "InsertCoinsToUserPortfolioAsync", $"portfolioId:{coins.First().PortfolioId}" }, ex);
                return(ResultsItem.Error($"Unable to add all the coins to your portfolio. {ex.Message}"));
            }
        }