コード例 #1
0
        private async void ButtonSubmit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool isFilePathEmpty = string.IsNullOrEmpty(uploadFilePath);

                if (!isFilePathEmpty)
                {
                    ProgressDialogController controller = await this.ShowProgressAsync("Please wait...", "Uploading data");

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

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

                    string BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory;
                    string filePath          = BaseDirectoryPath + $"Resources\\Images\\{fileId}";

                    Item   item     = Dynamodb.GetItem(myId, MyAWSConfigs.AdminDBTableName);
                    string oldImage = item["aPropic"];
                    Console.WriteLine("><><><><><><><><><><>" + oldImage);

                    //Delete old profile pic in local
                    //string oldFilePath = BaseDirectoryPath + $"Resources\\Images\\{oldImage}";
                    //DeleteOldPic(oldFilePath);

                    //Delete old profile pic in s3Bucket
                    S3Bucket.DeleteFile(oldImage, MyAWSConfigs.AdminS3BucketName);

                    item["aPropic"] = fileId;

                    await Task.Run(() => Models.S3Bucket.UploadFile(uploadFilePath, fileId, MyAWSConfigs.AdminS3BucketName));

                    MessageBox.Show(fileId);
                    await Task.Run(() => Models.Dynamodb.UpdateItem(item, Models.MyAWSConfigs.AdminDBTableName));

                    await controller.CloseAsync();

                    await this.ShowMessageAsync("Success", "Changed Successfully..", MessageDialogStyle.Affirmative);

                    //activity recorded
                    Models.ActivityLogs.Activity(Models.Components.AdminComponent, "User Changed Profile Picture");

                    //imgUploadImage.Source = null;
                }
                else
                {
                    await this.ShowMessageAsync("Error", "Please check all fields", MessageDialogStyle.Affirmative);
                }
            }
            catch
            {
                await this.ShowMessageAsync("Error", "Task not completed", MessageDialogStyle.Affirmative);
            }
        }
コード例 #2
0
        private async void ButtonSubmit_Click(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show("this is submit button");
            String name = txtName.Text;

            //MessageBox.Show(name);

            try
            {
                bool isNameEmpty        = string.IsNullOrEmpty(txtName.Text);
                bool isPhoneEmpty       = string.IsNullOrEmpty(txtPhone.Text);
                bool isDescriptionEmpty = string.IsNullOrEmpty(txtDescription.Text);
                bool isFilePathEmpty    = string.IsNullOrEmpty(uploadFilePath);
                bool isFileIdEmpty      = string.IsNullOrEmpty(txtId.Text);

                if (!isNameEmpty && !isDescriptionEmpty && !isPhoneEmpty)
                {
                    string tableName = MyAWSConfigs.ReaderDBtableName;
                    Table  table     = Table.LoadTable(client, tableName);

                    ProgressDialogController controller = await this.ShowProgressAsync("Please wait...", "");

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


                    string partitionKey = txtId.Text;
                    Console.WriteLine("oooooooooooooooooooooooooooooooo" + partitionKey);

                    var item = new Document();

                    Document doc = new Document();
                    doc["id"]          = partitionKey;
                    doc["name"]        = txtName.Text;
                    doc["phone"]       = txtPhone.Text;
                    doc["description"] = txtDescription.Text;
                    ///////////////////////////////////////////////////       //#ToDo : Add readerList
                    //item["readerList"] = readerList;

                    UpdateItemOperationConfig config = new UpdateItemOperationConfig
                    {
                        // Get updated item in response.
                        ReturnValues = ReturnValues.AllNewAttributes
                    };

                    if (uploadFilePath != null)
                    {
                        string[] temp = uploadFilePath.Split('.');
                        string   BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory;
                        string   filePath          = BaseDirectoryPath + $"Resources\\Images\\{partitionKey}";
                        item = table.GetItem(partitionKey);
                        string oldImage = item["aPropic"];
                        Console.WriteLine("><><><><><><><><><><>" + oldImage);

                        //Delete old profile pic in local
                        string oldFilePath = BaseDirectoryPath + $"Resources\\Images\\{oldImage}";
                        DeleteOldPic(oldFilePath);

                        //Delete old profile pic in s3Bucket
                        controller.SetMessage("Deleting File");
                        await Task.Run(() => S3Bucket.DeleteFile(oldImage, MyAWSConfigs.RefImagesBucketName));


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

                    controller.SetMessage("Adding database record");
                    await Task.Run(() => table.UpdateItem(doc, config));

                    Console.WriteLine("UpdateMultipleAttributes: Printing item after updates ...");
                    //MessageBox.Show("Successfully Updated!");

                    await controller.CloseAsync();

                    await this.ShowMessageAsync("Success", "Person Updated !", MessageDialogStyle.Affirmative);
                }
                else
                {
                    await this.ShowMessageAsync("Error", "Please check all fields", MessageDialogStyle.Affirmative);
                }
            }
            catch
            {
                await this.ShowMessageAsync("Error", "Task not completed", MessageDialogStyle.Affirmative);
            }
        }
コード例 #3
0
        private async void BtnChangePropic_Click(object sender, RoutedEventArgs e)
        {
            //ChangeAdminPropic changeAdminPassword = new ChangeAdminPropic(myId);
            //changeAdminPassword.ShowDialog();

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter      = "Image files | *.jpg; *.jpeg; *.png";
            openFileDialog.FilterIndex = 1;
            openFileDialog.Multiselect = false;

            //open file dialog
            if (openFileDialog.ShowDialog() == true)
            {
                uploadFilePath = openFileDialog.FileName;
                AdminDp.Source = null;
            }

            try
            {
                bool isFilePathEmpty = string.IsNullOrEmpty(uploadFilePath);

                if (!isFilePathEmpty)
                {
                    tableName = MyAWSConfigs.AdminDBTableName;

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

                    string BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory;

                    //get current dp name
                    item = Dynamodb.GetItem(myId, tableName);
                    string oldImage = item["aPropic"];
                    Console.WriteLine("><><><><><><><><><><>" + oldImage);

                    //Delete old profile pic in local
                    string oldFilePath = BaseDirectoryPath + $"Resources\\Images\\{oldImage}";
                    DeleteOldPic(oldFilePath);

                    //Delete old profile pic in s3Bucket
                    S3Bucket.DeleteFile(oldImage, MyAWSConfigs.AdminS3BucketName);

                    item["aPropic"] = fileId;

                    //activity recorded
                    Models.ActivityLogs.Activity(Models.Components.AdminComponent, "User Changed Profile Picture");

                    await Task.Run(() => S3Bucket.UploadFile(uploadFilePath, fileId, MyAWSConfigs.AdminS3BucketName));

                    MessageBox.Show("Success", "Successfully Updated!");
                }
                else
                {
                    MessageBox.Show("Error", "Please check all fields");
                }
            }
            catch
            {
                MessageBox.Show("Error", "Task not completed");
            }
        }