// GET public IActionResult Index(int?authorId, int?borrowerId) { if (authorId == null && borrowerId == null) { //show All Books var books = new BookHandler().GetBookswithAuthor(); return(CheckBookCount(books)); } else if (authorId != null) { //filter by Author By Id var author = new AuthorHandler().GetAuthorwithBooksById((int)authorId); if (author.Books.Count == 0) { return(View("AuthorEmpty", author)); } else { return(View(author.Books)); } } else if (borrowerId != null) { var books = new BookHandler().GetBookwithAuthorandBorrowerById((int)borrowerId); return(CheckBookCount(books)); } else { throw new ArgumentException(); } return(View()); }
// GET public IActionResult Index() { List <Author> authors = new AuthorHandler().GetAlAuthorsWithBooks(); if (authors.Count == 0) { return(View("Empty")); } return(View(authors)); }
public IActionResult DeleteAuthor(int id) { var builder = new DbContextOptionsBuilder <LibraryContext>(); var db = new LibraryContext(builder.Options); var author = new AuthorHandler().GetAuthorById(id); using (db) { if (author != null) { db.Entry(author).State = EntityState.Deleted; db.SaveChanges(); } } return(RedirectToAction("Index")); }
public ActionResult Edit(int productId) { #region Prep Utilities AddNewBookViewModel model = new AddNewBookViewModel(); model.model_ID = new Guid("11111111-1111-1111-1111-111111111111").ToString(); #endregion myHandler = new BusinessLogicHandler(); Book book = myHandler.GetBook(productId); IEnumerable<BookAuthor> bookAuthorList = myHandler.GetBookAuthors(book.BookID); model.books = new Book(); model.books = book; #region Create SupplierHandler supHandler = new SupplierHandler(); /*TEMP LIST*/ //List<Supplier> nameList = new List<Supplier>(); IEnumerable<Supplier> nameList = (IEnumerable<Supplier>)supHandler.GetBookSupplierList(); var disp = from nameAndId in nameList select new { Value = nameAndId.SupplierID, Text = nameAndId.Name }; ViewBag.SupplierList = new SelectList(disp.ToList()); BookCategoryHandler typeHandler = new BookCategoryHandler(); IEnumerable<BookCategory> typeList = (IEnumerable<BookCategory>)typeHandler.GetBookCategoryList(); var dispBC = from name in typeList select new { Value = name.BookCategoryID, Text = name.CategoryName }; ViewBag.BookCategoryList = new SelectList(dispBC.ToList()); AuthorHandler authHandler = new AuthorHandler(); IEnumerable<Author> authList = (IEnumerable<Author>)authHandler.GetAuthorList(); var dispAuth = from nameAndSurname in authList select new { Value = nameAndSurname.AuthorID, Text = nameAndSurname.Name, nameAndSurname.Surname }; ViewBag.authList = new SelectList(dispAuth.ToList()); PublisherHandler publHandler = new PublisherHandler(); IEnumerable<Publisher> pubList = (IEnumerable<Publisher>)publHandler.GetPublisherList(); var dispPublisher = from pubName in pubList select new { Value = pubName.PublisherID, Text = pubName.Name }; ViewBag.pubList = new SelectList(dispPublisher.ToList()); #endregion Supplier sp = new Supplier(); Author ath = new Author(); BookCategory bkc = new BookCategory(); Publisher pb = new Publisher(); foreach (var item in nameList) { if (item.SupplierID == model.books.SupplierID) { sp.SupplierID = item.SupplierID; sp.Name = item.Name; } } int[] authors = new int[bookAuthorList.Count()]; int x = 0; foreach (var item in bookAuthorList) { if (item.BookID == model.books.BookID) { authors[x] = item.AuthorID; x++; } } foreach (var item in pubList) { if (item.PublisherID == model.books.PublisherID) { pb.PublisherID = item.PublisherID; pb.Name = item.Name; } } foreach (var item in typeList) { if (item.BookCategoryID == model.books.BookCategoryID) { bkc.BookCategoryID = item.BookCategoryID; bkc.CategoryName = item.CategoryName; } } #region Display List<SelectListItem> publisher = new List<SelectListItem>(); publisher.Add(new SelectListItem { Value = pb.PublisherID.ToString(), Text = pb.Name, Selected = true }); foreach (var item in pubList) { if (item.PublisherID != pb.PublisherID) publisher.Add(new SelectListItem { Text = item.Name, Value = item.PublisherID.ToString() }); } model.publishers = new List<SelectListItem>(); model.publishers = publisher; ViewData["publishers"] = publisher; List<SelectListItem> bookCategory = new List<SelectListItem>(); bookCategory.Add(new SelectListItem { Value = bkc.BookCategoryID.ToString(), Text = bkc.CategoryName, Selected = true }); foreach (var item in typeList) { if (item.BookCategoryID != bkc.BookCategoryID) bookCategory.Add(new SelectListItem { Text = item.CategoryName, Value = item.BookCategoryID.ToString() }); } model.bookCategories = new List<SelectListItem>(); model.bookCategories = bookCategory; ViewData["bookCategories"] = bookCategory; List<SelectListItem> supplier = new List<SelectListItem>(); supplier.Add(new SelectListItem { Value = sp.SupplierID.ToString(), Text = sp.Name, Selected = true }); foreach (var item in nameList) { if (item.SupplierID != sp.SupplierID) supplier.Add(new SelectListItem { Text = item.Name, Value = item.SupplierID.ToString() }); } model.suppliers = new List<SelectListItem>(); model.suppliers = supplier; ViewData["suppliers"] = supplier; List<SelectListItem> author = new List<SelectListItem>(); foreach (var item in authList) { if (authors.Contains(item.AuthorID)) { author.Add(new SelectListItem { Text = item.Name, Value = item.AuthorID.ToString(), Selected = true }); } else { author.Add(new SelectListItem { Text = item.Name, Value = item.AuthorID.ToString() }); } } model.authors = new List<SelectListItem>(); model.authors = author; ViewData["authors"] = author; #endregion return View(model); }
public ActionResult Create(FormCollection collection, HttpPostedFileBase file) { try { myHandler = new BusinessLogicHandler(); book = new Book(); book.BookTitle = collection.GetValue("books.BookTitle").AttemptedValue.ToString(); book.Synopsis = collection.GetValue("books.Synopsis").AttemptedValue.ToString(); book.ISBN = collection.GetValue("books.ISBN").AttemptedValue.ToString(); book.BookCategoryID = Convert.ToInt32(collection.GetValue("CategoryName").AttemptedValue); book.PublisherID = Convert.ToInt32(collection.GetValue("PublisherName").AttemptedValue); book.SupplierID = Convert.ToInt32(collection.GetValue("Name").AttemptedValue); //book.AuthorID = Convert.ToInt32(collection.GetValue("FullName").AttemptedValue); string[] Authors = (string[])collection.GetValue("FullName").RawValue; book.CostPrice = Convert.ToDouble(collection.GetValue("books.CostPrice").AttemptedValue); book.SellingPrice = Convert.ToDouble(collection.GetValue("books.SellingPrice").AttemptedValue); book.DateAdded = DateTime.Now; //TryUpdateModel(book); //CONSIDER REMOVING THIS..! if (ModelState.IsValid) { if (file != null) { file.SaveAs(HttpContext.Server.MapPath("~/Uploads/Books/") + file.FileName); book.CoverImage = file.FileName; } Book ba = new Book(); BookAuthor bookAuthors = new BookAuthor(); ba = myHandler.AddExperimentBook(book); ba.BookTitle = book.BookTitle; ba.Synopsis = book.Synopsis; ba.ISBN = book.ISBN; ba.BookCategoryID = book.BookCategoryID; ba.PublisherID = book.PublisherID; ba.SupplierID = book.SupplierID; ba.CoverImage = book.CoverImage; //myHandler.AddBook(ba); bookAuthors = myHandler.TrialInsertBook(ba); foreach (var item in Authors) //INSERTING BOOK AUTHORS { bookAuthors.AuthorID = Convert.ToInt32(item); myHandler.InsertBookAuthor(bookAuthors); } TempData["AlertMessage"] = "Book Successfully Entered"; } //return RedirectToAction("Index", "Book", book); return RedirectToAction("Create", "Book", null); //REDIRECT TO GET ACTION METHOD #INCASE THEY WANT TO INSERT ANOTHER BOOK :) } catch { AddNewBookViewModel model = new AddNewBookViewModel(); #region Create SupplierHandler supHandler = new SupplierHandler(); /*TEMP LIST*/ //List<Supplier> nameList = new List<Supplier>(); IEnumerable<Supplier> nameList = (IEnumerable<Supplier>)supHandler.GetBookSupplierList(); var disp = from nameAndId in nameList select new { Value = nameAndId.SupplierID, Text = nameAndId.Name }; ViewBag.SupplierList = new SelectList(disp.ToList()); BookCategoryHandler typeHandler = new BookCategoryHandler(); IEnumerable<BookCategory> typeList = (IEnumerable<BookCategory>)typeHandler.GetBookCategoryList(); var dispBC = from name in typeList select new { Value = name.BookCategoryID, Text = name.CategoryName }; ViewBag.BookCategoryList = new SelectList(dispBC.ToList()); AuthorHandler authHandler = new AuthorHandler(); IEnumerable<Author> authList = (IEnumerable<Author>)authHandler.GetAuthorList(); var dispAuth = from nameAndSurname in authList select new { Value = nameAndSurname.AuthorID, Text = nameAndSurname.Name, nameAndSurname.Surname }; ViewBag.authList = new SelectList(dispAuth.ToList()); PublisherHandler publHandler = new PublisherHandler(); IEnumerable<Publisher> pubList = (IEnumerable<Publisher>)publHandler.GetPublisherList(); var dispPublisher = from pubName in pubList select new { Value = pubName.PublisherID, Text = pubName.Name }; ViewBag.pubList = new SelectList(dispPublisher.ToList()); #endregion #region Display List<SelectListItem> bookCategory = new List<SelectListItem>(); //bookCategory.Add(new SelectListItem { Text = "Select Category", Value = "", Selected = true }); foreach (var item in typeList) { bookCategory.Add(new SelectListItem { Text = item.CategoryName, Value = item.BookCategoryID.ToString() }); } model.bookCategories = new List<SelectListItem>(); model.bookCategories = bookCategory; ViewData["bookCategories"] = bookCategory; List<SelectListItem> supplier = new List<SelectListItem>(); //supplier.Add(new SelectListItem { Text = "Select Supplier", Value = "", Selected = true }); foreach (var item in nameList) { supplier.Add(new SelectListItem { Text = item.Name, Value = item.SupplierID.ToString() }); } model.suppliers = new List<SelectListItem>(); model.suppliers = supplier; ViewData["suppliers"] = supplier; List<SelectListItem> author = new List<SelectListItem>(); //author.Add(new SelectListItem { Text = "Select Author", Value = "", Selected = true }); foreach (var item in authList) { author.Add(new SelectListItem { Text = item.Name, Value = item.AuthorID.ToString() }); } model.authors = new List<SelectListItem>(); model.authors = author; ViewData["authors"] = author; List<SelectListItem> publisher = new List<SelectListItem>(); //publisher.Add(new SelectListItem { Text = "Select Publisher", Value = "", Selected = true }); foreach (var item in pubList) { publisher.Add(new SelectListItem { Text = item.Name, Value = item.PublisherID.ToString() }); } model.publishers = new List<SelectListItem>(); model.publishers = publisher; ViewData["publishers"] = publisher; #endregion return View(model); } }
public ActionResult Create() { #region Create AddNewBookViewModel bookM = new AddNewBookViewModel(); SupplierHandler supHandler = new SupplierHandler(); /*TEMP LIST*/ //List<Supplier> nameList = new List<Supplier>(); IEnumerable<Supplier> nameList = (IEnumerable<Supplier>)supHandler.GetBookSupplierList(); var disp = from nameAndId in nameList select new { Value = nameAndId.SupplierID, Text = nameAndId.Name }; ViewBag.SupplierList = new SelectList(disp.ToList()); BookCategoryHandler typeHandler = new BookCategoryHandler(); IEnumerable<BookCategory> typeList = (IEnumerable<BookCategory>)typeHandler.GetBookCategoryList(); var dispBC = from name in typeList select new { Value = name.BookCategoryID, Text = name.CategoryName }; ViewBag.BookCategoryList = new SelectList(dispBC.ToList()); AuthorHandler authHandler = new AuthorHandler(); IEnumerable<Author> authList = (IEnumerable<Author>)authHandler.GetAuthorList(); var dispAuth = from nameAndSurname in authList select new { Value = nameAndSurname.AuthorID, Text = nameAndSurname.Name, nameAndSurname.Surname }; ViewBag.authList = new SelectList(dispAuth.ToList()); PublisherHandler publHandler = new PublisherHandler(); IEnumerable<Publisher> pubList = (IEnumerable<Publisher>)publHandler.GetPublisherList(); var dispPublisher = from pubName in pubList select new { Value = pubName.PublisherID, Text = pubName.Name }; ViewBag.pubList = new SelectList(dispPublisher.ToList()); #endregion #region Display List<SelectListItem> bookCategory = new List<SelectListItem>(); //bookCategory.Add(new SelectListItem { Text = "Select Category", Value = "", Selected = true }); foreach (var item in typeList) { bookCategory.Add(new SelectListItem { Text = item.CategoryName, Value = item.BookCategoryID.ToString() }); } bookM.bookCategories = new List<SelectListItem>(); bookM.bookCategories = bookCategory; ViewData["bookCategories"] = bookCategory; List<SelectListItem> supplier = new List<SelectListItem>(); //supplier.Add(new SelectListItem { Text = "Select Supplier", Value = "", Selected = true }); foreach (var item in nameList) { supplier.Add(new SelectListItem { Text = item.Name, Value = item.SupplierID.ToString() }); } bookM.suppliers = new List<SelectListItem>(); bookM.suppliers = supplier; ViewData["suppliers"] = supplier; List<SelectListItem> author = new List<SelectListItem>(); //author.Add(new SelectListItem { Text = "Select Author", Value = "", Selected = true }); foreach (var item in authList) { author.Add(new SelectListItem { Text = item.Name, Value = item.AuthorID.ToString() }); } bookM.authors = new List<SelectListItem>(); bookM.authors = author; ViewData["authors"] = author; List<SelectListItem> publisher = new List<SelectListItem>(); //publisher.Add(new SelectListItem { Text = "Select Publisher", Value = "", Selected = true }); foreach (var item in pubList) { publisher.Add(new SelectListItem { Text = item.Name, Value = item.PublisherID.ToString() }); } bookM.publishers = new List<SelectListItem>(); bookM.publishers = publisher; ViewData["publishers"] = publisher; #endregion return View(bookM); }
public IActionResult UpdateAuthor(int id) { var author = new AuthorHandler().GetAuthorById(id); return(View(author)); }
public void Dado_um_comando_valido_deve_criar_a_tarefa() { _handler = new AuthorHandler(new FakeAuthorRepository(new DataContext(new DbContextOptions <DataContext>())), _mapper, _bus, _cache); _result = (GenericCommandResult)_handler.Handle(_validCommand); Assert.AreEqual(_result.Success, false); }
private IScrapedElement GetAuthor(HtmlDocument htmlDoc) { var authorHandler = new AuthorHandler(); return(authorHandler.Handle(htmlDoc, "Author")); }
public GenericCommandResult Update([FromBody] UpdateAuthorCommand command, [FromServices] AuthorHandler handler) { _logger.LogInformation("Executing api/author to update author"); return((GenericCommandResult)handler.Handle(command)); }