private void fillRelatedObjects()
        {
            IsInProgress = true;
            parentView.RunAsynchronousOperation(delegate
            {
                var myPlacesCache    = MyPlacesReposidory.GetCache(null);
                var activitiesHandle = ActivitiesReposidory.Instance.BeginEnsure();
                var customersHandle  = CustomersReposidory.Instance.BeginEnsure();
                var groupsHandle     = CustomerGroupsReposidory.Instance.BeginEnsure();
                var myPlacesHandle   = myPlacesCache.BeginEnsure();

                WaitHandle.WaitAll(new WaitHandle[] { activitiesHandle, customersHandle, groupsHandle, myPlacesHandle });


                parentView.SynchronizationContext.Send(delegate
                {
                    Activities     = ActivitiesReposidory.Instance.Items.Values;
                    Customers      = CustomersReposidory.Instance.Items.Values;
                    CustomerGroups = CustomerGroupsReposidory.Instance.Items.Values;
                    MyPlaces       = myPlacesCache.Items.Values;
                    IsInProgress   = false;
                }, null);
            });
        }
示例#2
0
 public void Fill()
 {
     IsInProgress = true;
     parentView.RunAsynchronousOperation(delegate(OperationContext context)
     {
         myTrainingsCache.EnsureLoaded();
         parentView.SynchronizationContext.Send(delegate
         {
             myTrainings.Clear();
             foreach (var myTraining in myTrainingsCache.Items.Values)
             {
                 myTrainings.Add(new MyTrainingViewModel(myTraining));
             }
             IsInProgress = false;
         }, null);
     });
 }
        public void Save()
        {
            var validator = new ObjectValidator(typeof(SupplementCycleDefinitionDTO));

            if (definition.Profile == null)
            {
                definition.Profile = UserContext.Current.CurrentProfile;
            }
            var result = validator.Validate(definition);

            if (!result.IsValid)
            {
                BAMessageBox.ShowValidationError(result.ToBAResults());
                return;
            }
            parentView.RunAsynchronousOperation(delegate
            {
                try
                {
                    context.CycleDefinition = ServiceManager.SaveSupplementsCycleDefinition(definition);
                    //todo:add here clone of saved definition to the cache
                    SupplementsCycleDefinitionsReposidory.Instance.Update(context.CycleDefinition.StandardClone());
                    parentView.SynchronizationContext.Send(delegate
                    {
                        Fill(parentView, context);
                        IsModified = false;
                    }, null);
                }
                catch (ValidationException ex)
                {
                    parentView.SynchronizationContext.Send(state => BAMessageBox.ShowValidationError(ex.Results), null);
                }
                catch (Exception ex)
                {
                    parentView.SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, SuplementsEntryStrings.Exception_SupplementsCycleDefinitionEditorViewModel_Save, ErrorWindow.EMailReport), null);
                }
            }, v =>
            {
                updateButtons(v.State == OperationState.Started);
            });
        }
        public void Disconnect()
        {
            CanDisconnect = false;
            var customerToSave = SelectedCustomer.StandardClone();

            parentWindow.RunAsynchronousOperation(delegate
            {
                try
                {
                    customerToSave.ConnectedAccount = null;
                    customerToSave = ServiceManager.SaveCustomer(customerToSave);
                    CustomersReposidory.Instance.Update(customerToSave);
                    SelectedCustomer = customerToSave;
                    parentWindow.SynchronizationContext.Send(state => EditMode = false, null);
                }
                finally
                {
                    CanDisconnect = true;
                }
            });
        }