public AddEditIssueFinancialVarianceCodeModel(CommonUtils.Operation operation, int itemId)
        {
            CompositionInitializer.SatisfyImports(this);

            OkButtonCommand = new DelegateCommand<object>(OkButtonHander, CanExecuteOkButtonHandler);
            CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, x => true);

            if (operation == CommonUtils.Operation.Add)
            {
                mIssueFinancialVarianceCode = new IssueFinancialVarianceCode();
            }
            else if (operation == CommonUtils.Operation.Update)
            {
                var varianceId = itemId;
                CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

                cmsWebServiceClient.GetIssueFinancialVarianceCodeCompleted += (s1, e1) =>
                {
                    mIssueFinancialVarianceCode = e1.Result;
                    if (DataLoaded != null)
                    {
                        mIssueFinancialVarianceCode = e1.Result;
                        DataLoaded();
                    }
                };
                cmsWebServiceClient.GetIssueFinancialVarianceCodeAsync(varianceId);
            }
        }
예제 #2
0
        public IssueFinancialVarianceCode SaveFinancialVarianceCode(IssueFinancialVarianceCode financialVarianceCode)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                var original = (from x in cee.IssueFinancialVarianceCodes where x.Id == financialVarianceCode.Id select x).FirstOrDefault();

                if (original == null)
                {
                    cee.IssueFinancialVarianceCodes.Add(financialVarianceCode);
                }
                else
                {
                    cee.Entry(original).CurrentValues.SetValues(financialVarianceCode);
                }

                cee.SaveChanges();
            }
            return financialVarianceCode;
        }
        private void LoadData(bool inEditMode)
        {
            var getIssueTrendNoticeStatuses = DatabaseLoader.GetIssueTrendNoticeStatuses();
            var getIssueMilestoneDelayTypes = DatabaseLoader.GetIssueMilestoneDelayTypes();
            var getIssueFinancialVarianceCodes = DatabaseLoader.GetIssueFinancialVarianceCodes();
            var getVendorsTask = DatabaseLoader.GetVendors();

            var tasks = new List<Task>
            {
                getIssueTrendNoticeStatuses,
                getIssueMilestoneDelayTypes,
                getIssueFinancialVarianceCodes,
                getVendorsTask
            };

            Task.Factory.ContinueWhenAll(tasks.ToArray(), x =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    Statuses = getIssueTrendNoticeStatuses.Result;
                    RaisePropertyChanged("Statuses");
                    RaisePropertyChanged("Status");

                    IssueMilestoneDelayTypes = getIssueMilestoneDelayTypes.Result;
                    IssueMilestoneDelayType no_selection = new IssueMilestoneDelayType { Id = -1, Code = NO_SELECTION };
                    IssueMilestoneDelayTypes.Insert(0, no_selection);

                    RaisePropertyChanged("IssueMilestoneDelayTypes");
                    RaisePropertyChanged("SelectedIssueMilestoneDelayType");

                    IssueFinancialVarianceCodes = getIssueFinancialVarianceCodes.Result;
                    IssueFinancialVarianceCode noCode = new IssueFinancialVarianceCode { Id = -1, Code = NO_SELECTION };
                    IssueFinancialVarianceCodes.Insert(0, noCode);

                    RaisePropertyChanged("IssueFinancialVarianceCodes");
                    RaisePropertyChanged("SelectedFinancialVarianceCode");

                    Vendors = getVendorsTask.Result;
                    if (!inEditMode)
                    {
                        SelectedVendor = (from v in Vendors where v.Name.Equals(NO_SELECTION, StringComparison.CurrentCultureIgnoreCase) select v).FirstOrDefault();
                        SelectedIssueMilestoneDelayType = (from v in IssueMilestoneDelayTypes where v.Code.Equals(NO_SELECTION, StringComparison.CurrentCultureIgnoreCase) select v).FirstOrDefault();
                        SelectedFinancialVarianceCode = (from v in IssueFinancialVarianceCodes where v.Code.Equals(NO_SELECTION, StringComparison.CurrentCultureIgnoreCase) select v).FirstOrDefault();
                    }

                    RaisePropertyChanged("Vendors");
                    RaisePropertyChanged("SelectedVendor");

                    if (ViewModelLoaded != null) ViewModelLoaded();
                });
            });
        }