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