public IActionResult ViewDetail(int id) { BookTable book = _bookrepo.GetBookTableById(id); ; return(View("Details", book)); }
public ActionResult Rent(int?id) { if (Session["UserID"] != null) { BookTable book = db.BookTables.Find(id); if (book.BookStatus == false) { RentViewModel viewModel = new RentViewModel(); viewModel.UserID1 = Convert.ToInt32(Session["UserID"]); BookDetailTable bookDetail = db.BookDetailTables.Find(id); viewModel.BookDetailTable = bookDetail; viewModel.BookTable = book; viewModel.RentDate1 = DateTime.Now; viewModel.DueDate1 = DateTime.Now.AddDays(7); viewModel.BookID1 = book.BookID; viewModel.Deposit1 = 100000 + 3000 * 7; viewModel.Cost1 = 3000; return(View(viewModel)); } else { return(RedirectToAction("Index", "Home")); } } else { return(RedirectToAction("Index", "Home")); } }
public async Task Book_Your_Table_POST_false() { //Arrange BookTable bookYourTable = new BookTable() { BookingDate = DateTime.Now, CustomerId = 1, RestaurantId = 1, capacityCount = 2, Id = 1 }; //Act var mockOrder = new Mock <IBookYourTableBusiness>(); mockOrder.Setup(x => x.BookYourTable(bookYourTable)).Returns(false); var tableBookingController = new TableBookingController(mockOrder.Object); tableBookingController.ControllerContext = new ControllerContext(); tableBookingController.ControllerContext.HttpContext = new DefaultHttpContext(); tableBookingController.ControllerContext.HttpContext.Request.Headers["CustomerId"] = "1"; var data = await tableBookingController.Put(bookYourTable); //Assert var okObjectResult = data as OkObjectResult; Assert.AreEqual(200, okObjectResult.StatusCode); }
public ActionResult Create(BookViewModel viewModel) { if (ModelState.IsValid) { BookTable book = new BookTable(); book.ISBN = viewModel.ISBN1; book.BookStatus = false; BookDetailTable bookDetail = new BookDetailTable(); bookDetail.ISBN = viewModel.ISBN1; bookDetail.Title = viewModel.Title1; bookDetail.Summary = viewModel.Summary1; if (viewModel.AuthorID1 == Convert.ToInt32(db.AuthorTables.Find(viewModel.AuthorID1).AuthorID)) { bookDetail.AuthorID = viewModel.AuthorID1; } if (viewModel.PublisherID1 == Convert.ToInt32(db.PublisherTables.Find(viewModel.PublisherID1).PublisherID)) { bookDetail.PublisherID = viewModel.PublisherID1; } db.BookTables.Add(book); db.BookDetailTables.Add(bookDetail); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("About", "Home")); } }
static void Update() { //Console.WriteLine("Nothing"); Console.WriteLine("What book do you want to update: "); string oldName = Console.ReadLine(); using (var db = new BookAppDBEntities()) { var book = db.BookTables .Where(x => x.Name == oldName).FirstOrDefault(); db.BookTables.Remove(book); db.SaveChanges(); Console.WriteLine("Enter the new name: "); string newName = Console.ReadLine(); if (book != null) { var newBook = new BookTable() { // var input = Console.ReadLine(); Id = Guid.NewGuid(), Name = newName }; db.BookTables.Add(newBook); db.SaveChanges(); Console.WriteLine($"{newName} was being updated."); } // Console.WriteLine($"{newName} was being updated."); } }
void DeleteBookByID() { if (CheckIfBookExists()) { try { SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("DELETE from dbo.book_master_tbl WHERE book_id='" + TextBox_BookId.Text.Trim() + "'", con); cmd.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert('Book Deleted Successfully');</script>"); BookTable.DataBind(); } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } } else { Response.Write("<script>alert('Invalid Member ID');</script>"); } }
// GET: BookTables/Loan/5 public ActionResult Loan(int?id, string Name) { //get member's names for drop down list var MemberList = new List <string>(); var MemberQuery = from item in db.MemberTable select item; //populate view model to allow data from different tables to be used in same view var model = new MemberBookVM { MemberTable = MemberQuery.Select(a => new SelectListItem { Text = a.Name, Value = a.Name }) }; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BookTable bookTable = db.BookTable.Find(id); if (bookTable == null) { return(HttpNotFound()); } return(View(model)); }
static void Main(string[] args) { //Console.WriteLine("Enter a book name: "); using (var db = new BookAppDBEntities()) { var b1 = new BookTable() { Id = Guid.NewGuid(), Name = "Cplusplus" }; var b2 = new BookTable() { Id = Guid.NewGuid(), Name = "C Objective" }; var b3 = new BookTable() { Id = Guid.NewGuid(), Name = "F sharp" }; Guid id = Guid.Parse("00000000-0000-0000-0000-000000000000"); //var bk = db.BookTables.Where(x => x.Id == id).FirstOrDefault(); //bk.Name = "C sharp"; db.BookTables.Add(b1); db.BookTables.Add(b2); db.BookTables.Add(b3); db.SaveChanges(); } }
static void Find() { Console.WriteLine("Enter the name of the book to find in DB: "); string input = Console.ReadLine(); using (var db = new BookAppDBEntities()) { var newBook = new BookTable() { // var input = Console.ReadLine(); Id = Guid.NewGuid(), Name = input }; // var b = db.BookTables.Where(x => x.Name == input).FirstOrDefault(); //var b = db.BookTables // .Select(x => x.Name == input).FirstOrDefault(); //Console.WriteLine($"{b}"); // db.SaveChanges(); var book = db.BookTables.SingleOrDefault(p => p.Name == input); //Console.WriteLine("{0} was found.", book.Name); Console.WriteLine("{0} was found."); } }
public ActionResult ListBook() { try { BookTable bookTable = new BookTable(db); IEnumerable <Book> booksModel = bookTable.GetBooks(); string searchValue = Request.Form[ProjectConstants.SearchValue]; //IF it is a clear action, empty the search textbox if (Request.Form[ProjectConstants.Action] != null && Request.Form[ProjectConstants.Action] == ProjectConstants.Clear) { searchValue = null; } //Check for filter if (searchValue != null) { ViewBag.SearchValue = searchValue; booksModel = booksModel.Where(book => book.Name.Contains(searchValue)); } return(View(booksModel)); } catch (Exception) { throw; } }
public ActionResult Addbook(BookTable book) { var context = new LibraryDBEntities(); context.BookTables.Add(book); context.SaveChanges(); return(RedirectToAction("BookList")); }
public ActionResult DeleteConfirmed(int id) { BookTable bookTable = db.BookTable.Find(id); db.BookTable.Remove(bookTable); db.SaveChanges(); return(RedirectToAction("Index")); }
public static BookTable GetBookTable() { if (bookTable == null) { bookTable = new BookTable(); } return(bookTable); }
public ActionResult Edit(string id) { // Get the Specific Book by Id BookTable bookTable = new BookTable(db); Book editBook = bookTable.GetBookById(id); return(View(editBook)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { FillAuthorPublisherValues(); } BookTable.DataBind(); }
public ActionResult DeleteBook(string id) { // Get the Specific Book by Id BookTable bookTable = new BookTable(db); var deleteCount = bookTable.DeleteById(id); return(RedirectToActionPermanent(ProjectConstants.ListBook)); }
public ActionResult EditBook(Book book) { // Get the Specific Book by Id BookTable bookTable = new BookTable(db); bookTable.Update(book); return(RedirectToActionPermanent(ProjectConstants.ListBook)); }
public void GetBookbyId_Null() { Mock <IDatabase> mock = new Mock <IDatabase>(); BookTable booktable = new BookTable(mock.Object); List <Dictionary <string, string> > result = new List <Dictionary <string, string> >(); mock.Setup(x => x.Query(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(result); Assert.AreEqual(null, booktable.GetBookById("1")); }
public BookTable DetailsUpdate(BookTable Book, BookTable BookObj) { Book.ISBN = BookObj.ISBN; Book.Publisher = BookObj.Publisher; Book.Author = BookObj.Author; Book.Title = BookObj.Title; Book.Year = BookObj.Year; return(Book); }
public void DeletebyId() { Mock <IDatabase> mock = new Mock <IDatabase>(); mock.Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(1); BookTable booktable = new BookTable(mock.Object); int result = booktable.DeleteById("25"); Assert.AreEqual(1, result); }
public static void Update(this BookTable table, Book book) { table.Author = book.Author; table.Title = book.Title; table.Status = book.Status; if (book.Cover != null) { table.Cover = book.Cover; } }
public static Book ToBook(this BookTable table) { return(new Book() { Id = table.Id, Author = table.Author, Cover = table.Cover, Title = table.Title, Status = table.Status }); }
public ActionResult Edit([Bind(Include = "BookID,Title,Author,Genre,OnLoan,MemberID,Image")] BookTable bookTable) { if (ModelState.IsValid) { db.Entry(bookTable).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MemberID = new SelectList(db.MemberTable, "MemberID", "Name", bookTable.MemberID); return(View(bookTable)); }
protected void txtKeyword_TextChanged(object sender, EventArgs e) { txtID.Text = ""; string sql = "select * from bookstat_full where title like @keyword or category like @keyword or isbn like @keyword or author like @keyword or publisher like @keyword"; BookTable.DataSource = SqlHelper.ExecuteDataTable(sql, new SqlParameter[] { new SqlParameter("keyword", "%" + txtKeyword.Text + "%") }); BookTable.DataBind(); btnAll.Checked = false; }
private void BindUserInfo() { string sql = "select * from bookstat_full"; BookTable.DataSource = SqlHelper.ExecuteDataTable(sql); BookTable.DataBind(); btnAll.Checked = false; txtID.Text = ""; txtKeyword.Text = ""; Label1.Text = BookStatBLL.GetBookOnSaleCount().ToString(); }
public ActionResult Remove(int id) { BookTable book = db.BookTables.Find(id); BookDetailTable bookDetail = db.BookDetailTables.Find(id); db.BookTables.Remove(book); db.BookDetailTables.Remove(bookDetail); db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult BookTable(BookTable model) { var kq1 = new BookTableDAO().Insert(model); var kq2 = new TableDAO().Update(model); if (kq1 & kq2) { return(Redirect("/trang-chu")); } return(PartialView(model)); }
public void GetBookbyId_ExpectedException() { Mock <IDatabase> mock = new Mock <IDatabase>(); BookTable booktable = new BookTable(mock.Object); Dictionary <string, string> parameter = new Dictionary <string, string>(); List <Dictionary <string, string> > result = new List <Dictionary <string, string> >(); parameter.Add("new", "test"); result.Add(parameter); mock.Setup(x => x.Query(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(result); Assert.IsInstanceOfType(booktable.GetBookById("1"), typeof(Book)); }
public BookTable GetBookTableById(int id) { BookTable book = new BookTable(); using (IDbConnection conn = Connection) { string sQuery = "SELECT * from bookTable where id = @id"; conn.Open(); book = conn.QueryFirstOrDefault <BookTable>(sQuery, new{ id = id }); return(book); } }
private void refreshBTN_Click(object sender, EventArgs e) { BindingSource bSource = new BindingSource(); bSource.DataSource = BookTable; BookTable.DataSource = bSource; BookTable.Update(); BookTable.Refresh(); }