Exemple #1
0
        private async Task LoadDataGridCollectionAsync()
        {
            try
            {
                this.progressRing.IsActive = true;

                IList <DataGridViewModel> data = await InsuranceClaimDataLoader.GetDataAsync();

                foreach (var item in data)
                {
                    if (!string.IsNullOrEmpty(item.ProductImageUri))
                    {
                        item.ProductImage = new BitmapImage(new Uri(item.ProductImageUri));
                    }
                    if (!string.IsNullOrEmpty(item.FormImageUri))
                    {
                        item.FormImage = new BitmapImage(new Uri(item.FormImageUri));
                    }
                }
                DataGridCollection.Clear();
                DataGridCollection.AddRange(data);
            }
            catch (Exception ex)
            {
                await Util.GenericApiCallExceptionHandler(ex, "Failure loading grid data");
            }
            finally
            {
                this.progressRing.IsActive = false;
            }
        }
Exemple #2
0
        private async void OnDeleteDataGridRowButtonClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                this.dataGrid.Tag = DataGridAction;

                var currentRow = (sender as Button)?.DataContext as DataGridViewModel;
                if (currentRow != null)
                {
                    ContentDialog dialog = new ContentDialog
                    {
                        Title               = "Are you sure?",
                        Content             = $"This operation will delete this claim permanently.",
                        PrimaryButtonText   = "Delete",
                        SecondaryButtonText = "Cancel",
                        DefaultButton       = ContentDialogButton.Secondary
                    };

                    ContentDialogResult result = await dialog.ShowAsync();

                    if (result == ContentDialogResult.Primary)
                    {
                        var  itemToRemove         = DataGridCollection.FirstOrDefault(x => x.Id == currentRow.Id);
                        bool entryRemovedFromFile = DataGridCollection.Remove(itemToRemove);
                        if (entryRemovedFromFile)
                        {
                            await InsuranceClaimDataLoader.DeleteDataAsync(new List <DataGridViewModel>() { itemToRemove });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await Util.GenericApiCallExceptionHandler(ex, "Failure deleting datagrid row");
            }
            finally
            {
                this.dataGrid.Tag          = null;
                this.dataGrid.SelectedItem = null;
            }
        }
Exemple #3
0
        private async void OnSubmitClaimButtonClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                this.progressRing.IsActive = true;

                CloseDetailsView();

                if (CurrentInputProductImage != null && (CurrentInputFormImage != null || CurrentInputFormFile != null))
                {
                    var claim = new DataGridViewModel(Guid.NewGuid())
                    {
                        ClaimId      = ++claimId,
                        IsFormImage  = IsFormImageSource,
                        CustomName   = emptyRow,
                        Date         = emptyRow,
                        WarrantyId   = emptyRow,
                        Warranty     = emptyRow,
                        InvoiceTotal = emptyRow
                    };

                    // store image file to local folder
                    if (CurrentInputProductImage.ImageUrl != null)
                    {
                        claim.ProductImageUri = CurrentInputProductImage.ImageUrl;
                        claim.ProductImage    = new BitmapImage(new Uri(CurrentInputProductImage.ImageUrl));
                    }
                    else if (CurrentInputProductImage.GetImageStreamCallback != null)
                    {
                        StorageFile imageFile = await InsuranceClaimDataLoader.CreateFileInLocalFolderAsync(claim.Id, "ProductImage.jpg");

                        await Util.SaveBitmapToStorageFileAsync(await CurrentInputProductImage.GetImageStreamCallback(), imageFile);

                        claim.ProductImageUri = imageFile.Path;
                        claim.ProductImage    = new BitmapImage(new Uri(imageFile.Path));
                    }

                    // store form file to local folder
                    if (isFormImageSource)
                    {
                        CurrentInputFormFile = await InsuranceClaimDataLoader.CreateFileInLocalFolderAsync(claim.Id, "FormImage.jpg");

                        if (CurrentInputFormImage?.ImageUrl != null)
                        {
                            claim.FormImageUri = CurrentInputFormImage.ImageUrl;
                            claim.FormImage    = new BitmapImage(new Uri(CurrentInputFormImage.ImageUrl));

                            await Util.DownloadAndSaveBitmapAsync(CurrentInputFormImage.ImageUrl, CurrentInputFormFile);
                        }
                        else if (CurrentInputFormImage?.GetImageStreamCallback != null)
                        {
                            await Util.SaveBitmapToStorageFileAsync(await CurrentInputFormImage.GetImageStreamCallback(), CurrentInputFormFile);

                            claim.FormImageUri = CurrentInputFormFile.Path;
                            claim.FormImage    = new BitmapImage(new Uri(CurrentInputFormFile.Path));
                        }
                    }
                    else if (CurrentInputFormFile != null)
                    {
                        StorageFile file = await InsuranceClaimDataLoader.CopyFileToLocalFolderAsync(CurrentInputFormFile, $"FormFile{CurrentInputFormFile.FileType}", claim.Id);

                        claim.FormFile = new Uri(file.Path);
                    }

                    DataGridCollection.Add(claim);

                    // show submitted form
                    this.inputSubmittedGrid.Visibility = Visibility.Visible;

                    // validate product image and form
                    await ProcessClaimAsync(claim);

                    // store current claim
                    await InsuranceClaimDataLoader.SaveOrUpdateDataAsync(claim);

                    // update datagrid collection
                    await LoadDataGridCollectionAsync();
                }
            }
            catch (Exception ex)
            {
                await Util.GenericApiCallExceptionHandler(ex, "Failure processing claim");
            }
            finally
            {
                this.progressRing.IsActive = false;
            }
        }