Пример #1
0
        private async void ButtonSubmit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool isNameEmpty        = string.IsNullOrEmpty(txtName.Text);
                bool isDescriptionEmpty = string.IsNullOrEmpty(txtDescription.Text);
                bool isFilePathEmpty    = string.IsNullOrEmpty(uploadFilePath);
                bool isFileIdEmpty      = string.IsNullOrEmpty(txtId.Text);

                if (isNew)
                {
                    if (!isNameEmpty && !isDescriptionEmpty && !isFilePathEmpty && !isFileIdEmpty && !txtId.Text.Contains(" "))
                    {
                        ProgressDialogController controller = await this.ShowProgressAsync("Please wait...", "");

                        controller.SetIndeterminate();
                        controller.SetCancelable(false);

                        string[] temp   = uploadFilePath.Split('.');
                        string   fileId = $"{txtId.Text}.{temp[temp.Length - 1]}";

                        var           item       = new Document();
                        List <string> readerList = new List <string>()
                        {
                            "a"
                        };

                        item["id"]          = fileId;
                        item["name"]        = txtName.Text;
                        item["description"] = txtDescription.Text;
                        item["status"]      = 0;
                        item["readerList"]  = readerList;

                        Console.WriteLine("done here");

                        controller.SetMessage("Uploading file");
                        await Task.Run(() => Models.S3Bucket.UploadFile(uploadFilePath, fileId, Models.MyAWSConfigs.RefImagesBucketName));

                        controller.SetMessage("Adding database record");
                        await Task.Run(() => Models.Dynamodb.PutItem(item, Models.MyAWSConfigs.RefPersonsDBTableName));

                        controller.SetMessage("Creating face indexes");
                        await Task.Run(() => Models.FaceCollection.AddFace(fileId, Models.MyAWSConfigs.FaceCollectionID));

                        await controller.CloseAsync();

                        txtName.Text          = "";
                        txtDescription.Text   = "";
                        txtId.Text            = "";
                        imgUploadImage.Source = null;

                        this.allPeoplePageView.LoadPersonsData().ConfigureAwait(false);

                        await this.ShowMessageAsync("Success", "New Person added", MessageDialogStyle.Affirmative);

                        this.Close();
                    }
                    else
                    {
                        await this.ShowMessageAsync("Error", "Please check all fields", MessageDialogStyle.Affirmative);
                    }
                }
                else
                {
                    if (!isNameEmpty && !isDescriptionEmpty)
                    {
                        ProgressDialogController controller = await this.ShowProgressAsync("Please wait...", "");

                        controller.SetIndeterminate();
                        controller.SetCancelable(false);

                        var item = new Document();

                        item["id"]          = this.id;
                        item["name"]        = txtName.Text;
                        item["description"] = txtDescription.Text;

                        controller.SetMessage("Adding database record");
                        await Task.Run(() => Models.Dynamodb.UpdateItem(item, Models.MyAWSConfigs.RefPersonsDBTableName));

                        await controller.CloseAsync();

                        txtName.Text          = "";
                        txtDescription.Text   = "";
                        txtId.Text            = "";
                        imgUploadImage.Source = null;

                        detectedPerson.BackToRef();

                        await this.ShowMessageAsync("Success", "Person Updated", MessageDialogStyle.Affirmative);

                        this.Close();
                    }
                    else
                    {
                        await this.ShowMessageAsync("Error", "Please check all fields", MessageDialogStyle.Affirmative);
                    }
                }
            }
            catch
            {
                await this.ShowMessageAsync("Error", "Task not completed", MessageDialogStyle.Affirmative);
            }
        }