Exemple #1
0
 protected void CreateBook_Click(object sender, EventArgs e)
 {
     BookCreate.DataSource = new List <Book> {
         new Book {
             Title = string.Empty
         }
     };
     BookCreate.DataBind();
 }
Exemple #2
0
        protected void SaveCreate_Click(object sender, EventArgs e)
        {
            var title       = (BookCreate.FindControl("BookTitle") as TextBox).Text;
            var authors     = (BookCreate.FindControl("BookAuthors") as TextBox).Text;
            var ISBN        = (BookCreate.FindControl("BookIsbn") as TextBox).Text;
            var site        = (BookCreate.FindControl("BookSite") as TextBox).Text;
            var description = (BookCreate.FindControl("BookDescription") as TextBox).Text;
            var categoryId  = int.Parse((BookCreate.FindControl("BookCategory") as DropDownList).SelectedValue);

            if (string.IsNullOrEmpty(title))
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Title cannot be empty");
                return;
            }
            else if (title.Length < 5 || title.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Title must be between 5 and 50 symbols");
                return;
            }
            else if (string.IsNullOrEmpty(authors))
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Authors cannot be empty");
                return;
            }
            else if (authors.Length < 5 || authors.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Authors must be between 5 and 50 symbols");
                return;
            }
            else if (ISBN.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("ISBN must be less than 50 symbols");
                return;
            }
            else if (site.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("ISBN must be less than 50 symbols");
                return;
            }
            else if (description.Length > 2000)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Description must be less than 2000 symbols");
                return;
            }
            else if (categoryId == -1)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Authors cannot be empty");
                return;
            }

            LibrarySystemDbContext context = new LibrarySystemDbContext();

            context.Books.Add(new Book
            {
                Title       = title,
                Authors     = authors,
                ISBN        = ISBN,
                WebSite     = site,
                Description = description,
                CategoryId  = categoryId
            });

            context.SaveChanges();

            BookCreate.DataSource = null;
            BookCreate.DataBind();
            BooksGrid.DataBind();
        }
Exemple #3
0
 protected void CancelCreate_Click(object sender, EventArgs e)
 {
     BookCreate.DataSource = null;
     BookCreate.DataBind();
 }