The following example shows how to add a new portfolio to the Data Source “ManagingEnergy_Template”. However for convenience, in this example we use the Portfolio Manager to add our new portfolio instead of using the Data Source object directly. The reason for this might not be initially obvious, but consider the extra effort (or overhead) required to first retrieve the Data Source object in order to add the new Portfolio. This methodology is useful in web applications where you have to perform an operation upon a post back and can easily store the Data Source ID in session state.
// create a new Portfolio Portfolio portfolio = new Portfolio("MyNewPortfolio"); portfolio.Name = "My New Portfolio"; portfolio.Description = "The description for my new portfolio";
// add the portfolio to the Data Source "ManagingEnergy_Template" api.PortfolioManager.AddPortfolio("ManagingEnergy_Template", portfolio);
|
A Note Regarding the Manager Classes
Under the hood the DataSource class invokes the PortfolioManager for the operations it exposes which deal with Portfolios. This is a common theme for all API objects.