示例#1
0
        private async Task GetOwnerAndUpdateGridAsync(OwnerDataModel selectedDirtyOwner, bool isBusyIndicatorOn)
        {
            try
            {
                if (!isBusyIndicatorOn)
                {
                    BusyIndicator.BlockUI();
                }

                if (selectedDirtyOwner == null || selectedDirtyOwner.IdOwner == null)
                {
                    await InitializeAsync(true);

                    throw new ArgumentNullException();
                }

                OwnerDataModel resultOwner = await GetOwnerAsync(selectedDirtyOwner.IdOwner, isBusyIndicatorOn);

                if (resultOwner != null)
                {
                    int indexOfOwner = Owners.IndexOf(selectedDirtyOwner);
                    SelectedOwner.IsDirty = false;
                    Owners.RemoveAt(indexOfOwner);
                    Owners.Insert(indexOfOwner, resultOwner);
                }
            }
            finally
            {
                if (!isBusyIndicatorOn)
                {
                    BusyIndicator.UnblockUI();
                }
            }
        }
示例#2
0
        private async Task SaveChangesAsync(OwnerDataModel selectedDirtyOwner, bool updateGrid)
        {
            try
            {
                BusyIndicator.BlockUI();
                if (selectedDirtyOwner == null)
                {
                    await InitializeAsync(true);

                    throw new ArgumentNullException();
                }

                OwnerModel      owner    = mappingManager.MapToOwnerModel(selectedDirtyOwner);
                RequestResponse response = new RequestResponse();
                if (selectedDirtyOwner.IsNew)
                {
                    response = await requestManager.PostAsync <OwnerModel>(RoutingConstants.OwnerRoute, owner);

                    updateGrid = false;
                }
                else
                {
                    response = await requestManager.PatchAsync(RoutingConstants.OwnerRoute, owner);
                }

                if (response != null && response.IsError)
                {
                    notificationManager.Alert(response.ErrorMessage, response.IsFatalError);
                    await InitializeAsync(true);
                }
                else if (updateGrid)
                {
                    await GetOwnerAndUpdateGridAsync(selectedDirtyOwner, true);
                }
                else if (!updateGrid)
                {
                    selectedDirtyOwner = mappingManager.MapToOwnerDataModel((response as RequestResponse <OwnerModel>).Data);
                    Owners.RemoveAt(0);
                    Owners.Insert(0, selectedDirtyOwner);
                    ScrollToNewOwner(this, new SelectAndMoveToNewItemInGridArgs()
                    {
                        NewItem = selectedDirtyOwner
                    });
                }
            }
            finally
            {
                BusyIndicator.UnblockUI();
            }
        }