public Action SaveCommand() { if (_saveCommand == null) { _saveCommand = delegate() { bool confirmed = Script.Confirm(String.Format("Are you sure save these sessions?")); if (!confirmed) { return; } SessionVM stopSession = StopSession.GetValue(); dev1_session sessionToUpdate = stopSession.GetUpdatedModel(); try { OrganizationServiceProxy.Update(sessionToUpdate); // Save next session if (StartNewSession.GetValue()) { dev1_session nextSession = StartSession.GetValue().GetUpdatedModel(); OrganizationServiceProxy.Create(nextSession); } } catch (Exception ex) { Script.Alert("There was a problem saving your session. Please contact your system administrator.\n\n" + ex.Message); } }; } return(_saveCommand); }
public void AddValidation() { SessionVM self = this; ValidationRules.CreateRules() .AddRequiredMsg("Enter the activity you wish to stop") .Register(Activity); ValidationRules.CreateRules() .AddRequiredMsg("Enter the start date of the session") .AddRule("Start date must be before the end date", delegate(object value) { bool isValid = true; DateTime endTime = self.dev1_endtime.GetValue(); if ((endTime != null) && (value != null)) { isValid = endTime > (DateTime)value; } return(isValid); }) .Register(dev1_starttime); ValidationRules.CreateRules() .AddRequiredMsg("Enter the end time of the session") .Register(dev1_endtime); ValidationRules.CreateRules() .AddRequiredMsg("Enter the duration of the session") .Register(dev1_duration); }
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); }
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); }