Esempio n. 1
0
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int bookId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]);
        var id     = ctx.Books.Where(x => x.BookID == bookId).FirstOrDefault();

        ctx.Books.Remove(id);
        ctx.SaveChanges();
        BindGrid();
    }
Esempio n. 2
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        int id         = Convert.ToInt32(tbxBookID.Text);
        var updateBook = ctx.Books.SingleOrDefault(x => x.BookID == id);

        if (updateBook != null)
        {
            updateBook.BookID     = int.Parse(tbxBookID.Text);
            updateBook.CategoryID = int.Parse(ddlBookCategory.SelectedValue);
            updateBook.ISBN       = tbxISBN.Text;
            updateBook.Price      = Convert.ToDecimal(tbxPrice.Text);
            updateBook.Stock      = int.Parse(tbxStock.Text);
            updateBook.Title      = tbxBookTitle.Text;
            updateBook.Author     = tbxAuthor.Text;
        }
        ctx.Books.AddOrUpdate(updateBook);
        ctx.SaveChanges();
        Response.Redirect("BookSummaries.aspx");
    }