Example #1
0
        private void UpdateButton_Click(object sender, RoutedEventArgs e)
        {
            if (ValidateBook())
            {
                //Cannot allow editing while saving
                SetFocusable(false);

                //Update the book
                _book.Author = AuthorTextBox.Text;
                _book.Title  = TitleTextBox.Text;
                _book.Code   = CodeTextBox.Text;
                _book.Year   = Convert.ToUInt16(YearPicker.SelectedDate.Value.Year);

                //Send the person to save it into the database.
                LibraryDataProvider.UpdateData <Book>(LibraryDataProvider.bookUrl, _book, _book.Id);

                //Update the archivated borrowing data if needed
                bool allowed = true;
                //Only allow if set
                if (allowed)
                {
                    //Get all occurance
                    var occurances = ArchiveDataProvider.GetManyBySingleId(true, _book.Id);
                    foreach (var occurance in occurances)
                    {
                        //Update
                        occurance.Author = AuthorTextBox.Text;
                        occurance.Title  = TitleTextBox.Text;
                        occurance.Code   = CodeTextBox.Text;
                        //Save
                        LibraryDataProvider.UpdateData <ArchiveData>(LibraryDataProvider.archiveUrl, occurance, occurance.Id);
                    }
                }

                //Close the dialog window.
                DialogResult = true;
                Close();
            }
        }
        private void UpdateButton_Click(object sender, RoutedEventArgs e)
        {
            if (ValidatePerson())
            {
                //Cannot allow editing while saving
                SetFocusable(false);

                //Update the person.
                _person.FirstName   = FirstNameTextBox.Text;
                _person.LastName    = LastNameTextBox.Text;
                _person.DateOfBirth = DateOfBirthDatePicker.SelectedDate.Value;

                //Update the person in the database.
                LibraryDataProvider.UpdateData <Person>(LibraryDataProvider.personUrl, _person, _person.Id);

                //Update the archivated borrowing data if needed
                bool allowed = true;
                //Only allow if set
                if (allowed)
                {
                    //Get all occurance
                    var occurances = ArchiveDataProvider.GetManyBySingleId(false, _person.Id);
                    foreach (var occurance in occurances)
                    {
                        //Update
                        occurance.FirstName   = FirstNameTextBox.Text;
                        occurance.LastName    = LastNameTextBox.Text;
                        occurance.DateOfBirth = DateOfBirthDatePicker.SelectedDate.Value;
                        //Save
                        LibraryDataProvider.UpdateData <ArchiveData>(LibraryDataProvider.archiveUrl, occurance, occurance.Id);
                    }
                }

                //Close the dialog window.
                DialogResult = true;
                Close();
            }
        }
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            //Ask for permission.
            var result = MessageBox.Show("Biztos, hogy törölni akarja a felhasználót?",
                                         "Megerősítés",
                                         MessageBoxButtons.YesNo,
                                         MessageBoxIcon.Question);

            //Delete after validation.
            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                //Cannot allow editing while deleting
                SetFocusable(false);

                //Update the archivated borrowing data if needed
                bool allowed = true;
                //Only allow if set
                if (allowed)
                {
                    //Get all occurance
                    var occurances = ArchiveDataProvider.GetManyBySingleId(false, _person.Id);
                    foreach (var occurance in occurances)
                    {
                        //Update
                        occurance.BorrowerId = null;
                        //Save
                        LibraryDataProvider.UpdateData <ArchiveData>(LibraryDataProvider.archiveUrl, occurance, occurance.Id);
                    }
                }

                //Delete from the database
                LibraryDataProvider.DeleteData <Person>(LibraryDataProvider.personUrl, _person.Id);

                //Close the bialog window
                DialogResult = true;
                Close();
            }
        }