//insert authors in database protected void AddAuthor(object sender, EventArgs e) { Create_Connection(); SqlCommand cmd = new SqlCommand("InsertAuthors", conn); cmd.CommandType = CommandType.StoredProcedure; if (string.IsNullOrWhiteSpace(Name.Text) || Surname.Text == String.Empty || Nationality.Text == String.Empty || Birthdate.Text == String.Empty) { Response.Redirect("Booklibrary"); } else { cmd.Parameters.AddWithValue("@AuthorName", Name.Text); cmd.Parameters.AddWithValue("@AuthorLastname", Surname.Text); cmd.Parameters.AddWithValue("@AuthorNationality", Nationality.Text); cmd.Parameters.AddWithValue("@Birthdate", Convert.ToDateTime(Birthdate.Text)); cmd.Parameters.AddWithValue("@Email", Email.Text); cmd.Parameters.AddWithValue("@DateInserted", DateTime.Now); cmd.Parameters.AddWithValue("@AllowAuthor", true); cmd.ExecuteNonQuery(); conn.Close(); Author_GridView.DataBind(); Response.Redirect("Booklibrary"); } }
//insert books in database public void AddBook(object sender, EventArgs e) { Create_Connection(); SqlCommand cmd = new SqlCommand("InsertBook", conn); cmd.CommandType = CommandType.StoredProcedure; if (BookName.Text == string.Empty || BookDescribtion.Text == string.Empty || AuthorNamesDropdown.SelectedValue == null || GenresDropdown.SelectedValue == null) { Response.Redirect("Booklibrary"); } else { cmd.Parameters.AddWithValue("@BookName", BookName.Text); cmd.Parameters.AddWithValue("@BookDescribtion", BookDescribtion.Text); cmd.Parameters.AddWithValue("@ReleaseDate", Convert.ToInt32(BookReleaseDate.Text)); cmd.Parameters.AddWithValue("@AuthorID", AuthorNamesDropdown.SelectedValue); cmd.Parameters.AddWithValue("@GenreID", GenresDropdown.SelectedValue); cmd.ExecuteNonQuery(); conn.Close(); Author_GridView.DataBind(); Response.Redirect("Booklibrary"); } }