public ContactsEditorViewModel()
        {
            SelectedContact = (Observable <ObservableContact>)ValidatedObservableFactory.ValidatedObservable(new ObservableContact());

            Contacts = new EntityDataViewModel(10, typeof(Contact), true);


            Contacts.OnSelectedRowsChanged += OnSelectedRowsChanged;
            Contacts.FetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' returntotalrecordcount='true' no-lock='true' distinct='false' count='{0}' paging-cookie='{1}' page='{2}'>
                <entity name='contact'>
                    <attribute name='firstname' />
                    <attribute name='lastname' />
                    <attribute name='telephone1' />
                    <attribute name='birthdate' />
                    <attribute name='accountrolecode' />
                    <attribute name='parentcustomerid'/>
                    <attribute name='transactioncurrencyid'/>
                    <attribute name='creditlimit'/>
                    <attribute name='numberofchildren'/>
                    <attribute name='contactid' />
                    <attribute name='ownerid'/>{3}
                  </entity>
                </fetch>";

            // Register validation
            ContactValidation.Register(Contacts.ValidationBinder);
            ContactValidation.Register(new ObservableValidationBinder(this.SelectedContact));
        }
Ejemplo n.º 2
0
        public ConnectionsViewModel(EntityReference parentRecordId, Dictionary <string, string> connectToTypes)
        {
            ParentRecordId = parentRecordId;
            ObservableConnection connection = new ObservableConnection(connectToTypes);

            connection.Record2Id.SetValue(ParentRecordId);
            ConnectionEdit = (Observable <ObservableConnection>)ValidatedObservableFactory.ValidatedObservable(connection);
            Connections.OnSelectedRowsChanged += Connections_OnSelectedRowsChanged;
            Connections.OnDataLoaded.Subscribe(Connections_OnDataLoaded);
            ConnectionEdit.GetValue().OnSaveComplete += ConnectionsViewModel_OnSaveComplete;
            ObservableConnection.RegisterValidation(Connections.ValidationBinder);
        }
Ejemplo n.º 3
0
        public ContactViewModel()
        {
            ObservableContact contact = new ObservableContact();

            Contacts    = new EntityDataViewModel(15, typeof(Contact), false);
            ContactEdit = (Observable <ObservableContact>)ValidatedObservableFactory.ValidatedObservable(contact);//Knockout.Observable<ObservableContact>(new ObservableContact());
            ContactEdit.GetValue().OnSaveComplete += ContactViewModel_OnSaveComplete;
            ErrorMessage = Knockout.Observable <string>();
            Contacts.OnDataLoaded.Subscribe(Contacts_OnDataLoaded);

            ObservableContact.RegisterValidation(Contacts.ValidationBinder);
        }
Ejemplo n.º 4
0
        public ConnectionsViewModel(EntityReference parentRecordId, string[] connectToTypes, int pageSize, string viewFetchXml)
        {
            Connections = new EntityDataViewModel(pageSize, typeof(Connection), true);
            ParentRecordId.SetValue(parentRecordId);
            _viewFetchXml = viewFetchXml;
            ObservableConnection connection = new ObservableConnection(connectToTypes);

            connection.Record2Id.SetValue(parentRecordId);
            ConnectionEdit = (Observable <ObservableConnection>)ValidatedObservableFactory.ValidatedObservable(connection);

            Connections.OnDataLoaded.Subscribe(Connections_OnDataLoaded);
            ConnectionEdit.GetValue().OnSaveComplete += ConnectionsViewModel_OnSaveComplete;
            ObservableConnection.RegisterValidation(Connections.ValidationBinder);
            AllowAddNew = Knockout.DependentObservable <bool>(AllowAddNewComputed);
        }
Ejemplo n.º 5
0
        public ContactsViewModel(EntityReference parentCustomerId, int pageSize)
        {
            Contacts = new EntityDataViewModel(pageSize, typeof(Contact), true);
            ParentCustomerId.SetValue(parentCustomerId);

            ObservableContact contact = new ObservableContact();

            contact.ParentCustomerId.SetValue(parentCustomerId);
            ContactEdit = (Observable <ObservableContact>)ValidatedObservableFactory.ValidatedObservable(contact);
            ContactEdit.GetValue().OnSaveComplete += ContactsViewModel_OnSaveComplete;
            Contacts.OnDataLoaded.Subscribe(Contacts_OnDataLoaded);
            ObservableContact.RegisterValidation(Contacts.ValidationBinder);
            AllowAddNew = Knockout.DependentObservable <bool>(AllowAddNewComputed);
            AllowOpen   = Knockout.Observable <bool>(false);
            Contacts.OnSelectedRowsChanged += Contacts_OnSelectedRowsChanged;
        }
Ejemplo n.º 6
0
        public ConnectionsViewModel(EntityReference parentRecordId, string[] connectToTypes, int pageSize, FetchQuerySettings view)
        {
            Connections = new EntityDataViewModel(pageSize, typeof(Connection), true);
            if (view != null)
            {
                _viewFetchXml = QueryParser.GetFetchXmlParentFilter(view, "record1id");
                // Set initial sort
                _defaultSortCol = new SortCol(view.OrderByAttribute, !view.OrderByDesending);
            }

            ParentRecordId.SetValue(parentRecordId);

            ObservableConnection connection = new ObservableConnection(connectToTypes);

            connection.Record2Id.SetValue(parentRecordId);
            ConnectionEdit = (Observable <ObservableConnection>)ValidatedObservableFactory.ValidatedObservable(connection);

            Connections.OnDataLoaded.Subscribe(Connections_OnDataLoaded);
            ConnectionEdit.GetValue().OnSaveComplete += ConnectionsViewModel_OnSaveComplete;
            ObservableConnection.RegisterValidation(Connections.ValidationBinder);
            AllowAddNew = Knockout.DependentObservable <bool>(AllowAddNewComputed);
        }
        public StartStopSessionViewModel(Guid activityToStartStop, Guid sessionToStartStop)
        {
            // Create start session
            dev1_session newSession = new dev1_session();

            newSession.dev1_StartTime = DateTime.Now;
            StartSession = (Observable <SessionVM>)ValidatedObservableFactory.ValidatedObservable(new SessionVM(this, newSession));

            // Load the Sessions
            dev1_session session   = (dev1_session)OrganizationServiceProxy.Retrieve(dev1_session.EntityLogicalName, "{FD722AC2-B234-E211-A471-000C299FFE7D}", new string[] { "AllColumns" });
            SessionVM    sessionVM = new SessionVM(this, session);

            StopSession = (Observable <SessionVM>)ValidatedObservableFactory.ValidatedObservable(sessionVM);

            DependentObservableOptions <bool> isFormValidDependantProperty = new DependentObservableOptions <bool>();

            isFormValidDependantProperty.Model = this;

            isFormValidDependantProperty.GetValueFunction = new Func <bool>(delegate
            {
                StartStopSessionViewModel vm = (StartStopSessionViewModel)isFormValidDependantProperty.Model;

                if (vm.StartNewSession.GetValue())
                {
                    return(ValidationRules.AreValid(
                               new object[] { ((StartStopSessionViewModel)isFormValidDependantProperty.Model).StopSession,
                                              ((StartStopSessionViewModel)isFormValidDependantProperty.Model).StartSession }));
                }
                else
                {
                    return(ValidationRules.AreValid(
                               new object[] { ((StartStopSessionViewModel)isFormValidDependantProperty.Model).StopSession }));
                }
            });
            CanSave = Knockout.DependentObservable <bool>(isFormValidDependantProperty);
        }