Exemplo n.º 1
0
        private async Task LoadData(string id)
        {
            progressBar.Visibility = Visibility.Visible;
            try
            {
                IEnumerable <RefPerson> temp = await Task.Run(() => RefPerson.GetAllRefPersons());

                List <RefPerson> refs          = new List <RefPerson>(temp);
                List <String>    selectedrefs  = new List <String>();
                List <String>    tickedreaders = new List <String>();

                //selectedrefs =

                var item = Dynamodb.GetItem(id, MyAWSConfigs.ReaderDBtableName);
                Console.WriteLine("dsdddddddddddddddddddddddd" + item["description"]);
                selectedrefs = item["refList"].AsListOfString();

                foreach (var r in refs)
                {
                    r.isCheckedRef = false;
                }



                //Console.WriteLine();

                for (int i = 0; i < selectedrefs.Count; i++)
                {
                    foreach (var j in refs)
                    {
                        if (j.id == selectedrefs[i])
                        {
                            tickedreaders.Add(j.id);
                            j.isCheckedRef = true;
                        }
                    }
                }



                foreach (var j in refs)
                {
                    //tickedreaders.Add(j.id);
                    Console.WriteLine("\n" + j.isCheckedRef);
                }

                RefDataGrid.ItemsSource = refs;
                RefDataGrid.Items.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                progressBar.Visibility = Visibility.Hidden;
            }
        }
Exemplo n.º 2
0
        public async Task ShowProfileData(string myid)
        {
            progressBar.Visibility = Visibility.Visible;
            try
            {
                //Console.WriteLine("name   vvvvv- - - ", myid);
                ////Console.WriteLine(aPassword);

                try
                {
                    tableName = MyAWSConfigs.AdminDBTableName;
                    item      = Dynamodb.GetItem(myid, tableName);

                    //Console.WriteLine(item["aPassword"]);

                    //check item is there
                    if (item != null)
                    {
                        //Console.WriteLine("name   - - - ", item["aName"]);
                        AdminName.Text  = item["aName"];
                        AdminPhone.Text = item["aPhone"];
                        AdminEMail.Text = item["aId"];

                        //set pro pic to image
                        string imagename = item["aPropic"];
                        await Task.Run(() => Models.S3Bucket.DownloadFile(imagename, MyAWSConfigs.AdminS3BucketName));

                        var    BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory;
                        string filePath          = BaseDirectoryPath + $"Resources/Images/{imagename}";
                        AdminDp.Source = new BitmapImage(new Uri(filePath));

                        AdminType.Text = "Non-Root Admin";

                        //check admin is root or not
                        if (item["root"].AsBoolean() == true)
                        {
                            AdminType.Text = "Root Admin - Only you can access other Admins data";
                        }
                    }
                    else
                    {
                        MessageBox.Show("Can not Load Data!!!");
                    }
                }
                catch (AmazonDynamoDBException ex)
                {
                    MessageBox.Show("Message : Server Error", ex.Message);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Message : Unknown Error", ex.Message);
                }
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        // only root admins can register admins, otherwise gives warnings
        private void RegAdmin_Click(object sender, RoutedEventArgs e)
        {
            string tableName = MyAWSConfigs.AdminDBTableName;

            var item = Dynamodb.GetItem(aId, tableName);

            if (item["root"].AsBoolean() == true)
            {
                RegisterAdmin acv = new RegisterAdmin();
                RegAdmin.IsEnabled = true;
                acv.ShowDialog();
            }
            else
            {
                MessageBox.Show("Only the rood admin can register the new users");
            }
        }
Exemplo n.º 5
0
 //show profile in the edit window
 private void ShowProfileData()
 {
     try
     {
         string tableName = MyAWSConfigs.AdminDBTableName;
         Item   item      = Dynamodb.GetItem(myId, tableName);
         Console.Write("my adminid<<<<<<<<<<<<<<<<<<", myId, ">>>>>>>>>>>>>>>>>>>");
         txtEmail.Text = myId;
         txtName.Text  = item["aName"];
         txtPhone.Text = item["aPhone"];
     }
     catch (AmazonDynamoDBException ex)
     {
         MessageBox.Show("Message : Server Error", ex.Message);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Message : Unknown Error", ex.Message);
     }
     finally
     {
         Mouse.OverrideCursor = null;
     }
 }
Exemplo n.º 6
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");
            }
        }
Exemplo n.º 7
0
        private void ButtonSubmit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string tableName = MyAWSConfigs.AdminDBTableName;
                Item   item      = Dynamodb.GetItem(myId, tableName);
                //Console.Write("my adminid<<<<<<<<<<<<<<<<<<", myId, ">>>>>>>>>>>>>>>>>>>");

                bool isFileIdEmpty   = string.IsNullOrEmpty(txtEmail.Text);
                bool isNameEmpty     = string.IsNullOrEmpty(txtName.Text);
                bool isPasswordEmpty = string.IsNullOrEmpty(txtPassword.Password);
                bool isPhoneEmpty    = string.IsNullOrEmpty(txtPhone.Text);

                // check wether the fields are empty
                if (!isNameEmpty && !isPhoneEmpty && !isFileIdEmpty && !txtEmail.Text.Contains(" ") && !isPasswordEmpty)
                {
                    // check the password is correct
                    if (Models.HashMD5.MD5Hash(txtPassword.Password) == item["aPassword"])
                    {
                        Console.WriteLine("\n*** Executing UpdateMultipleAttributes() ***");
                        Console.WriteLine("\nUpdating multiple attributes....");
                        string partitionKey = myId;

                        Document doc = new Document();
                        doc["aId"] = partitionKey;
                        // List of attribute updates.
                        // The following replaces the existing authors list.
                        doc["aName"]  = txtName.Text;
                        doc["aPhone"] = txtPhone.Text;

                        //update item
                        Dynamodb.UpdateItem(doc, tableName);
                        Console.WriteLine("UpdateMultipleAttributes: Printing item after updates ...");
                        MessageBox.Show("Successfully Updated!");

                        //activity recorded
                        Models.ActivityLogs.Activity(Models.Components.AdminComponent, "Admin Updated his Details");

                        this.Close();
                    }
                    else
                    {
                        //activity recorded
                        Models.ActivityLogs.Activity(Models.Components.AdminComponent, "Failed:Attempt: Wrong Pwd, update Details");

                        MessageBox.Show("Message : Wrong Password!");
                    }
                }
                else
                {
                    MessageBox.Show("Message : Please fill all all the fields!!!");
                }
            }
            catch (AmazonDynamoDBException ex)
            {
                MessageBox.Show("Message : Server Error", ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Message : Unknown Error", ex.Message);
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
Exemplo n.º 8
0
        private void ButtonSubmit_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                string tableName = MyAWSConfigs.AdminDBTableName;
                var    item      = Dynamodb.GetItem(myId, tableName);
                //Console.Write("my adminid<<<<<<<<<<<<<<<<<<", myId, ">>>>>>>>>>>>>>>>>>>");

                bool isPasswordEmpty    = string.IsNullOrEmpty(txtPassword.Password);
                bool isNewPasswordEmpty = string.IsNullOrEmpty(txtNewPassword.Password);
                bool isCPasswordEmpty   = string.IsNullOrEmpty(txtNewCPassword.Password);

                if (!isPasswordEmpty && !isNewPasswordEmpty && !isCPasswordEmpty)
                {
                    //check enetered and saved password hashes are same
                    if (HashMD5.MD5Hash(txtPassword.Password) == item["aPassword"])
                    {
                        Console.WriteLine("\n*** Executing UpdateMultipleAttributes() ***");
                        Console.WriteLine("\nUpdating multiple attributes....");
                        string partitionKey = myId;

                        Document doc = new Document();
                        doc["aId"] = partitionKey;
                        // List of attribute updates.
                        // The following replaces the existing authors list.
                        doc["aPassword"] = HashMD5.MD5Hash(txtNewPassword.Password);

                        // update password
                        Dynamodb.UpdateItem(doc, tableName);

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


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

                        this.Close();
                    }
                    else
                    {
                        //activity recorded
                        Models.ActivityLogs.Activity(Models.Components.AdminComponent, "Wrong Password for change Password");

                        MessageBox.Show("Message : Wrong Password!");
                    }
                }
                else
                {
                    MessageBox.Show("Message : Please fill all all the fields!!!");
                }
            }
            catch (AmazonDynamoDBException ex)
            {
                MessageBox.Show("Message : Server Error", ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Message : Unknown Error", ex.Message);
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }