public ActionResult TotalSales(FormCollection formCollection) { var fromdate = Convert.ToDateTime(formCollection["fromdate"]); var todate = Convert.ToDateTime(formCollection["todate"]); ViewBag.fromdate = fromdate; ViewBag.todate = todate; List<_671Books.Models.Orders> orders = new List<_671Books.Models.Orders>(); using (BookStoreEntities book = new BookStoreEntities()) { //var order = book.Orders.Where(o => o.orderdate >= fromdate && o.orderdate <= todate).ToList(); var order = book.GetOrderHistory().Where(o => o.orderdate >= fromdate && o.orderdate <= todate).ToList(); ViewBag.Orders = "orders"; foreach (var o in order) { _671Books.Models.Orders _order = new _671Books.Models.Orders(); _order.OrderID = o.orderid; _order.OrderDate = o.orderdate.ToShortDateString(); _order.TotalPrice = o.totalprice; _order.name = o.title; _order.publisher = o.publisher; _order.genre = o.genre; _order.edition = o.edition; _order.author = o.author; _order.year = o.year; orders.Add(_order); } } return View(orders); }
public ActionResult OrderHistory() { //List<_671Books.Models.Book> _books = new List<_671Books.Models.Book>(); List<_671Books.Models.Orders> _orders = new List<_671Books.Models.Orders>(); 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.Orders.Where(b => b.cid.ToString() == userSettings).ToList(); var userBooks = _book.GetOrderHistory().Where(b => b.cid.ToString() == userSettings).ToList(); foreach (var b in userBooks) { //_671Books.Models.Book book = new _671Books.Models.Book(); _671Books.Models.Orders order = new _671Books.Models.Orders(); //book.Author = b.author; //book.Edition = b.edition; //book.Genre = b.genre; //book.ID = b.bid; //book.Name = b.title; //book.Price = b.price; //book.Publisher = b.publisher; //book.Year = b.year; //_books.Add(book); //order.ID = b.cid; order.OrderID = b.orderid; order.OrderDate = b.orderdate.ToShortDateString(); order.TotalPrice = b.totalprice; order.ShippingAddress = b.shippingaddress; order.Quantity = b.qtysold; order.name = b.title; order.publisher = b.publisher; order.author = b.author; order.genre = b.genre; order.year = b.year; order.edition = b.edition; order.price = b.price; order.Status = b.Status; _orders.Add(order); } } return View(_orders); }