예제 #1
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}"));
            }
        }
예제 #2
0
        public static ResultsPair <LocalAccount.ViewUser> AuthorizeViewUser(string username, string portfolioName)
        {
            using (PegasunDBContext db = new PegasunDBContext())
            {
                var user = db.Users.FirstOrDefault(x => x.Username == username);
                if (user == null)
                {
                    return(ResultsPair.CreateError <LocalAccount.ViewUser>($"Could not find the user {username}."));
                }

                var portfolios = db.Portfolios.Where(x => x.UserId == user.UserId && x.DisplayType == 3).ToList();
                if (portfolios.IsNullOrEmpty() || !portfolios.Any(x => Utilities.FormatPortfolioName(x.Name).EqualsTo(portfolioName)))
                {
                    return(ResultsPair.CreateError <LocalAccount.ViewUser>($"Could not find the portfolio {portfolioName}"));
                }

                return(ResultsPair.CreateSuccess(new LocalAccount.ViewUser
                {
                    PortfolioName = portfolioName,
                    SelectedPortfolioID = portfolios.First(x => Utilities.FormatPortfolioName(x.Name).EqualsTo(portfolioName)).PortfolioId,
                    Portfolios = portfolios.Adapt <List <LocalCoins.Portfolio> >(),
                    Username = user.Username
                }));
            }
        }
예제 #3
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}"));
            }
        }
예제 #4
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}"));
            }
        }
예제 #5
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}"));
            }
        }
예제 #6
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}"));
            }
        }
예제 #7
0
        public static ResultsPair <LocalCoins.Portfolio> UpdatePortfolio(int portfolioId, string portfolioName, Types.PortfolioDisplayType displayType, bool isDefault)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    Portfolios portfolio = db.Portfolios.FirstOrDefault(x => x.PortfolioId == portfolioId);
                    if (portfolio != null)
                    {
                        portfolio.Name        = portfolioName.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM });
                        portfolio.DisplayType = (short)displayType;
                        portfolio.IsDefault   = isDefault;

                        db.Update(portfolio);
                        db.SaveChanges();
                    }

                    return(ResultsPair.Create(ResultsItem.Success("Successfully updated portfolio name."), portfolio.Adapt <LocalCoins.Portfolio>()));
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { "UpdatePortfolio", $"portfolioId:{portfolioId},portfolioName:{portfolioName}" }, ex);
                return(ResultsPair.CreateError <LocalCoins.Portfolio>($"Unable to update portfolio. {ex.Message}"));
            }
        }
예제 #8
0
        public static async Task <List <LocalCoins.Portfolio> > GetAllUserPortfolioAsync(PegaUser user)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    List <Portfolios> servicePortfolios = await db.Portfolios.Where(x => x.UserId == user.UserId).ToListAsync();

                    if (servicePortfolios.IsNullOrEmpty())
                    {
                        var result = await InsertNewPortfolio(user.UserId, "Default", Types.PortfolioDisplayType.Private, isDefault : true);

                        result.Value.OwnerUsername = user.Username;
                        return(new List <LocalCoins.Portfolio> {
                            result.Value
                        });
                    }

                    List <LocalCoins.Portfolio> localPortfolios = servicePortfolios.Adapt <List <LocalCoins.Portfolio> >();
                    localPortfolios.ForEach(x => x.OwnerUsername = user.Username);
                    return(localPortfolios);
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { "GetAllUserPortfolio", $"UserId:{user.UserId}" }, ex);
                return(new List <LocalCoins.Portfolio>());
            }
        }
예제 #9
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}"));
            }
        }
예제 #10
0
        public static async Task <LocalCommunity.BBThread> GetBBThreadWithComments(int threadId, LocalAccount.PegaUser currentUser)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    var getThreadTask   = GetBBThreadsFromDB(db, currentUser, threadId: threadId);
                    var getCommentsTask = GetBBThreadCommentsFromDB(db, threadId, currentUser);

                    LocalCommunity.BBThread         thread   = (await getThreadTask).FirstOrDefault();
                    List <LocalCommunity.BBComment> comments = await getCommentsTask;

                    if (thread == null)
                    {
                        return(null);
                    }

                    thread.ThreadComments = comments;
                    thread.ThreadName     = "thread_" + thread.ThreadId;

                    return(thread);
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { $"ThreadId:{threadId}" }, ex);
                return(new LocalCommunity.BBThread());
            }
        }
예제 #11
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}"));
            }
        }
예제 #12
0
        public static ResultsItem InsertNewAPI(LocalCoins.ExchangeApiInfo exchangeApiDetails, PegaUser user)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    ApiDetails serviceApi = new ApiDetails
                    {
                        Name        = exchangeApiDetails.Name.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM }),
                        Exchange    = (short)exchangeApiDetails.Exchange,
                        ApiAction   = (short)exchangeApiDetails.ApiAction,
                        ApiPublic   = Cryptography.Encrypt(exchangeApiDetails.ApiPublic, Types.EncryptionType.ApiKey_Public, user),
                        ApiPrivate  = Cryptography.Encrypt(exchangeApiDetails.ApiPrivate, Types.EncryptionType.ApiKey_Private, user),
                        ApiThirdKey = exchangeApiDetails.ApiThirdKey.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM }),
                        DateAdded   = DateTime.Now,
                        UserId      = user.UserId,
                    };

                    db.ApiDetails.Add(serviceApi);
                    db.SaveChanges();
                }

                return(ResultsItem.Success("Successfully created a new API."));
            }
            catch (Exception ex)
            {
                return(ResultsItem.Error($"Unable to create a new API. {ex.Message}"));
            }
        }
예제 #13
0
 public static List <LocalCoins.OfficialCoin> GetAllOfficialCoins()
 {
     using (PegasunDBContext db = new PegasunDBContext())
     {
         List <OfficialCoins> coins = db.OfficialCoins.ToList();
         return(coins.Adapt <List <LocalCoins.OfficialCoin> >());
     }
 }
예제 #14
0
        public static async Task <ResultsItem> VoteBBComment(long commentId, bool isUpvote, LocalAccount.PegaUser user)
        {
            try
            {
                string message = "Successfully updated your vote. It will be reflected shortly.";
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    var getServiceCommentTask = db.BBComments.FirstOrDefaultAsync(x => x.CommentId == commentId);
                    var getExistingVoteTask   = db.BBCommentVotes.FirstOrDefaultAsync(x => x.CommentId == commentId && x.UserId == user.UserId);

                    var serviceComment = await getServiceCommentTask;
                    var existingVote   = await getExistingVoteTask;

                    if (serviceComment == null)
                    {
                        return(ResultsItem.Error("This comment does not exist."));
                    }
                    if (existingVote != null)
                    {
                        if (existingVote.IsUpvote == isUpvote)
                        {
                            db.Remove(existingVote); message = "Successfully removed your vote. It will be reflected shortly.";
                        }                                                                                                                                              // Same vote (e.g. clicked on upvote twice), which means they are re-tracing their vote.
                        else
                        {
                            existingVote.IsUpvote = isUpvote;
                        }
                    }
                    else
                    {
                        var newServiceVote = new BBCommentVotes
                        {
                            CommentId = commentId,
                            IsUpvote  = isUpvote,
                            UserId    = user.UserId
                        };
                        db.BBCommentVotes.Add(newServiceVote);
                    }

                    db.SaveChanges();
                    return(ResultsItem.Success(message));
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { $"User:{user.Username}", $"CommentId:{commentId}" }, ex);
                return(ResultsItem.Error($"Unable to submit your vote. {ex.Message}"));
            }
        }
예제 #15
0
        // CurrentUser can be null
        public static async Task <List <LocalCommunity.BBThread> > GetBBThreads(int take, List <Types.ConvThreadCategory> categories, LocalAccount.PegaUser currentUser, int officialCoinId = 0)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    List <LocalCommunity.BBThread> threads = await GetBBThreadsFromDB(db, currentUser, take : take, categories : categories, officialCoindId : officialCoinId);

                    return(threads);
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { $"Category:{string.Join(",", categories)}" }, ex);
                return(new List <LocalCommunity.BBThread>());
            }
        }
예제 #16
0
        public static async Task <List <LocalCoins.CryptoCoin> > GetAllUserCoinsByPortfolioIdAsync(int portfolioId)
        {
            try
            {
                TypeAdapterConfig.GlobalSettings.Default.NameMatchingStrategy(NameMatchingStrategy.IgnoreCase);
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    List <Coins> serviceCoins = await db.Coins.Where(x => x.PortfolioId == portfolioId).ToListAsync();

                    List <LocalCoins.CryptoCoin> localPortfolios = serviceCoins.Adapt <List <LocalCoins.CryptoCoin> >();
                    return(localPortfolios);
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { "GetAllUserCoinsByPortfolioIdAsync", $"portfolioId:{portfolioId}" }, ex);
                return(new List <LocalCoins.CryptoCoin>());
            }
        }
예제 #17
0
        public static async Task <List <LocalCoins.ExchangeApiInfo> > GetAllUserExchangeAPIAsync(int userId)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    List <ApiDetails> apiDetails = await db.ApiDetails.Where(x => x.UserId == userId).ToListAsync();

                    List <LocalCoins.ExchangeApiInfo> localApis = apiDetails.Adapt <List <LocalCoins.ExchangeApiInfo> >();

                    return(localApis);
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { "GetAllUserExchangeAPIAsync", $"UserId:{userId}" }, ex);
                return(new List <LocalCoins.ExchangeApiInfo>());
            }
        }
예제 #18
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}"));
            }
        }
예제 #19
0
        public static ResultsPair <LocalAccount.PegaUser> ViewUserProfile(string username)
        {
            using (PegasunDBContext db = new PegasunDBContext())
            {
                var user = db.Users.FirstOrDefault(x => x.Username == username);
                if (user == null)
                {
                    return(ResultsPair.CreateError <LocalAccount.PegaUser>($"Could not find the user {username}."));
                }

                var portfolios = db.Portfolios.Where(x => x.UserId == user.UserId && x.DisplayType == 3).ToList();

                LocalAccount.PegaUser localUser = user.Adapt <LocalAccount.PegaUser>();
                localUser.Portfolios           = portfolios.Adapt <List <LocalCoins.Portfolio> >();
                localUser.TotalCreatedThreads  = db.BBThreads.Count(x => x.UserId == user.UserId);
                localUser.TotalCreatedComments = db.BBComments.Count(x => x.UserId == user.UserId);

                return(ResultsPair.CreateSuccess(localUser));
            }
        }
예제 #20
0
        //[TestMethod]
        public void RefreshOfficialCoinsInDB()
        {
            List <LocalCoins.MarketCoin> fetchedCoins = FetchAPILogic.GetAllCoinsFromApiAsync().Result;

            using (PegasunDBContext db = new PegasunDBContext())
            {
                List <OfficialCoins> existingOfficialCoins = db.OfficialCoins.ToList();
                fetchedCoins.ForEach(x =>
                {
                    if (!existingOfficialCoins.Any(o => o.Name == x.CoinMarketCapID))
                    {
                        db.OfficialCoins.Add(new OfficialCoins
                        {
                            Name   = x.CoinMarketCapID,
                            Symbol = x.Symbol
                        });
                    }
                });
                db.SaveChanges();
            }
        }
예제 #21
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}"));
            }
        }
예제 #22
0
        // Todo: Implement coin security. Logged in User's portfolio must contain the ID coins are being CRUD'ed to.

        public static async Task <LocalCoins.CryptoCoin> GetSingleCoinByUser(long coinId)
        {
            try
            {
                TypeAdapterConfig.GlobalSettings.Default.NameMatchingStrategy(NameMatchingStrategy.IgnoreCase);
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    var serviceCoin = await db.Coins.FirstOrDefaultAsync(x => x.CoinId == coinId);

                    if (serviceCoin != null)
                    {
                        return(serviceCoin.Adapt <LocalCoins.CryptoCoin>());
                    }
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { "GetAllUserCoinsByPortfolioIdAsync", $"coinId:{coinId}" }, ex);
            }
            return(null);
        }
예제 #23
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}"));
            }
        }
예제 #24
0
        public static ResultsItem DeleteAPI(int apiId)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    ApiDetails apiDetail = db.ApiDetails.FirstOrDefault(x => x.Id == apiId);
                    if (apiDetail != null)
                    {
                        db.ApiDetails.Remove(apiDetail);
                        db.SaveChanges();
                    }
                }

                return(ResultsItem.Success("Successfully updated deleted API."));
            }
            catch (Exception ex)
            {
                return(ResultsItem.Error($"Unable to delete API. {ex.Message}"));
            }
        }
예제 #25
0
 private static async Task <LocalAccount.PTUserInfo> GetPTUserInfo(int userId)
 {
     try
     {
         TypeAdapterConfig.GlobalSettings.Default.NameMatchingStrategy(NameMatchingStrategy.IgnoreCase);
         using (PegasunDBContext db = new PegasunDBContext())
         {
             PTUserInfo ptUserInfo = db.PTUserInfo.FirstOrDefault(x => x.UserId == userId);
             if (ptUserInfo == null)
             {
                 return((await CreateNewPTUserInfo(new LocalAccount.PegaUser {
                     UserId = userId
                 })).Value);
             }
             return(ptUserInfo.Adapt <LocalAccount.PTUserInfo>());
         }
     }
     catch
     {
         return(null);
     }
 }
예제 #26
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}"));
            }
        }
예제 #27
0
        private static async Task <List <LocalCommunity.BBComment> > GetBBThreadCommentsFromDB(PegasunDBContext db, int threadId, LocalAccount.PegaUser currentUser)
        {
            var query = db.BBComments.Select(x => new
            {
                BBComment  = x,
                User       = new { x.User.UserId, x.User.Username, x.User.Email },
                VoteResult = new { TotalVotes = x.BBCommentVotes.Count, TotalUpvotes = x.BBCommentVotes.Count(v => v.IsUpvote) }
            });

            var result = await query.Where(x => x.BBComment.ThreadId == threadId).ToListAsync();

            List <LocalCommunity.BBComment> comments = new List <LocalCommunity.BBComment>();

            result.ForEach(r =>
            {
                LocalCommunity.BBComment comment = r.BBComment.Adapt <LocalCommunity.BBComment>();
                comment.User                  = r.User.Adapt <LocalAccount.PegaUser>();
                comment.VoteResult            = r.VoteResult.Adapt <LocalCommunity.VoteResult>();
                comment.CurrentLoggedInUserID = (currentUser?.UserId).GetValueOrDefault();

                comments.Add(comment);
            });

            return(comments);
        }
예제 #28
0
        private static async Task <List <LocalCommunity.BBThread> > GetBBThreadsFromDB(PegasunDBContext db, LocalAccount.PegaUser currentUser, int?take = null, int?threadId = null,
                                                                                       List <Types.ConvThreadCategory> categories = null, int officialCoindId = 0)
        {
            if ((take == null || categories.IsNullOrEmpty()) && threadId == null)
            {
                throw new Exception("GetMessageThread: Not all parameters were passed in correctly.");
            }

            var query = db.BBThreads.OrderByDescending(x => x.CreateDate).Select(x => new
            {
                BBThread      = x,
                User          = new { x.User.UserId, x.User.Username, x.User.Email },
                VoteResult    = new { TotalVotes = x.BBThreadVotes.Count, TotalUpvotes = x.BBThreadVotes.Count(v => v.IsUpvote) },
                TotalComments = x.BBComments.Count
            });

            var result = threadId.GetValueOrDefault() > 0 ? await query.Where(x => x.BBThread.ThreadId == threadId).ToListAsync()
                                                          : officialCoindId > 0
                                                               ? await query.Where(x => x.BBThread.OfficialCoinId == officialCoindId).Take(take.GetValueOrDefault()).ToListAsync()
                                                               : await query.Where(x => categories.Any(c => (short)c == x.BBThread.CategoryCode)).Take(take.GetValueOrDefault()).ToListAsync();

            List <LocalCommunity.BBThread> threads = new List <LocalCommunity.BBThread>();

            result.ForEach(r =>
            {
                LocalCommunity.BBThread thread = r.BBThread.Adapt <LocalCommunity.BBThread>();
                thread.User                  = r.User.Adapt <LocalAccount.PegaUser>();
                thread.VoteResult            = r.VoteResult.Adapt <LocalCommunity.VoteResult>();
                thread.TotalComments         = r.TotalComments;
                thread.CurrentLoggedInUserID = (currentUser?.UserId).GetValueOrDefault();

                threads.Add(thread);
            });

            return(threads);
        }