public ActionResult Admin() { BookStoreEntities book = new BookStoreEntities(); List<_671Books.Models.Book> _books = new List<_671Books.Models.Book>(); using (BookStoreEntities bookEntities = new BookStoreEntities()) { //_books = bookEntities.Books.ToList(); var books = bookEntities.books.Where(b => b.qtyinstore > 0).ToList(); foreach (var b in books) { _671Books.Models.Book _book = new _671Books.Models.Book(); _book.ID = b.bid; _book.Name = b.title; _book.Author = b.author; _book.Genre = b.genre; _book.Year = b.year; _book.Edition = b.edition; _book.Publisher = b.publisher; _book.Price = b.price; _book.QuantityInStore = b.qtyinstore; //_book.QuantitySold = b.qtysold; //_book.BookCover = b.BookCover; _books.Add(_book); } return View(_books); } }
public ActionResult Admin(FormCollection formCollection) { List<_671Books.Models.Book> _books = new List<_671Books.Models.Book>(); using (BookStoreEntities bookEntities = new BookStoreEntities()) { var Author = formCollection["Author"]; var Genre = (formCollection["Genres"]); var Year = (formCollection["Year"]); var books = bookEntities.books.ToList(); if (Author.Length != 0) { books = books.Where(b => b.author.ToLower().Contains(Author.ToLower()) && b.qtyinstore > 0).ToList(); } if (Genre.Length != 0) { books = books.Where(b => b.genre == Genre && b.qtyinstore > 0).ToList(); } if (Year.Length != 0) { books = books.Where(b => b.year.ToString() == Year && b.qtyinstore > 0).ToList(); } foreach (var book in books) { _671Books.Models.Book _book = new _671Books.Models.Book(); _book.ID = book.bid; _book.Name = book.title; _book.Author = book.author; _book.Genre = book.genre; _book.Year = book.year; _book.Edition = book.edition; _book.Publisher = book.publisher; _book.Price = book.price; _book.QuantityInStore = book.qtyinstore; //_book.QuantitySold = book.qtysold; _books.Add(_book); } return View(_books); } }
public ActionResult BookDetails(string ID, string Source) { _671Books.Models.Book _book = new _671Books.Models.Book(); BookStoreEntities book = new BookStoreEntities(); var books = book.books.ToList(); books = books.Where(b => b.bid.ToString() == ID).ToList(); if (Source != "Index") { ViewBag.DisplayButton = "display:none"; ViewBag.DisplayRemoveButton = "display:block"; } else { ViewBag.DisplayButton = "display:block"; ViewBag.DisplayRemoveButton = "display:none"; } foreach (var b in books) { _book.ID = b.bid; _book.Name = b.title; _book.Author = b.author; _book.Genre = b.genre; _book.Year = b.year; _book.Edition = b.edition; _book.Publisher = b.publisher; _book.Price = b.price; _book.QuantityInStore = b.qtyinstore; //_book.QuantitySold = b.qtysold; // _book.BookCover = b.BookCover; } return View(_book); }
public ActionResult Cart(FormCollection formCollection) { int n = 0; var Name = formCollection["Name"]; var ShippingAddress = formCollection["ShippingAddress"]; var BillingAddress = formCollection["BillingAddress"]; var Card = formCollection["Card"]; var CVV = formCollection["CVV"]; long cardInt; bool isCardNumerical = Int64.TryParse(Card, out cardInt); //string error = ""; int cvvInt; bool isCVVNumerical = Int32.TryParse(CVV, out cvvInt); var error = new StringBuilder(); if (string.IsNullOrEmpty(Name)) { error.AppendLine("Please enter a Name"); error.AppendLine(); //error = error + "Please enter a Name" + "\n" ; } if (string.IsNullOrEmpty(ShippingAddress)) { //error = error + "Please enter Shipping Address" + "\n"; error.AppendLine("Please enter Shipping Address"); error.AppendLine(); } if (string.IsNullOrEmpty(BillingAddress)) { //error = error + "Please enter Billing Address" + "\n"; error.Append("Please enter Billing Address"); error.AppendLine(); } if (string.IsNullOrEmpty(Card)) { //error = error + "Please enter Credit Card Number" + "\n"; error.Append("Please enter Credit Card Number"); error.AppendLine(); } if (string.IsNullOrEmpty(CVV)) { //error = error + "Please enter CVV Number" + "\n"; error.Append("Please enter CVV Number"); error.AppendLine(); } if (!isCardNumerical) { //error = error + "Please enter valid Credit Card Number" + "\n"; error.Append("Please enter valid Credit Card Number"); error.AppendLine(); } if (!isCVVNumerical) { //error = error + "Please enter valid CVV Number" + "\n"; error.Append("Please enter valid CVV Number"); error.AppendLine(); } error = error.Replace("\n", Environment.NewLine); ViewBag.SummaryDiv = error.ToString(); List<_671Books.Models.Book> _books = new List<_671Books.Models.Book>(); if (error.Length == 0) { List<string> ID = new List<string>(); List<string> a = new List<string>(); int count = 0; string value = ""; decimal total = 0; //string[] a = new string[100]; string userSettings = "0"; if (Request.Cookies["UserSettings"] != null) { if (Request.Cookies["UserSettings"]["UserID"] != null) { userSettings = Request.Cookies["UserSettings"]["UserID"]; } } using (BookStoreEntities book = new BookStoreEntities()) { foreach (var key in formCollection.AllKeys) { if (key != "Name" && key != "ShippingAddress" && key != "BillingAddress" && key != "Card" && key != "MM" && key != "YY" && key != "CVV" && key != "placeOrder") { if (key.Contains("txt")) { value = formCollection["txt"]; //a = value.Split(','); } else { var v = key; ID.Add(v); } } //var value = formCollection[key]; //var ID = key.Substring(2, key.Length - 3); //if (key.Contains("txt")) //{ // var value = formCollection[key]; // var ID = key.Substring(3, key.Length - 3); // } Random r = new Random(); n = r.Next(1000001, 9999999); string[] b = value.Split(','); for (int j = 0; j < b.Count(); j++) { a.Add(b[j]); } var bookToRemove = book.Carts.Where(_book => _book.cid.ToString() == userSettings && _book.orderStatus == "Placed"); book.Carts.RemoveRange(bookToRemove); book.SaveChanges(); decimal qty = 0; for (int i = 0; i < a.Count(); i++) { var id = ID[i]; var originalRecord = book.books.FirstOrDefault(x => x.bid.ToString() == id); if (originalRecord != null) { var num = Convert.ToDecimal(a[i]); total = total + num; var den = Convert.ToDecimal(originalRecord.price); qty = num / den; //book.Carts.Add(new Cart { cid = Convert.ToInt32(userSettings), bid = originalRecord.bid, price = Convert.ToDecimal(a[i]), title = originalRecord.title, qty = (int)qty, edition = originalRecord.edition, year = originalRecord.year, author = originalRecord.author, publisher = originalRecord.publisher, genre = originalRecord.genre,inWishList = false, orderStatus = "Ordered", qtyinstore = originalRecord.qtyinstore}); //book.SaveChanges(); book.Orders.Add(new Order { cid = Convert.ToInt32(userSettings), bid=originalRecord.bid, orderdate = DateTime.Now, shippingaddress = ShippingAddress, Status = "Ordered", totalprice = num, orderid = n, qtysold = Convert.ToInt32(qty) }); book.SaveChanges(); } // book.Carts.Add(new Cart { cid = Convert.ToInt32(userSettings), bid = Convert.ToInt32(ID[i]), }); } //uncomment following if the above logic fails //book.Orders.Add(new Order { cid = Convert.ToInt32(userSettings), orderdate = DateTime.Now, shippingaddress = ShippingAddress, Status = "Ordered", totalprice = total, orderid = n, qtysold = Convert.ToInt32(qty) }); //book.SaveChanges(); } return RedirectToAction("Confirmation", "Home", new {orderNumber = n}); } else { string userSettings = "0"; if (Request.Cookies["UserSettings"] != null) { if (Request.Cookies["UserSettings"]["UserID"] != null) { userSettings = Request.Cookies["UserSettings"]["UserID"]; } } using (BookStoreEntities _book = new BookStoreEntities()) { var userBooks = _book.Carts.Where(b => b.cid.ToString() == userSettings && b.inWishList == false && b.orderStatus == "Placed").ToList(); foreach (var b in userBooks) { _671Books.Models.Book book = new _671Books.Models.Book(); book.Author = b.author; //book.BookCover book.Edition = b.edition; book.Genre = b.genre; book.ID = b.bid; //book.ISBN = b.i book.Name = b.title; book.Price = b.price; book.Publisher = b.publisher; book.QuantityInStore = b.qtyinstore; book.Year = b.year; _books.Add(book); } } return View(_books); } }
public ActionResult Cart() { List<_671Books.Models.Book> _books = new List<_671Books.Models.Book>(); string userSettings = "0"; if (Request.Cookies["UserSettings"] != null) { if (Request.Cookies["UserSettings"]["UserID"] != null) { userSettings = Request.Cookies["UserSettings"]["UserID"]; } } using (BookStoreEntities _book = new BookStoreEntities()) { var userBooks = _book.Carts.Where(b => b.cid.ToString() == userSettings && b.inWishList == false && b.orderStatus == "Placed").ToList(); foreach (var b in userBooks) { _671Books.Models.Book book = new _671Books.Models.Book(); book.Author = b.author; //book.BookCover book.Edition = b.edition; book.Genre = b.genre; book.ID = b.bid; //book.ISBN = b.i book.Name = b.title; book.Price = b.price; book.Publisher = b.publisher; book.QuantityInStore = b.qtyinstore; book.Year = b.year; _books.Add(book); } //ViewBag.ModelCount = _books.Count(); //for (var i = 0; i < userBooks.Count; i++ ) //{ // book.Author = userBooks[i].author; // //book.BookCover // book.Edition = userBooks[i].edition; // book.Genre = userBooks[i].genre; // book.ID = userBooks[i].bid; // //book.ISBN = b.i // book.Name = userBooks[i].title; // book.Price = userBooks[i].price; // book.Publisher = userBooks[i].publisher; // book.QuantityInStore = userBooks[i].qtyinstore; // book.Year = userBooks[i].year; // _books.Add(book); //} } return View(_books); }
public ActionResult BookDetailsAdmin(FormCollection formCollection) { var ID = Convert.ToInt32(formCollection["txtID"]); var TitleBook = formCollection["TitleBook"]; var Edition = formCollection["Edition"]; var Year = formCollection["Year"]; var Price = formCollection["Price"]; var Author = formCollection["Author"]; var Publisher = formCollection["Publisher"]; var Genre = formCollection["Genre"]; var QtyInStore = formCollection["QtyInStore"]; decimal outPrice = 0; bool isPriceDecimal = Decimal.TryParse(Price, out outPrice); int outYear = 0; bool isYearNumerical = Int32.TryParse(Year, out outYear); int outQtyInStore = 0; bool isQtyInStoreNumerical = Int32.TryParse(QtyInStore, out outQtyInStore); int outEdition = 0; bool isEditionNumerical = Int32.TryParse(Edition, out outEdition); bool flag = true; bool numflag = true; string error = ""; if (string.IsNullOrEmpty(TitleBook)) { flag = false; } if (string.IsNullOrEmpty(Edition)) { flag = false; } if (string.IsNullOrEmpty(Year)) { flag = false; } if (string.IsNullOrEmpty(Author)) { flag = false; } if (string.IsNullOrEmpty(Publisher)) { flag = false; } if (string.IsNullOrEmpty(Genre)) { flag = false; } if (string.IsNullOrEmpty(Price)) { flag = false; } if (string.IsNullOrEmpty(QtyInStore)) { flag = false; } if (!isPriceDecimal) { numflag = false; } if (!isYearNumerical) { numflag = false; } if (!isEditionNumerical) { numflag = false; } if (!isQtyInStoreNumerical) { numflag = false; } if (flag) { if (numflag) { using (BookStoreEntities book = new BookStoreEntities()) { //var bookToRemove = book.books.Where(b => b.bid == ID); //book.books.RemoveRange(bookToRemove); //book.SaveChanges(); //book.books.Add(new book { bid = ID, title = TitleBook, edition = Edition, author = Author, genre = Genre, price = Price, publisher = Publisher, year = Year, qtyinstore = QtyInStore, qtysold = 0 }); //book.SaveChanges(); var bookToFind = book.books.Find(ID); bookToFind.author = Author; bookToFind.edition = outEdition; bookToFind.year = outYear; bookToFind.publisher = Publisher; bookToFind.genre = Genre; bookToFind.price = outPrice; bookToFind.qtyinstore = outQtyInStore; bookToFind.title = TitleBook; book.SaveChanges(); } } else { ViewBag.SummaryDiv = "Please enter valid values"; _671Books.Models.Book _book = new _671Books.Models.Book(); BookStoreEntities book = new BookStoreEntities(); var books = book.books.ToList(); books = books.Where(b => b.bid == ID).ToList(); foreach (var b in books) { _book.ID = b.bid; _book.Name = b.title; _book.Author = b.author; _book.Genre = b.genre; _book.Year = b.year; _book.Edition = b.edition; _book.Publisher = b.publisher; _book.Price = b.price; _book.QuantityInStore = b.qtyinstore; //_book.QuantitySold = b.qtysold; // _book.BookCover = b.BookCover; } return View(_book); } } else { ViewBag.SummaryDiv = "Please enter all values"; _671Books.Models.Book _book = new _671Books.Models.Book(); BookStoreEntities book = new BookStoreEntities(); var books = book.books.ToList(); books = books.Where(b => b.bid == ID).ToList(); foreach (var b in books) { _book.ID = b.bid; _book.Name = b.title; _book.Author = b.author; _book.Genre = b.genre; _book.Year = b.year; _book.Edition = b.edition; _book.Publisher = b.publisher; _book.Price = b.price; _book.QuantityInStore = b.qtyinstore; //_book.QuantitySold = b.qtysold; // _book.BookCover = b.BookCover; } return View(_book); } return RedirectToAction("Admin", "Home"); }
public ActionResult BookDetailsAdmin(string ID) { _671Books.Models.Book _book = new _671Books.Models.Book(); BookStoreEntities book = new BookStoreEntities(); var books = book.books.ToList(); books = books.Where(b => b.bid.ToString() == ID).ToList(); foreach (var b in books) { _book.ID = b.bid; _book.Name = b.title; _book.Author = b.author; _book.Genre = b.genre; _book.Year = b.year; _book.Edition = b.edition; _book.Publisher = b.publisher; _book.Price = b.price; _book.QuantityInStore = b.qtyinstore; //_book.QuantitySold = b.qtysold; // _book.BookCover = b.BookCover; } return View(_book); }
public ActionResult WishList() { List<_671Books.Models.Book> _books = new List<_671Books.Models.Book>(); string userSettings = ""; if (Request.Cookies["UserSettings"] != null) { if (Request.Cookies["UserSettings"]["UserID"] != null) { userSettings = Request.Cookies["UserSettings"]["UserID"]; } } using (BookStoreEntities _book = new BookStoreEntities()) { var userBooks = _book.Carts.Where(b => b.cid.ToString() == userSettings && b.inWishList == true).ToList(); foreach (var b in userBooks) { _671Books.Models.Book book = new _671Books.Models.Book(); book.Author = b.author; //book.BookCover book.Edition = b.edition; book.Genre = b.genre; book.ID = b.bid; //book.ISBN = b.i book.Name = b.title; book.Price = b.price; book.Publisher = b.publisher; book.Year = b.year; _books.Add(book); } } return View(_books); }