Exemplo n.º 1
0
        public OrgnizationEditViewModel()
        {
            db = new ClientsContext();

            CreateContractED = new DelegateCommand(() =>
            {
                if (ContractsEd_ == null)
                {
                    var contractsEd = new ContractsEd
                    {
                        IdOrg    = Organization_.Id,
                        Agent    = ContractEdAgents[0],
                        Operator = Operators[0],
                        Num      = db.GetNextContracts(ClientsContext.NextContractType.EDInfodec),
                        Date     = DateTime.Now
                    };
                    db.ContractsEds.Add(contractsEd);
                    db.SaveChanges();
                    ContractsEd_ = contractsEd;
                    OnPropertyChanged("ContractsEd_");
                }
                ;
            });
            CreateContractLD = new DelegateCommand(() =>
            {
                if (ContractsLd_ == null)
                {
                    var contract = new ContractsLd
                    {
                        IdOrg = Organization_.Id,
                        Agent = ContractEdAgents[0],
                        Num   = db.GetNextContracts(ClientsContext.NextContractType.LDCtm),
                        Date  = DateTime.Now
                    };
                    db.ContractsLds.Add(contract);
                    db.SaveChanges();
                    ContractsLd_ = contract;
                    OnPropertyChanged("ContractsLd_");
                }
                ;
            });
            LicenseeLDChangeCommand = new DelegateCommand(() =>
            {
                OrganizationLicenseeLDView fr = new OrganizationLicenseeLDView();
                fr.Left = System.Windows.Forms.Cursor.Position.X;
                fr.Top  = System.Windows.Forms.Cursor.Position.Y;
                if (fr.ShowDialog() == true)
                {
                    var vm = fr.DataContext as OrganizationLicenseeLDViewModel;
                    Organization_.LicenseeLdidOrg           = vm.OrganizationSelected.Id;
                    Organization_.LicenseeLdidOrgNavigation = vm.OrganizationSelected;
                    OnPropertyChanged(nameof(Organization_));
                }
            });
            LicenseeLDEqualCommand = new DelegateCommand(() =>
            {
                Organization_.LicenseeLdidOrg           = Organization_.Id;
                Organization_.LicenseeLdidOrgNavigation = Organization_;
                OnPropertyChanged(nameof(Organization_));
            });
            SaveCommand = new DelegateCommand(() =>
            {
                db.SaveChanges();
            });
        }