Example #1
0
        private static void AddAutomaticCertificates()
        {
            // cycle through mandatory certificates to add
            foreach (byte[] bCertData in CertificateOperations.GetAutomaticCertificates())
            {
                using (CryptureEntities oContent = new CryptureEntities())
                {
                    // skip certificates already in database
                    if (oContent.Users.Where(u => u.Certificate == bCertData).Count() > 0)
                    {
                        continue;
                    }

                    // create new item to add
                    User oUser = new User()
                    {
                        Certificate = bCertData,
                        Sid         = null
                    };

                    oContent.Users.Add(oUser);
                    oContent.SaveChanges();
                }
            }
        }
Example #2
0
        private void oRemoveItemUser_Click(object sender, RoutedEventArgs e)
        {
            // get the selected object based on what button was pressed
            object oObject = (sender == oRemoveCertButton) ?
                             oCertDataGrid.SelectedItem : oItemDataGrid.SelectedItem;

            // prevent removal of automatic certificate
            if (oObject is User)
            {
                if (CertificateOperations.GetAutomaticCertificates().Where(u =>
                                                                           StructuralComparisons.StructuralEqualityComparer.Equals(u, ((User)oObject).Certificate)).Count() > 0)
                {
                    MessageBox.Show(this, "Removal of automatic certificate is prohibited.",
                                    "Removal Prohibited", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
            }

            // confirm removal
            if (oObject == null || MessageBox.Show(this,
                                                   "Are you sure you want to remove '" + ((oObject is User) ?
                                                                                          ((User)oObject).Name : ((Item)oObject).Label) + "'?",
                                                   "Removal Confirmation",
                                                   MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
            {
                return;
            }

            // remove select item or user
            using (CryptureEntities oContent = new CryptureEntities())
            {
                oContent.Entry(oObject).State = EntityState.Deleted;
                oContent.SaveChanges();
                oRefreshItemButton_Click();
            }
        }