private void ListViewMenu_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ListViewMenu.SelectedIndex == 0)
            {
            }

            if (ListViewMenu.SelectedIndex == 2)
            {
                BooksUC booksUC = new BooksUC(this, userId);

                UCgrid.Children.Clear();
                UCgrid.Children.Add(booksUC);
            }

            if (ListViewMenu.SelectedIndex == 1)
            {
                UsersUC usersUC = new UsersUC(this, userId);

                UCgrid.Children.Clear();
                UCgrid.Children.Add(usersUC);
            }


            if (ListViewMenu.SelectedIndex == 3)
            {
                this.Close();
            }
        }
        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            UsersUC usersUC = new UsersUC(ad, adminId);

            ad.UCgrid.Children.Clear();
            ad.UCgrid.Children.Add(usersUC);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            UsersUC usersUC = new UsersUC(this, userId);

            UCgrid.Children.Clear();
            UCgrid.Children.Add(usersUC);
        }
        private void SubmitBtn_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new LibraryDBEntities())
            {
                try
                {
                    int roleId;
                    if (Login.Text != "" && Password.Text != "" && LName.Text != "" && FName.Text != "" &&
                        Email.Text != "")
                    {
                        if (RolesList.SelectedItem == null)
                        {
                            roleId = 2;
                        }

                        else
                        {
                            roleId = RolesList.SelectedIndex + 1;
                        }
                        var loginTest = db.Users.FirstOrDefault(l => l.Login == Login.Text);
                        if (loginTest == null)
                        {
                            var newUser = new User
                            {
                                Login    = Login.Text,
                                Password = Password.Text,
                                LName    = LName.Text,
                                FName    = FName.Text,
                                Email    = Email.Text,
                                RoleID   = roleId
                            };
                            db.Users.Add(newUser);
                            db.SaveChanges();

                            UsersUC usersUC = new UsersUC(ad, adminId);

                            ad.UCgrid.Children.Clear();
                            ad.UCgrid.Children.Add(usersUC);
                        }
                        else
                        {
                            MessageBox.Show("A user with the same Login already exists!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Fill in all fields!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void SubmitBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (LibraryDBEntities db = new LibraryDBEntities())
                {
                    var editedDUser = db.Users.Find(userId);
                    if (Login.Text != "" && Password.Text != "" && LName.Text != "" && FName.Text != "" &&
                        Email.Text != "")
                    {
                        editedDUser.LName    = LName.Text;
                        editedDUser.FName    = FName.Text;
                        editedDUser.Email    = Email.Text;
                        editedDUser.Login    = Login.Text;
                        editedDUser.Password = Password.Text;
                        if (editedDUser.Id == 1)
                        {
                            editedDUser.RoleID = editedDUser.RoleID;
                            MessageBox.Show("You cannot change your role! Leave it as Admin!");
                        }

                        else
                        {
                            if (RolesList.SelectedItem == null)
                            {
                                editedDUser.RoleID = editedDUser.RoleID;
                            }
                            else
                            {
                                editedDUser.RoleID = RolesList.SelectedIndex + 1;
                            }
                        }


                        db.SaveChanges();

                        UsersUC usersUC = new UsersUC(ad, adminId);

                        ad.UCgrid.Children.Clear();
                        ad.UCgrid.Children.Add(usersUC);
                    }
                    else
                    {
                        MessageBox.Show("Do not leave any field empty!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void ListViewItem_Selected(object sender, RoutedEventArgs e)
        {
            //int firstIndex = ListViewMenu.SelectedIndex;


            if (ListViewMenu.SelectedIndex == 0)
            {
                UsersUC usersUC = new UsersUC(this, userId);

                UCgrid.Children.Clear();
                UCgrid.Children.Add(usersUC);
            }
        }
        private void DeleteBtn_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new LibraryDBEntities())
            {
                try
                {
                    if (db.Users.Any())
                    {
                        dynamic selectedItem = Users.SelectedItems[0];
                        if (selectedItem != null)
                        {
                            int id           = (int)selectedItem.Id;
                            var userToDelete = db.Users.Find(id);
                            if (id != adminId)
                            {
                                if (userToDelete.Id != 1)
                                {
                                    db.Users.Remove(userToDelete);

                                    db.SaveChanges();
                                    MessageBox.Show("User info about " + userToDelete.FName + " " + userToDelete.LName + " was deleted");
                                    UsersUC usersUC = new UsersUC(ad, adminId);

                                    ad.UCgrid.Children.Clear();
                                    ad.UCgrid.Children.Add(usersUC);
                                }
                                else
                                {
                                    MessageBox.Show("You cannot destroy your Creator!!!!!");
                                }
                            }
                            else
                            {
                                MessageBox.Show("You cannot delete yourself!");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("No users existed!");
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Select a user!");
                }
            }
        }