예제 #1
0
 /// <summary>
 /// Constructor method injects the dependency of type TrowooDbContext, PortfolioService, SecurityService into the class upon instantiation.
 /// </summary>
 /// <param name="trowooDbContext">Database Context dependecy injection.</param>
 /// <param name="portfolioService">PortfolioService class dependency injection.</param>
 /// <param name="securityService">SecurityService class dependency injection.</param>
 /// <remarks>
 /// </remarks>
 public PositionService(
     TrowooDbContext trowooDbContext,
     PortfolioService portfolioService,
     SecurityService securityService
     )
 {
     TrowooDbContext  = trowooDbContext;
     PortfolioService = portfolioService;
     SecurityService  = securityService;
 }
예제 #2
0
        /// <summary>
        /// Creates a position for a security within a portfolio.
        /// </summary>
        /// <param name="position">Position object to add.</param>
        /// <param name="portfolioId">Portfolio Id. An integer.</param>
        /// <param name="securityId">Security Id. An integer.</param>
        /// <returns>New Portfolio object.</returns>
        /// <remarks>
        /// <para>Uses Portfolio- and SecurityService classes to obtain respective entities.</para>
        /// </remarks>
        public Position Create(Position position, int portfolioId, int securityId)
        {
            var portfolio = PortfolioService.GetById(portfolioId);
            var security  = SecurityService.GetById(securityId);

            position.Security = security;
            TrowooDbContext.Positions.Add(position);
            portfolio.Positions.Add(position);
            TrowooDbContext.SaveChanges();
            return(position);
        }