public Order CreateOrderID(string userName) { Order order = new Order { UserName = userName }; myBooks.Orders.Add(order); myBooks.SaveChanges(); return(order); }
protected void btnConfirm_Click(object sender, EventArgs e) { // Only proceed to save in database if book cover image is valid if (IsValidFile()) { b = new Book(); b.Title = txtBookTitle.Text; b.CategoryID = Convert.ToInt32(ddCategory.SelectedValue); b.ISBN = txtISBN.Text; b.Author = txtAuthor.Text; b.Stock = Convert.ToInt32(txtStock.Text); b.Price = Convert.ToInt32(txtPrice.Text); FileUploadImage.SaveAs(Server.MapPath("~/images/" + b.ISBN + System.IO.Path.GetExtension(FileUploadImage.FileName).ToLower())); try { context.Books.Add(b); context.SaveChanges(); Response.Write("<script>confirm('Success!'); window.location = 'OwnerAddBook.aspx';</script>"); } catch (Exception a) { Response.Write("<script> if(confirm('Book add was unsuccessful...Would you like to add new book?'))" + "{window.location = 'OwnerAddBook.aspx';} else {window.location = 'BookSearch.aspx';} </script>"); } } }
public static void DeleteBooks(string title) { using (MyBooks entities = new MyBooks()) { Book book = entities.Books.Where(z => z.Title == title).First <Book>(); entities.Books.Remove(book); entities.SaveChanges(); } }
public static void EditInventory(int bookID, string title, int categoryID, string isbn, string author, int stock, decimal price) { using (MyBooks entities = new MyBooks()) { Book book = entities.Books.Where(x => x.BookID == bookID).First <Book>(); book.Title = title; book.CategoryID = categoryID; book.ISBN = isbn; book.Author = author; book.Stock = stock; book.Price = price; entities.SaveChanges(); } }