public IssueKpiControlViewModel(Issue issue, IssueKpiControl view)
        {
            mView = view;
            mIssue = issue;
            CompositionInitializer.SatisfyImports(this);
            mTimer.Interval = TimeSpan.FromMilliseconds(500);
            mTimer.Tick += RefreshKpiTable;

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            IssueKpis = new List<IssueKpiTableViewModel>();

            AddButtonCommand = new DelegateCommand<object>(AddButtonHandler, CanExecuteAddButtonHandler);
            RemoveButtonCommand = new DelegateCommand<object>(RemoveButtonHandler, CanExecuteRemoveButtonHandler);
            ShowHideBaselineCommand = new DelegateCommand<object>(ShowHideBaselineHandler, x => true);

            IsBusy = true;

            cmsWebServiceClient.GetIssueKpiVarianceCodesCompleted += (s1, e1) =>
            {
                IssueKpiVarianceCodes = e1.Result;
                RaisePropertyChanged("IssueKpiVarianceCodes");

                cmsWebServiceClient.GetIssueKpisCompleted += (s, e) =>
                {
                     mIssue.IssueKpis = e.Result;

                     DatabaseLoader.GetIssueSettings().ContinueWith(getIssueFinancialSettingsTask =>
                     {
                        CMS.UiFactory.StartNew(() =>
                         {
                             mIssueSetting = getIssueFinancialSettingsTask.Result;

                             foreach (var issueKpi in mIssue.IssueKpis)
                             {
                                 var financialTableItem = new IssueKpiTableViewModel(issueKpi, IssueKpiVarianceCodes, view,
                                     CanUserModifyActuals(), mIssueSetting);
                                 mIssueKpis.Add(financialTableItem);
                             }
                             mIssueKpis = mIssueKpis.OrderBy(x => x.Date).ToList();
                             RaisePropertyChanged("IssueKpis");

                             //mDictionary = Utils.BuildDictionaryForCollection(mIssue.IssueFinancials.Select(x => x.Id).ToList());
                             mIssue.ModifiedObjects.KpisModified = true;

                             if (view.ViewModelLoaded != null)
                             {
                                 view.ViewModelLoaded();
                             }
                             IsBusy = false;
                         });
                     });

                };
                cmsWebServiceClient.GetIssueKpisAsync(mIssue.Id);

            };
            cmsWebServiceClient.GetIssueKpiVarianceCodesAsync();
        }
        private void AddButtonHandler(object parameter)
        {
            if (CanExecuteAddButtonHandler(parameter))
            {
                if (AreAllValid())
                {

                    MonthPicker monthPicker = new MonthPicker(mIssueKpis.Select(x => x.Date).Distinct().ToList());

                    monthPicker.Closed += (s1, e1) =>
                    {
                        if (monthPicker.DialogResult.HasValue && monthPicker.DialogResult.Value)
                        {
                            IsBusy = true;
                            foreach (var date in monthPicker.Dates)
                            {
                                var previousMonthKpi = mIssue.IssueKpis.FirstOrDefault(x => x.IssueId == mIssue.Id && x.Date == date.Date.AddMonths(-1));

                                var issueKpi = new IssueKpi {IssueId = mIssue.Id, Date = date.Date, LastModifiedDate = DateTime.Now, LastModifiedUserId = CMS.User.Id};

                                if (previousMonthKpi != null) issueKpi.KpiDescription = previousMonthKpi.KpiDescription; //Copy Kpi description from previous months

                                var newIssueKpiTableViewModel = new IssueKpiTableViewModel(issueKpi, IssueKpiVarianceCodes, mView,
                                    CanUserModifyActuals(), mIssueSetting);
                                newIssueKpiTableViewModel.ValueGenerationTargetReadOnly = mValueGenerationTargetReadOnly;
                                newIssueKpiTableViewModel.BaselineReadOnly = mBaselineReadOnly;

                                mIssueKpis.Add(newIssueKpiTableViewModel);
                                mIssue.IssueKpis.Add(issueKpi);
                            }
                            mTimer.Start();
                        }
                    };
                    monthPicker.Show();
                }
            }
        }