コード例 #1
0
        public CustomerDataViewModel(IUnityContainer container, ICustomerService customerService,
                                     INotificationService notificationService, CustomerModel customer)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            this.customerService     = customerService;
            this.notificationService = notificationService;
            this.SaveCustomerCommand = new RelayCommand(onSaveCustomerExecuted, onSaveCustomerCanExecute);

            this.customer          = customer;
            this.customerViewModel = new CustomerModelViewModel(customer);

            var company = customer as CompanyModel;

            if (company != null)
            {
                this.companyViewModel = new CompanyModelViewModel(company);
                return;
            }

            var person = customer as PersonModel;

            if (person != null)
            {
                this.personViewModel            = new PersonModelViewModel(person);
                this.CustomerSearchBoxViewModel =
                    container.Resolve <CustomerSearchBoxViewModel>(new ParameterOverrides
                {
                    { "customerType", CustomerType.Company }
                });

                if (person.Company != null)
                {
                    this.CustomerSearchBoxViewModel.SelectedCustomer = new CustomerDisplayNameViewModel(person.Company);
                }

                this.CustomerSearchBoxViewModel.PropertyChanged += ((s, e) =>
                {
                    if (e.PropertyName == "SelectedCustomer" && s is CustomerSearchBoxViewModel)
                    {
                        var selectedCustomer = (s as CustomerSearchBoxViewModel).SelectedCustomer;
                        person.Company = selectedCustomer == null ? null : selectedCustomer.Model as CompanyModel;
                    }
                });

                return;
            }

            throw new ArgumentOutOfRangeException("customer");
        }
コード例 #2
0
        public void Test_CompanyModelProperties()
        {
            var vm = new CompanyModelViewModel();

            vm.PropertyChanged += ((s, e) =>
            {
                if (e.PropertyName == "Name")
                {
                    string name = (s as CompanyModelViewModel).Name;
                    Assert.AreEqual("Firma X", name);
                }
            });

            vm.Name = "Firma X";
            vm.UID  = "1234";

            Assert.AreEqual("Firma X", vm.Name);
            Assert.AreEqual("1234", vm.UID);
        }