Esempio n. 1
0
        private void TakeBack_Click(object sender, RoutedEventArgs e)
        {
            string bookName = BookName.Text.ToString();

            using (LibraryDbEntities books = new LibraryDbEntities())
            {
                Table book = books.Tables.FirstOrDefault(x => x.BookName == bookName);

                TakeBack.Content = "Return the book to the library";
                book.GivenTo     = "";
                books.SaveChanges();
                Result.Text = $"Place in Library: {book.PlaceInLibrary}";
            }
        }
Esempio n. 2
0
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            string bookName = BookName.Text.ToString();

            using (LibraryDbEntities books = new LibraryDbEntities())
            {
                Table book = books.Tables.FirstOrDefault(x => x.BookName == bookName);

                string giveTo = GiveTo.Text.ToString();

                book.GivenTo = giveTo;

                books.SaveChanges();
                GiveTo.Text = string.Empty;
                Result.Text = $"Place in Library: {book.PlaceInLibrary}"
                              + Environment.NewLine +
                              $"Given to: {book.GivenTo}";
                GiveButton.Content = string.Empty;
            }
        }
Esempio n. 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string authorName = string.Empty;
            string givenTo    = string.Empty;
            var    bookName   = nameBox.Text.ToString();

            if (nameBox.ToString() != null)
            {
                authorName = authorBox.Text.ToString();
            }
            var placeInLibrary = placeBox.Text.ToString();

            if (givenBox.ToString() != null)
            {
                givenTo = givenBox.Text.ToString();
            }

            using (LibraryDbEntities books = new LibraryDbEntities())
            {
                if (bookName == "" || placeInLibrary == "")
                {
                    MessageBox.Show("You have to type the name of the book and it's place in the library", "Error", MessageBoxButton.OK);
                    InitializeComponent();
                }


                else
                {
                    if (bookName.Length > 150)
                    {
                        MessageBox.Show("The name of the book can not be more than 150 characters", "Error", MessageBoxButton.OK);
                        InitializeComponent();
                    }
                    else if (authorName.Length > 100)
                    {
                        MessageBox.Show("The name of the author can not be more than 100 characters", "Error", MessageBoxButton.OK);
                        InitializeComponent();
                    }
                    else if (placeInLibrary.Length > 100)
                    {
                        MessageBox.Show("The place in the library can not be more than 100 characters", "Error", MessageBoxButton.OK);
                        InitializeComponent();
                    }
                    else if (givenTo.Length > 100)
                    {
                        MessageBox.Show("The name of the person that the books is given to can not be more than 100 characters", "Error", MessageBoxButton.OK);
                        InitializeComponent();
                    }
                    else
                    {
                        Table book = new Table()
                        {
                            AuthorName     = authorName,
                            BookName       = bookName,
                            PlaceInLibrary = placeInLibrary,
                            GivenTo        = givenTo,
                        };
                        books.Tables.Add(book);

                        books.SaveChanges();
                    }
                }
            }
            nameBox.Text   = string.Empty;
            authorBox.Text = string.Empty;
            placeBox.Text  = string.Empty;
            givenBox.Text  = string.Empty;
        }