コード例 #1
0
        private async Task <OwnerDataModel> GetOwnerAsync(Guid idOwner, bool isBusyIndicatorOn)
        {
            OwnerDataModel owner = new OwnerDataModel();

            try
            {
                if (!isBusyIndicatorOn)
                {
                    BusyIndicator.BlockUI();
                }

                string url      = string.Format("{0}/{1}?id={2}", RoutingConstants.OwnerRoute, RoutingFragmentConstants.GetOwnerWithParentOwnerCode, idOwner);
                var    response = await requestManager.GetAsync <OwnerModel>(url);

                if (response != null && response.IsError)
                {
                    notificationManager.Alert(response.ErrorMessage, response.IsFatalError);
                    await InitializeAsync(isBusyIndicatorOn);

                    owner = null;
                }
                else if (!response.IsError)
                {
                    owner = mappingManager.MapToOwnerDataModel(response.Data);
                }
            }
            finally
            {
                if (!isBusyIndicatorOn)
                {
                    BusyIndicator.UnblockUI();
                }
            }
            return(owner);
        }
コード例 #2
0
        private async Task <bool> ValidateOwnerAsync(OwnerDataModel selectedDirtyOwner)
        {
            string url = string.Format("{0}/{1}?id={2}&ownerCode={3}&parentsOwnerCode={4}&ownersSystemCode={5}", RoutingConstants.OwnerRoute, RoutingFragmentConstants.ValidateCreationOrEditOfAnOwner, selectedDirtyOwner.IdOwner, selectedDirtyOwner.OwnerCode, selectedDirtyOwner.OwnerCodeOfParent, selectedDirtyOwner.SystemCode);
            bool   validationResult = false;

            try
            {
                BusyIndicator.BlockUI();
                RequestResponse <TMValidationResult> response = await requestManager.GetAsync <TMValidationResult>(url);

                if (response != null && response.IsError || response.Data == null)
                {
                    notificationManager.Alert(response.ErrorMessage, string.Empty, response.IsFatalError);
                }

                validationResult = response.Data.IsValid;
                if (!validationResult)
                {
                    notificationManager.Alert(response.Data.ValidationMessage);
                }
            }
            finally
            {
                BusyIndicator.UnblockUI();
            }

            return(validationResult);
        }
コード例 #3
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();
                }
            }
        }
コード例 #4
0
        private async Task <bool> ValidateDeletionOfOwnerAsync()
        {
            string url = string.Format("{0}/{1}?id={2}", RoutingConstants.OwnerRoute, RoutingFragmentConstants.ValidateDeletionOfAnOwner, SelectedOwner.IdOwner);
            bool   validationResult = false;

            try
            {
                BusyIndicator.BlockUI();
                RequestResponse <TMValidationResult> response = await requestManager.GetAsync <TMValidationResult>(url);

                if (response.IsError || response.Data == null)
                {
                    notificationManager.Alert(response.ErrorMessage, string.Empty, response.IsFatalError);
                }

                validationResult = response.Data.IsValid;
                if (!validationResult)
                {
                    notificationManager.Alert(response.Data.ValidationMessage);
                }
            }
            finally
            {
                BusyIndicator.UnblockUI();
            }

            return(validationResult);
        }
コード例 #5
0
        private async Task <bool> ValidateDeletionOfFormAsync(Guid id)
        {
            bool validationResult = id == null;

            if (!validationResult)
            {
                try
                {
                    string url = string.Format("{0}/{1}?id={2}", RoutingConstants.FormRoute, RoutingFragmentConstants.ValidateDeletionOfFormFragment, id);
                    BusyIndicator.BlockUI();
                    RequestResponse <TMValidationResult> response = await requestManager.GetAsync <TMValidationResult>(url);

                    if (response.IsError || response.Data == null)
                    {
                        notificationManager.Alert(response.ErrorMessage, string.Empty, response.IsFatalError);
                    }
                    else if (!response.Data.IsValid)
                    {
                        notificationManager.Alert(response.Data.ValidationMessage);
                    }
                    else
                    {
                        validationResult = true;
                    }
                }
                finally
                {
                    BusyIndicator.UnblockUI();
                }
            }

            return(validationResult);
        }
コード例 #6
0
        private async void InitializeEditFormAsync(FormModel formModel)
        {
            bool canCall = true;

            try
            {
                if (formModel.IdForm != Guid.Empty)
                {
                    BusyIndicator.BlockUI();

                    string path = string.Format("{0}/{1}", RoutingConstants.FormRoute, formModel.IdForm.ToString());
                    RequestResponse <FormModel> response = await requestManager.GetAsync <FormModel>(path);

                    if (response.Data == null || response.IsError)
                    {
                        canCall = false;
                        await InitializeAsync(true);
                    }
                    else
                    {
                        formModel = response.Data;
                    }
                }
            }
            finally
            {
                BusyIndicator.UnblockUI();
            }

            if (canCall)
            {
                OpenEditForm(formModel);
            }
        }
コード例 #7
0
        private async Task InitializeAsync(bool busyIndicatorIsWorking)
        {
            FormModels.Clear();
            var filterQueryString = formFilter.ToQueryString();
            var url = string.Format("{0}?{1}", RoutingConstants.FormRoute, filterQueryString);
            RequestResponse <IEnumerable <FormModel> > response = new RequestResponse <IEnumerable <FormModel> >();

            try
            {
                if (!busyIndicatorIsWorking)
                {
                    BusyIndicator.BlockUI();
                }

                response = await requestManager
                           .GetAsync <IEnumerable <FormModel> >(url);

                if (response != null && !response.IsError)
                {
                    FormModels.AddRange(response.Data);
                    UpdateHeaderView();
                }
                else
                {
                    notificationManager.Alert(response.ErrorMessage, response.IsFatalError);
                }
            }
            finally
            {
                if (!busyIndicatorIsWorking)
                {
                    BusyIndicator.UnblockUI();
                }
            }
        }
コード例 #8
0
        public async Task BtnDeleteForm()
        {
            if (SelectedForm != null)
            {
                try
                {
                    BusyIndicator.BlockUI();
                    bool validationResult = await ValidateDeletionOfFormAsync(SelectedForm.IdForm);

                    if (validationResult)
                    {
                        bool deleteForm = false;
                        notificationManager.Confirm(Resources.ApplicationShortName, Environment.NewLine + Resources.DeleteFormQuestion, () => { deleteForm = true; }, owner: GetView());
                        if (deleteForm)
                        {
                            await DeleteFormAsync();
                        }
                    }
                }
                finally
                {
                    BusyIndicator.UnblockUI();
                }
            }
        }
コード例 #9
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();
            }
        }
コード例 #10
0
        private async Task InitializeAsync(bool isBusyIndicatorOn)
        {
            if (SelectedOwner != null)
            {
                SelectedOwner.IsDirty = false;
            }

            try
            {
                if (!isBusyIndicatorOn)
                {
                    BusyIndicator.BlockUI();
                }

                Owners.Clear();
                ownerFilter.Internal = false;
                var filterQueryString = ownerFilter.ToQueryString();
                var url = string.Format("{0}/{1}?{2}", RoutingConstants.OwnerRoute, RoutingFragmentConstants.GetOwnersWithParentOwnerCode, filterQueryString);
                RequestResponse <IEnumerable <OwnerModel> > response = await requestManager.GetAsync <IEnumerable <OwnerModel> >(url);

                if (response != null && response.IsError)
                {
                    notificationManager.Alert(response.ErrorMessage, response.IsFatalError);
                }
                else
                {
                    List <OwnerDataModel> ownerModels = response.Data.Select(owner => mappingManager.MapToOwnerDataModel(owner)).ToList();
                    Owners.AddRange(ownerModels);
                }
                UpdateHeaderView();
            }
            finally
            {
                if (!isBusyIndicatorOn)
                {
                    BusyIndicator.UnblockUI();
                }
            }
        }
コード例 #11
0
        private async Task DeleteOwnerAsync()
        {
            bool isValid = false;

            if (SelectedOwner != null && SelectedOwner.IdOwner != null)
            {
                isValid = await ValidateDeletionOfOwnerAsync();
            }

            if (isValid)
            {
                try
                {
                    BusyIndicator.BlockUI();
                    var result = await requestManager.DeleteAsync($"{RoutingConstants.OwnerRoute}/{SelectedOwner.IdOwner}");

                    if (result != null && result.IsError)
                    {
                        notificationManager.Alert(result.ErrorMessage, result.IsFatalError);
                    }
                    else if (!result.IsError)
                    {
                        notificationManager.ToastAlert(string.Format(Resources.BankDeleted, SelectedOwner.OwnerCode));
                        var owner = Owners.FirstOrDefault(x => x.IdOwner == SelectedOwner.IdOwner);
                        if (owner != null)
                        {
                            Owners.Remove(owner);
                        }
                    }
                }
                finally
                {
                    BusyIndicator.UnblockUI();
                }
            }
        }
コード例 #12
0
        private async Task UpdateGridAsync(UpdateFormEventArgs updatedFormArgs)
        {
            Guid callingOwnerId = updatedFormArgs.OwnerChooseModel.Id;
            Guid?formId         = updatedFormArgs.FormId;

            string path = string.Format("{0}/{1}", RoutingConstants.FormRoute, formId.ToString());

            try
            {
                BusyIndicator.BlockUI();
                var result = await requestManager.GetAsync <FormModel>(path);

                if (result.Data == null || result.IsError)
                {
                    await InitializeAsync(true);
                }
                else
                {
                    FormModel resultForm = result.Data;
                    if (updatedFormArgs.IsNew)
                    {
                        bool scrollToFirst = false;
                        if (OwnerChooseModel != null)
                        {
                            if (OwnerChooseModel.Id == callingOwnerId)
                            {
                                FormModels.Add(resultForm);
                                SelectedForm = FormModels.FirstOrDefault(x => x.IdForm.Equals(resultForm.IdForm));
                            }
                            else
                            {
                                scrollToFirst = true;
                            }
                        }
                        else
                        {
                            FormModels.Add(resultForm);
                            SelectedForm = FormModels.FirstOrDefault(x => x.IdForm.Equals(resultForm.IdForm));
                        }

                        ScrollOrRefreshGrid(this, new CleanFilterEventArgs()
                        {
                            ScrollToFirst = scrollToFirst
                        });
                    }
                    else
                    {
                        FormModel editedFormModel = FormModels.FirstOrDefault(x => x.IdForm == formId);
                        if (editedFormModel != null)
                        {
                            if (OwnerChooseModel != null && callingOwnerId != OwnerChooseModel.Id)
                            {
                                if (FormModels.Any())
                                {
                                    FormModels.Remove(editedFormModel);
                                }
                            }
                            else
                            {
                                int editedFormModelIndex = FormModels.IndexOf(editedFormModel);
                                if (editedFormModelIndex != -1)
                                {
                                    FormModels[editedFormModelIndex] = resultForm;
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                BusyIndicator.UnblockUI();
            }
        }