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 Product(int ProductID) { #region Prep Utilities myHandler = new BusinessLogicHandler(); UnifiedViewModel model = new UnifiedViewModel(); Author Author = new Author(); #endregion #region Config Roles if(User.IsInRole("supplier")) { model.iSupplier = true; } #endregion #region Get the Data if (myHandler.CheckProductType(ProductID)) { model.Book = new Book(); model.Book = myHandler.GetBook(ProductID); model.BookCategory = new BookCategory(); model.BookCategory = myHandler.GetBookCategory(model.Book.BookCategoryID); model.Publisher = new Publisher(); model.Publisher = myHandler.GetPublisher(model.Book.PublisherID); IEnumerable<BookAuthor> authorsINbook = myHandler.GetBookAuthors(model.Book.BookID); model.Authors = new List<Author>(); foreach(var item in authorsINbook) { Author = myHandler.GetAuthorDetails(item.AuthorID); model.Authors.Add(Author); } } else { model.Device = new Technology(); model.Device = myHandler.GetTechnologyDetails(ProductID); model.Manufacturer = new Manufacturer(); model.Manufacturer = myHandler.GetManufacturer(model.Device.ManufacturerID); model.Category = new TechCategory(); model.Category = myHandler.GetTechnologyType(model.Device.TechCategoryID); } #endregion return View(model); }