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}")); } }
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}")); } }
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}")); } }
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}")); } }
//[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(); } }