예제 #1
0
        public DomainObjects.Portfolio.Portfolio UpdateWithDistribution(string email, int portfolioId, decimal price, string name,
                                                                        string description, Dictionary <int, double> distribution)
        {
            var user      = UserBusiness.GetValidUser(email);
            var portfolio = GetValidByOwner(user.Id, portfolioId);

            if (portfolio == null)
            {
                throw new ArgumentException("Invalid portfolio.");
            }

            var projection = ProjectionBusiness.Get(portfolio.ProjectionId.Value);

            if (projection == null)
            {
                throw new ArgumentException("Invalid projection.");
            }

            var risk = PortfolioBusiness.GetRisk(projection.ProjectionValue, distribution);

            using (var transaction = new TransactionalDapperCommand())
            {
                var portfolioDetail = PortfolioDetailBusiness.SetNew(portfolioId, price, name, description, true);
                transaction.Insert(portfolioDetail);

                var newProjection = ProjectionBusiness.SetNew(portfolio.Id, projection.ProjectionValue, risk, projection.OptimisticProjectionValue, projection.PessimisticProjectionValue);
                transaction.Insert(newProjection);

                var distributions = DistributionBusiness.SetNew(newProjection.Id, distribution);
                foreach (Distribution dist in distributions)
                {
                    transaction.Insert(dist);
                }

                portfolio.ProjectionId = newProjection.Id;
                transaction.Update(portfolio);

                newProjection.Distribution = distributions;
                portfolio.Detail           = portfolioDetail;
                portfolio.Projection       = newProjection;
                transaction.Commit();
            }
            return(portfolio);
        }
예제 #2
0
        public DomainObjects.Portfolio.Portfolio Create(string email, int advisorId, decimal price, string name, string description,
                                                        double projectionValue, double?optimisticProjection, double?pessimisticProjection, Dictionary <int, double> distribution)
        {
            var advisor = AdvisorBusiness.GetWithOwner(advisorId, email);

            if (advisor == null)
            {
                throw new ArgumentException("Invalid advisor.");
            }

            var risk          = GetRisk(projectionValue, distribution);
            var advisorDetail = AdvisorDetailBusiness.GetForAutoEnabled(advisorId);

            var portfolio = new DomainObjects.Portfolio.Portfolio();

            portfolio.AdvisorId    = advisorId;
            portfolio.CreationDate = DateTime.UtcNow;
            using (var transaction = new TransactionalDapperCommand())
            {
                transaction.Insert(portfolio);
                var detail = PortfolioDetailBusiness.SetNew(portfolio.Id, price, name, description, true);
                transaction.Insert(detail);
                var projection = ProjectionBusiness.SetNew(portfolio.Id, projectionValue, risk, optimisticProjection, pessimisticProjection);
                transaction.Insert(projection);
                var distributions = DistributionBusiness.SetNew(projection.Id, distribution);
                foreach (Distribution dist in distributions)
                {
                    transaction.Insert(dist);
                }

                portfolio.ProjectionId = projection.Id;
                transaction.Update(portfolio);
                if (advisorDetail != null)
                {
                    advisorDetail = AdvisorDetailBusiness.SetNew(advisorId, advisorDetail.Name, advisorDetail.Description, true);
                    transaction.Insert(advisorDetail);
                }
                projection.Distribution = distributions;
                portfolio.Projection    = projection;
                portfolio.Detail        = detail;
                transaction.Commit();
            }
            return(portfolio);
        }