public void TakeData(BuRootModel model)
        {
            this.KeptRootModel = model;
            this.RegisterInChangeWatcher(model);
            var lines = Helper.ToObservableCollection(model.Items.Select(x => Helper.As <IBuLineModel>(x)));

            lines.Add(new BuCashModel(model.Cash));
            lines.Add(new BuTotalModel(model.TargetTotal));
            this.Lines = lines;
            var portfolioId           = this.LastValidInput.BottomUpPortfolioId;
            var registeredExpressions = new List <EditableExpressionModel>();

            foreach (var line in model.Items)
            {
                EditableExpressionModel targetExpression = line.Target;
                var securityId = line.Security.Id;
                var requestBuPortfolioSecurityTargetCommentsCommand = new DelegateCommand(delegate
                {
                    this.RequesCommentsForBuPortfolioSecurityTarget(portfolioId, securityId);
                });
                targetExpression.RegisterForBeingWatched(this, requestBuPortfolioSecurityTargetCommentsCommand);
                registeredExpressions.Add(targetExpression);
            }


            this.FinishLoading();
            this.OnGotData();
        }
Exemple #2
0
        protected void TakeData(BgaRootModel data)
        {
            this.defaultExpandCollapseStateSetter.SetDefaultCollapseExpandState(data.Globe);
            var residents = this.traverser.Traverse(data);

            // register for listening to any change to base and portfolio adjustment, if change happens we need to initiate recalculation
            this.RegisterResidentsForValueChangeWatch(residents);
            this.RegisterOveralyFactorsForValueChangeWatch(data.Factors);

            // we need an observable collection to make filtering (collapsing/expanding) work, because it is triggered by the CollectionChanged event
            this.Residents = new ObservableCollection <IGlobeResident>(residents);
            this.Factors   = new ObservableCollection <BgaFactorItemModel>(data.Factors.Items);
            this.RootModel = data;

            var targetingTypeId = this.LastValidInput.TargetingTypeId;
            var portfolioId     = this.LastValidInput.BroadGlobalActivePortfolioId;

            var registeredExpressions = new List <EditableExpressionModel>();

            foreach (var factor in factors)
            {
                EditableExpressionModel factorExpression = factor.OverlayFactor;
                var securityId = factor.BottomUpPortfolio.Fund.Id;
                var requestOverlayFactorCommentsCommand = new DelegateCommand(delegate
                {
                    this.RequestOverlayFactorComments(portfolioId, securityId);
                });
                factorExpression.RegisterForBeingWatched(this, requestOverlayFactorCommentsCommand);
                registeredExpressions.Add(factorExpression);
            }

            foreach (var resident in residents)
            {
                var basketId = -1;

                EditableExpressionModel baseExpression = null;
                EditableExpressionModel portfolioAdjustmentExpression = null;
                if (resident is BasketCountryModel)
                {
                    var r = resident as BasketCountryModel;
                    basketId       = r.Basket.Id;
                    baseExpression = r.Base;
                    portfolioAdjustmentExpression = r.PortfolioAdjustment;
                }
                if (resident is BasketRegionModel)
                {
                    var r = resident as BasketRegionModel;
                    basketId       = r.Basket.Id;
                    baseExpression = r.Base;
                    portfolioAdjustmentExpression = r.PortfolioAdjustment;
                }

                if (basketId > -1)
                {
                    var requestBaseCommentsCommand = new DelegateCommand(delegate
                    {
                        this.RequestBaseComments(targetingTypeId, basketId);
                    });
                    baseExpression.RegisterForBeingWatched(this, requestBaseCommentsCommand);
                    registeredExpressions.Add(baseExpression);

                    var requestPortfolioAdjustmentCommentsCommand = new DelegateCommand(delegate
                    {
                        this.RequestPortfolioAdjustmentComments(targetingTypeId, portfolioId, basketId);
                    });
                    portfolioAdjustmentExpression.RegisterForBeingWatched(this, requestPortfolioAdjustmentCommentsCommand);
                    registeredExpressions.Add(portfolioAdjustmentExpression);
                }
            }

            this.FinishLoading();
            this.OnGotData();
        }