// GET: Order public ActionResult Index() { SmartNerdDataContext db = new SmartNerdDataContext(); var orders = (from a in db.Orders where a.AccountID == new Guid(User.Identity.GetUserId()) && a.DatePlaced.HasValue select new Models.Order.Order { Address = new Models.Address { AddressID = a.Address.AddressID, City = a.Address.City, County = a.Address.County, FullName = a.Address.FullName, Line1 = a.Address.Line1, Line2 = a.Address.Line2, StateOrProvince = a.Address.StateOrProvince, ZipCode = a.Address.ZipCode }, DatePlaced = a.DatePlaced.Value, Total = a.OrderTotal, OrderID = a.OrderID, Products = a.OrderProducts.Select(b => new Models.Order.Product { Name = b.Product.Name, ProductID = b.ProductID, Quantity = b.Quantity, Price = b.Product.Price }) }).ToList(); return View(orders); }
public ActionResult CreateProduct(HttpPostedFileBase file, Product model) { SmartNerdDataContext db = new SmartNerdDataContext(); if (file == null || file.ContentLength == 0 || file.ContentType != "image/png") { ModelState.AddModelError("", "Product Image must be a valid PNG"); TempData["ModelState"] = ModelState; } if (ModelState.IsValid) { var prod = new DataModels.Product { Description = model.Description, Inventory = model.Inventory, Name = model.ProductName, Price = model.Price }; db.Products.InsertOnSubmit(prod); db.SubmitChanges(); var path = Path.Combine(Server.MapPath("~/Images/p"), prod.ProductID.ToString() + ".png"); file.SaveAs(path); return(RedirectToAction("Product", new { productID = prod.ProductID })); } return(RedirectToAction("CreateProduct", model)); }
// GET: Order public ActionResult Index() { SmartNerdDataContext db = new SmartNerdDataContext(); var orders = (from a in db.Orders where a.AccountID == new Guid(User.Identity.GetUserId()) && a.DatePlaced.HasValue select new Models.Order.Order { Address = new Models.Address { AddressID = a.Address.AddressID, City = a.Address.City, County = a.Address.County, FullName = a.Address.FullName, Line1 = a.Address.Line1, Line2 = a.Address.Line2, StateOrProvince = a.Address.StateOrProvince, ZipCode = a.Address.ZipCode }, DatePlaced = a.DatePlaced.Value, Total = a.OrderTotal, OrderID = a.OrderID, Products = a.OrderProducts.Select(b => new Models.Order.Product { Name = b.Product.Name, ProductID = b.ProductID, Quantity = b.Quantity, Price = b.Product.Price }) }).ToList(); return(View(orders)); }
public ActionResult CreateProduct(HttpPostedFileBase file,Product model) { SmartNerdDataContext db = new SmartNerdDataContext(); if(file == null || file.ContentLength == 0 || file.ContentType != "image/png") { ModelState.AddModelError("","Product Image must be a valid PNG"); TempData["ModelState"] = ModelState; } if(ModelState.IsValid) { var prod = new DataModels.Product { Description = model.Description, Inventory = model.Inventory, Name = model.ProductName, Price = model.Price }; db.Products.InsertOnSubmit(prod); db.SubmitChanges(); var path = Path.Combine(Server.MapPath("~/Images/p"),prod.ProductID.ToString() + ".png"); file.SaveAs(path); return RedirectToAction("Product",new { productID = prod.ProductID }); } return RedirectToAction("CreateProduct",model); }
public ActionResult Browse(int? categoryID = null) { SmartNerdDataContext dc = new SmartNerdDataContext(); List<Product> prods; //get all products if(categoryID == null) { prods = (from p in dc.Products select new Product { ProductName = p.Name, ProductID = p.ProductID, Price = p.Price, Description = p.Description }).ToList(); } else { prods = (from c in dc.Categories join ce in dc.CategoryEntries on c.CategoryID equals ce.CategoryID join p in dc.Products on ce.ProductID equals p.ProductID where c.CategoryID == categoryID.Value select new Product { ProductName = p.Name, ProductID = p.ProductID, Price = p.Price, Description = p.Description }).ToList(); } BrowsePage mp = new BrowsePage { Categories = (from c in dc.Categories select new Category { CategoryID = c.CategoryID, CategoryName = c.Name }).ToList(), Products = prods }; return View(mp); }
public ActionResult ThankYou(int OrderId) { SmartNerdDataContext db = new SmartNerdDataContext(); var order = db.Orders.Single(a => a.OrderID == OrderId); var orderModel = new Models.Order.Order { Address = new Models.Address { AddressID = order.Address.AddressID, City = order.Address.City, County = order.Address.County, FullName = order.Address.FullName, Line1 = order.Address.FullName, Line2 = order.Address.Line2, StateOrProvince = order.Address.StateOrProvince, ZipCode = order.Address.ZipCode }, DatePlaced = order.DatePlaced.Value, OrderID = Cart.OrderID, Total = order.OrderTotal, Products = (from a in order.OrderProducts join b in db.Products on a.ProductID equals b.ProductID select new Models.Order.Product { Name = b.Name, Price = b.Price, ProductID = b.ProductID, Quantity = a.Quantity }).ToList() }; return(View(orderModel)); }
public ActionResult Index() { SmartNerdDataContext _context = new SmartNerdDataContext(); var rprt = (from p in _context.Payments join o in _context.Orders on p.OrderID equals o.OrderID where o.DatePlaced != null group new { p, o } by o.DatePlaced.Value.Year + "-" + o.DatePlaced.Value.Month + "-" + o.DatePlaced.Value.Day into agg select new Models.Admin.ReportEntry { DatePlaced = DateTime.Parse(agg.Key), NumberOfOrders = agg.Count(), DailyTotal = agg.Sum(a => a.o.OrderTotal) }).ToList(); var frq = (from p in _context.Payments join o in _context.Orders on p.OrderID equals o.OrderID join op in _context.OrderProducts on o.OrderID equals op.OrderID join pr in _context.Products on op.ProductID equals pr.ProductID where o.DatePlaced != null group new { p, o, op, pr } by new { op.ProductID, pr.Name } into agg select new Models.Admin.FrequentEntry { ProductID = agg.Key.ProductID, Name = agg.Key.Name, TotalRevenue = agg.Sum(a => a.op.Quantity) * agg.First().pr.Price, NumberOrdered = agg.Sum(a => a.op.Quantity) }).OrderByDescending(f => f.TotalRevenue).Take(5).ToList(); return(View(new Models.Admin.ReportPage { DailyReport = rprt, FrequentProducts = frq })); }
public Cart(Guid cartID) { _context = new SmartNerdDataContext(); _order = (from o in _context.Orders where o.CartID == cartID select o).First(); }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); SmartNerdDataContext _context = new SmartNerdDataContext(); ViewBag.Categories = (from c in _context.Categories select new Models.Menu.Category { CategoryID = c.CategoryID, CategoryName = c.Name }).ToList(); }
public ActionResult RemoveAddress(int addressID, string returnUrl) { SmartNerdDataContext _context = new SmartNerdDataContext(); DataModels.AccountAddress addrs = (from aa in _context.AccountAddresses where aa.UserID == Cart.AccountID.ToString() && aa.AddressID == addressID select aa).First(); _context.AccountAddresses.DeleteOnSubmit(addrs); _context.SubmitChanges(); return(Redirect(returnUrl)); }
public ActionResult Address(Models.CartViewModels.AddressPage model) { if (model.AddressToUse != -1) { Cart.AddressID = model.AddressToUse; Cart.Save(); if (Session["CartID"] == null) { Session["CartID"] = Cart.CartID; } return(RedirectToAction("Pay", "Cart")); } else { TryUpdateModel(model.CartAddress); if (ModelState.IsValid) { Cart.UseNewAddress(new Address { City = model.CartAddress.City, Line1 = model.CartAddress.Line1, Line2 = model.CartAddress.Line2, StateOrProvince = model.CartAddress.StateOrProvince, ZipCode = model.CartAddress.ZipCode, County = model.CartAddress.County, FullName = model.CartAddress.FullName }); if (model.SaveAddress) { DataModels.AccountAddress aa = new DataModels.AccountAddress { UserID = User.Identity.GetUserId(), AddressID = Cart.AddressID.Value, AddressType = "Mailing" }; SmartNerdDataContext _context = new SmartNerdDataContext(); _context.AccountAddresses.InsertOnSubmit(aa); _context.SubmitChanges(); } Cart.Save(); if (Session["CartID"] == null) { Session["CartID"] = Cart.CartID; } return(RedirectToAction("Pay", "Cart")); } } Models.CartViewModels.AddressPage add = BuildAddressPage(); add.CartAddress = model.CartAddress; return(View(add)); }
public ActionResult Product(Product model) { SmartNerdDataContext db = new SmartNerdDataContext(); var prod = db.Products.Single(a => a.ProductID == model.ProductID); prod.Description = model.Description; prod.Name = model.ProductName; prod.Price = model.Price; prod.Inventory = model.Inventory; db.SubmitChanges(); return(View(model)); }
public ActionResult Product(Product prod) { SmartNerdDataContext _context = new SmartNerdDataContext(); if (ModelState.IsValid) { if (Cart.OrderID == 0) { Cart.Save(); Session["CartID"] = Cart.CartID; } Cart.AddProduct(prod); Cart.Save(); } return(RedirectToAction("Checkout", "Cart")); }
public ActionResult Product(Product prod) { SmartNerdDataContext _context = new SmartNerdDataContext(); if (ModelState.IsValid) { if (Cart.OrderID == 0) { Cart.Save(); Session["CartID"] = Cart.CartID; } Cart.AddProduct(prod); Cart.Save(); } return RedirectToAction("Checkout", "Cart"); }
private Models.CartViewModels.AddressPage BuildAddressPage() { SmartNerdDataContext _context = new SmartNerdDataContext(); Models.CartViewModels.AddressPage add = new Models.CartViewModels.AddressPage { BillingAddresses = new List <Models.Address>(), MailingAddresses = new List <Models.Address>(), }; if (User.Identity.GetUserId() != null) { add = new Models.CartViewModels.AddressPage(); List <Models.AccountAddress> addresses = (from aa in _context.AccountAddresses join a in _context.Addresses on aa.AddressID equals a.AddressID where aa.UserID == User.Identity.GetUserId() select new AccountAddress { AddressID = a.AddressID, FullName = a.FullName, City = a.City, County = a.County, Line1 = a.Line1, Line2 = a.Line2, StateOrProvince = a.StateOrProvince, ZipCode = a.ZipCode, AddressType = aa.AddressType, AccountID = new Guid(aa.UserID) }).ToList(); add.BillingAddresses = addresses.Where(m => m.AddressType == "Billing").Select(m => (Models.Address)m).ToList(); add.MailingAddresses = addresses.Where(m => m.AddressType == "Mailing").Select(m => (Models.Address)m).ToList(); } Models.Address addressInList = add.MailingAddresses.FirstOrDefault(a => a.AddressID == Cart.AddressID); if (Cart.AddressID != null && addressInList == null) { add.CartAddress = (from a in _context.Addresses where a.AddressID == Cart.AddressID select new Models.Address { FullName = a.FullName, City = a.City, County = a.County, Line1 = a.Line1, Line2 = a.Line2, StateOrProvince = a.StateOrProvince, ZipCode = a.ZipCode }).FirstOrDefault(); } return(add); }
public void UseNewAddress(Address newAddress) { SmartNerdDataContext _context2 = new SmartNerdDataContext(); DataModels.Address _newAddress = new DataModels.Address { FullName = newAddress.FullName, City = newAddress.City, Line1 = newAddress.Line1, Line2 = newAddress.Line2, County = newAddress.County, StateOrProvince = newAddress.StateOrProvince, ZipCode = newAddress.ZipCode, }; _context2.Addresses.InsertOnSubmit(_newAddress); _context2.SubmitChanges(); _order.AddressID = _newAddress.AddressID; }
public ActionResult Product(int productID, int?categoryID = null) { SmartNerdDataContext _context = new SmartNerdDataContext(); Models.Menu.Product prod = (from p in _context.Products where p.ProductID == productID select new Product { ProductID = p.ProductID, Price = p.Price, ProductName = p.Name, Description = p.Description, Quantity = 1, Inventory = p.Inventory }).First(); return(View(prod)); }
public ActionResult Product(int productID, int? categoryID = null) { SmartNerdDataContext _context = new SmartNerdDataContext(); Models.Menu.Product prod = (from p in _context.Products where p.ProductID == productID select new Product { ProductID = p.ProductID, Price = p.Price, ProductName = p.Name, Description = p.Description, Quantity = 1, Inventory = p.Inventory }).First(); return View(prod); }
public ActionResult Address(Models.CartViewModels.AddressPage model) { if(model.AddressToUse != -1) { Cart.AddressID = model.AddressToUse; Cart.Save(); if(Session["CartID"] == null) { Session["CartID"] = Cart.CartID; } return RedirectToAction("Pay","Cart"); } else { TryUpdateModel(model.CartAddress); if(ModelState.IsValid) { Cart.UseNewAddress(new Address { City = model.CartAddress.City, Line1 = model.CartAddress.Line1, Line2 = model.CartAddress.Line2, StateOrProvince = model.CartAddress.StateOrProvince, ZipCode = model.CartAddress.ZipCode, County = model.CartAddress.County, FullName = model.CartAddress.FullName }); if(model.SaveAddress) { DataModels.AccountAddress aa = new DataModels.AccountAddress { UserID = User.Identity.GetUserId(), AddressID = Cart.AddressID.Value, AddressType = "Mailing" }; SmartNerdDataContext _context = new SmartNerdDataContext(); _context.AccountAddresses.InsertOnSubmit(aa); _context.SubmitChanges(); } Cart.Save(); if(Session["CartID"] == null) { Session["CartID"] = Cart.CartID; } return RedirectToAction("Pay","Cart"); } } Models.CartViewModels.AddressPage add = BuildAddressPage(); add.CartAddress = model.CartAddress; return View(add); }
public ActionResult Checkout(bool? noProducts = null) { SmartNerdDataContext _context = new SmartNerdDataContext(); Models.CartViewModels.CheckoutPage c = new Models.CartViewModels.CheckoutPage { Products = (from op in Cart.Products join p in _context.Products on op.ProductID equals p.ProductID select new Models.Menu.Product { ProductID = p.ProductID, ProductName = p.Name, Quantity = op.Quantity, Description = p.Description, Price = p.Price }).ToList(), Total = Cart.Total }; if(noProducts.HasValue) { ModelState.AddModelError("","You must have products in your cart to continue"); } return View(c); }
// // GET: /Menu/ public ActionResult Index(int?categoryID = null) { SmartNerdDataContext dc = new SmartNerdDataContext(); List <Product> prods; //get all products if (categoryID == null) { prods = (from p in dc.Products select new Models.Menu.Product { ProductName = p.Name, ProductID = p.ProductID, Price = p.Price, Description = p.Description }).ToList(); } else { prods = (from c in dc.Categories join ce in dc.CategoryEntries on c.CategoryID equals ce.CategoryID join p in dc.Products on ce.ProductID equals p.ProductID where c.CategoryID == categoryID.Value select new Models.Menu.Product { ProductName = p.Name, ProductID = p.ProductID, Price = p.Price, Description = p.Description }).ToList(); } Models.Menu.MenuPage mp = new Models.Menu.MenuPage { Products = prods, CategoryID = 0 }; if (categoryID != null) { mp.CategoryID = categoryID.Value; } return(View(mp)); }
public ActionResult DeleteProduct(Product model) { SmartNerdDataContext db = new SmartNerdDataContext(); var entries = (from a in db.CategoryEntries where a.ProductID == model.ProductID select a).ToList(); foreach (var entry in entries) { db.CategoryEntries.DeleteOnSubmit(entry); } var prod = db.Products.Single(a => a.ProductID == model.ProductID); db.Products.DeleteOnSubmit(prod); db.SubmitChanges(); return(RedirectToAction("Browse")); }
public ActionResult Browse(int?categoryID = null) { SmartNerdDataContext dc = new SmartNerdDataContext(); List <Product> prods; //get all products if (categoryID == null) { prods = (from p in dc.Products select new Product { ProductName = p.Name, ProductID = p.ProductID, Price = p.Price, Description = p.Description }).ToList(); } else { prods = (from c in dc.Categories join ce in dc.CategoryEntries on c.CategoryID equals ce.CategoryID join p in dc.Products on ce.ProductID equals p.ProductID where c.CategoryID == categoryID.Value select new Product { ProductName = p.Name, ProductID = p.ProductID, Price = p.Price, Description = p.Description }).ToList(); } BrowsePage mp = new BrowsePage { Categories = (from c in dc.Categories select new Category { CategoryID = c.CategoryID, CategoryName = c.Name }).ToList(), Products = prods }; return(View(mp)); }
public ActionResult Pay(Models.CartViewModels.PayPage model) { if (ModelState.IsValid) { if (Cart.Products == null || Cart.Products.Count == 0) { return(RedirectToAction("Index", "Home")); } if (Cart.OrderID == 0) { return(RedirectToAction("Index", "Home")); } SmartNerdDataContext _context = new SmartNerdDataContext(); List <DataModels.Product> dataProducts = (from p in _context.Products where Cart.Products.Select(pr => pr.ProductID).Contains(p.ProductID) select p).ToList(); foreach (var p in Cart.Products) { DataModels.Product dataProduct = dataProducts.First(pr => pr.ProductID == p.ProductID); if (dataProduct.Inventory - p.Quantity < 0) { ModelState.AddModelError("", "There isn't sufficient inventory to place this order (" + dataProduct.Name + ": " + dataProduct.Inventory + ")."); return(View()); } } Cart.SubmitOrder(new Payment { CardNumber = model.CardNumber, CardType = model.CardType, PayPalID = model.PayPalUsername }); Session["CartID"] = null; return(RedirectToAction("ThankYou", "Cart", new { OrderId = Cart.OrderID })); } return(View()); }
public ActionResult Checkout(Models.CartViewModels.CheckoutPage model) { SmartNerdDataContext _context = new SmartNerdDataContext(); List <DataModels.Product> dataProducts = (from p in _context.Products where Cart.Products.Select(pr => pr.ProductID).Contains(p.ProductID) select p).ToList(); foreach (var p in model.Products) { DataModels.Product dataProduct = dataProducts.First(pr => pr.ProductID == p.ProductID); Cart.Products.Where(prod => prod.ProductID == p.ProductID).ToList().ForEach(prod => prod.Quantity = p.Quantity); foreach (var pr in Cart.Products.Where(prod => prod.Quantity < 1)) { Cart.RemoveProduct(pr.ProductID); } if (dataProduct.Inventory - p.Quantity < 0) { ModelState.AddModelError("", "There isn't sufficient inventory to place this order (" + dataProduct.Name + ": " + dataProduct.Inventory + ")."); Models.CartViewModels.CheckoutPage c = new Models.CartViewModels.CheckoutPage { Products = (from op in Cart.Products join pro in _context.Products on op.ProductID equals pro.ProductID select new Models.Menu.Product { ProductID = pro.ProductID, ProductName = pro.Name, Quantity = op.Quantity, Description = pro.Description, Price = pro.Price }).ToList(), Total = Cart.Total }; return(View(c)); } } Cart.Save(); return(RedirectToAction("Address", "Cart")); }
public ActionResult Search(SearchPage model) { SmartNerdDataContext dc = new SmartNerdDataContext(); List <Product> products = null; if (model.SearchTerm != null) { products = (from a in dc.Products where a.Name.Contains(model.SearchTerm) select new Product { Description = a.Description, Price = a.Price, ProductID = a.ProductID, ProductName = a.Name }).ToList(); } model.Products = products; return(View(model)); }
public ActionResult Checkout(bool?noProducts = null) { SmartNerdDataContext _context = new SmartNerdDataContext(); Models.CartViewModels.CheckoutPage c = new Models.CartViewModels.CheckoutPage { Products = (from op in Cart.Products join p in _context.Products on op.ProductID equals p.ProductID select new Models.Menu.Product { ProductID = p.ProductID, ProductName = p.Name, Quantity = op.Quantity, Description = p.Description, Price = p.Price }).ToList(), Total = Cart.Total }; if (noProducts.HasValue) { ModelState.AddModelError("", "You must have products in your cart to continue"); } return(View(c)); }
public ActionResult Product(int productID, int?categoryID = null) { if (TempData["ModelState"] != null && !ModelState.Equals(TempData["ModelState"])) { ModelState.Merge((ModelStateDictionary)TempData["ModelState"]); } SmartNerdDataContext _context = new SmartNerdDataContext(); Product prod = (from p in _context.Products where p.ProductID == productID select new Product { ProductID = p.ProductID, Price = p.Price, ProductName = p.Name, Description = p.Description, Inventory = p.Inventory }).First(); return(View(prod)); }
public ActionResult Recovery(Boolean?recover) { SmartNerdDataContext db = new SmartNerdDataContext(); if (recover.HasValue) { ModelState.AddModelError("", "System recovered"); FileInfo file = new FileInfo(Server.MapPath("~/Recovery/ddl.sql")); string script = file.OpenText().ReadToEnd(); try { db.ExecuteCommand(script); } catch { } try { db.ExecuteCommand(script); } catch { } file = new FileInfo(Server.MapPath("~/Recovery/menu.sql")); script = file.OpenText().ReadToEnd(); try { db.ExecuteCommand(script); } catch { } Directory.Delete(Server.MapPath("~/Images/p"), true); Directory.CreateDirectory(Server.MapPath("~/Images/p")); foreach (String image in Directory.GetFiles(Server.MapPath("~/Recovery/p"))) { String fileName = Path.GetFileName(image); String destFile = Path.Combine(Server.MapPath("~/Images/p"), fileName); System.IO.File.Copy(image, destFile, true); } } return(View(recover)); }
// // GET: /Menu/ public ActionResult Index(int? categoryID = null) { SmartNerdDataContext dc = new SmartNerdDataContext(); List<Product> prods; //get all products if(categoryID == null) { prods = (from p in dc.Products select new Models.Menu.Product { ProductName = p.Name, ProductID = p.ProductID, Price = p.Price, Description = p.Description }).ToList(); } else { prods = (from c in dc.Categories join ce in dc.CategoryEntries on c.CategoryID equals ce.CategoryID join p in dc.Products on ce.ProductID equals p.ProductID where c.CategoryID == categoryID.Value select new Models.Menu.Product { ProductName = p.Name, ProductID = p.ProductID, Price = p.Price, Description = p.Description }).ToList(); } Models.Menu.MenuPage mp = new Models.Menu.MenuPage{ Products = prods, CategoryID = 0 }; if(categoryID != null) { mp.CategoryID = categoryID.Value; } return View(mp); }
public ActionResult Product(Product model) { SmartNerdDataContext db = new SmartNerdDataContext(); var prod = db.Products.Single(a => a.ProductID == model.ProductID); prod.Description = model.Description; prod.Name = model.ProductName; prod.Price = model.Price; prod.Inventory = model.Inventory; db.SubmitChanges(); return View(model); }
public ActionResult Recovery(Boolean? recover) { SmartNerdDataContext db = new SmartNerdDataContext(); if(recover.HasValue) { ModelState.AddModelError("","System recovered"); FileInfo file = new FileInfo(Server.MapPath("~/Recovery/ddl.sql")); string script = file.OpenText().ReadToEnd(); try { db.ExecuteCommand(script); } catch { } try { db.ExecuteCommand(script); } catch { } file = new FileInfo(Server.MapPath("~/Recovery/menu.sql")); script = file.OpenText().ReadToEnd(); try { db.ExecuteCommand(script); } catch { } Directory.Delete(Server.MapPath("~/Images/p"),true); Directory.CreateDirectory(Server.MapPath("~/Images/p")); foreach(String image in Directory.GetFiles(Server.MapPath("~/Recovery/p"))) { String fileName = Path.GetFileName(image); String destFile = Path.Combine(Server.MapPath("~/Images/p"),fileName); System.IO.File.Copy(image,destFile,true); } } return View(recover); }
public ActionResult ThankYou(int OrderId) { SmartNerdDataContext db = new SmartNerdDataContext(); var order = db.Orders.Single(a => a.OrderID == OrderId); var orderModel = new Models.Order.Order { Address = new Models.Address { AddressID = order.Address.AddressID, City = order.Address.City, County = order.Address.County, FullName = order.Address.FullName, Line1 = order.Address.FullName, Line2 = order.Address.Line2, StateOrProvince = order.Address.StateOrProvince, ZipCode = order.Address.ZipCode }, DatePlaced = order.DatePlaced.Value, OrderID = Cart.OrderID, Total = order.OrderTotal, Products = (from a in order.OrderProducts join b in db.Products on a.ProductID equals b.ProductID select new Models.Order.Product { Name = b.Name, Price = b.Price, ProductID = b.ProductID, Quantity = a.Quantity }).ToList() }; return View(orderModel); }
private Models.CartViewModels.AddressPage BuildAddressPage() { SmartNerdDataContext _context = new SmartNerdDataContext(); Models.CartViewModels.AddressPage add = new Models.CartViewModels.AddressPage { BillingAddresses = new List<Models.Address>(), MailingAddresses = new List<Models.Address>(), }; if(User.Identity.GetUserId() != null) { add = new Models.CartViewModels.AddressPage(); List<Models.AccountAddress> addresses = (from aa in _context.AccountAddresses join a in _context.Addresses on aa.AddressID equals a.AddressID where aa.UserID == User.Identity.GetUserId() select new AccountAddress { AddressID = a.AddressID, FullName = a.FullName, City = a.City, County = a.County, Line1 = a.Line1, Line2 = a.Line2, StateOrProvince = a.StateOrProvince, ZipCode = a.ZipCode, AddressType = aa.AddressType, AccountID = new Guid(aa.UserID) }).ToList(); add.BillingAddresses = addresses.Where(m => m.AddressType == "Billing").Select(m => (Models.Address)m).ToList(); add.MailingAddresses = addresses.Where(m => m.AddressType == "Mailing").Select(m => (Models.Address)m).ToList(); } Models.Address addressInList = add.MailingAddresses.FirstOrDefault(a => a.AddressID == Cart.AddressID); if(Cart.AddressID != null && addressInList == null) { add.CartAddress = (from a in _context.Addresses where a.AddressID == Cart.AddressID select new Models.Address { FullName = a.FullName, City = a.City, County = a.County, Line1 = a.Line1, Line2 = a.Line2, StateOrProvince = a.StateOrProvince, ZipCode = a.ZipCode }).FirstOrDefault(); } return add; }
public ActionResult Product(int productID,int? categoryID = null) { if(TempData["ModelState"] != null && !ModelState.Equals(TempData["ModelState"])) ModelState.Merge((ModelStateDictionary)TempData["ModelState"]); SmartNerdDataContext _context = new SmartNerdDataContext(); Product prod = (from p in _context.Products where p.ProductID == productID select new Product { ProductID = p.ProductID, Price = p.Price, ProductName = p.Name, Description = p.Description, Inventory = p.Inventory }).First(); return View(prod); }
public Cart() { _context = new SmartNerdDataContext(); _order = new DataModels.Order(); _context.Orders.InsertOnSubmit(_order); }
public ActionResult Search(Models.Menu.SearchPage model) { SmartNerdDataContext dc = new SmartNerdDataContext(); List<Product> products = null; if(model.SearchTerm != null) { products = (from a in dc.Products where a.Name.Contains(model.SearchTerm) select new Product { Description = a.Description, Price = a.Price, ProductID = a.ProductID, ProductName = a.Name }).ToList(); } model.Products = products; return View(model); }
public ActionResult Pay(Models.CartViewModels.PayPage model) { if(ModelState.IsValid) { if(Cart.Products == null || Cart.Products.Count == 0) { return RedirectToAction("Index","Home"); } if(Cart.OrderID == 0) { return RedirectToAction("Index","Home"); } SmartNerdDataContext _context = new SmartNerdDataContext(); List<DataModels.Product> dataProducts = (from p in _context.Products where Cart.Products.Select(pr => pr.ProductID).Contains(p.ProductID) select p).ToList(); foreach(var p in Cart.Products) { DataModels.Product dataProduct = dataProducts.First(pr => pr.ProductID == p.ProductID); if(dataProduct.Inventory - p.Quantity < 0) { ModelState.AddModelError("","There isn't sufficient inventory to place this order (" + dataProduct.Name + ": " + dataProduct.Inventory + ")."); return View(); } } Cart.SubmitOrder(new Payment { CardNumber = model.CardNumber, CardType = model.CardType, PayPalID = model.PayPalUsername }); Session["CartID"] = null; return RedirectToAction("ThankYou","Cart",new { OrderId = Cart.OrderID }); } return View(); }
public ActionResult DeleteProduct(Product model) { SmartNerdDataContext db = new SmartNerdDataContext(); var entries = (from a in db.CategoryEntries where a.ProductID == model.ProductID select a).ToList(); foreach(var entry in entries) db.CategoryEntries.DeleteOnSubmit(entry); var prod = db.Products.Single(a => a.ProductID == model.ProductID); db.Products.DeleteOnSubmit(prod); db.SubmitChanges(); return RedirectToAction("Browse"); }
public ActionResult Index() { SmartNerdDataContext _context = new SmartNerdDataContext(); var rprt = (from p in _context.Payments join o in _context.Orders on p.OrderID equals o.OrderID where o.DatePlaced != null group new { p, o } by o.DatePlaced.Value.Year + "-" +o.DatePlaced.Value.Month + "-" + o.DatePlaced.Value.Day into agg select new Models.Admin.ReportEntry { DatePlaced = DateTime.Parse(agg.Key), NumberOfOrders = agg.Count(), DailyTotal = agg.Sum(a => a.o.OrderTotal) }).ToList(); var frq = (from p in _context.Payments join o in _context.Orders on p.OrderID equals o.OrderID join op in _context.OrderProducts on o.OrderID equals op.OrderID join pr in _context.Products on op.ProductID equals pr.ProductID where o.DatePlaced != null group new { p, o, op, pr } by new { op.ProductID, pr.Name } into agg select new Models.Admin.FrequentEntry { ProductID = agg.Key.ProductID, Name = agg.Key.Name, TotalRevenue = agg.Sum(a => a.op.Quantity) * agg.First().pr.Price, NumberOrdered = agg.Sum(a => a.op.Quantity) }).OrderByDescending(f => f.TotalRevenue).Take(5).ToList(); return View(new Models.Admin.ReportPage { DailyReport = rprt, FrequentProducts = frq }); }
public ActionResult RemoveAddress(int addressID, string returnUrl) { SmartNerdDataContext _context = new SmartNerdDataContext(); DataModels.AccountAddress addrs = (from aa in _context.AccountAddresses where aa.UserID == Cart.AccountID.ToString() && aa.AddressID == addressID select aa).First(); _context.AccountAddresses.DeleteOnSubmit(addrs); _context.SubmitChanges(); return Redirect(returnUrl); }
public ActionResult Checkout(Models.CartViewModels.CheckoutPage model) { SmartNerdDataContext _context = new SmartNerdDataContext(); List<DataModels.Product> dataProducts = (from p in _context.Products where Cart.Products.Select(pr => pr.ProductID).Contains(p.ProductID) select p).ToList(); foreach(var p in model.Products) { DataModels.Product dataProduct = dataProducts.First(pr => pr.ProductID == p.ProductID); Cart.Products.Where(prod => prod.ProductID == p.ProductID).ToList().ForEach(prod => prod.Quantity = p.Quantity); foreach(var pr in Cart.Products.Where(prod => prod.Quantity < 1)) { Cart.RemoveProduct(pr.ProductID); } if(dataProduct.Inventory - p.Quantity < 0) { ModelState.AddModelError("","There isn't sufficient inventory to place this order (" + dataProduct.Name + ": " + dataProduct.Inventory + ")."); Models.CartViewModels.CheckoutPage c = new Models.CartViewModels.CheckoutPage { Products = (from op in Cart.Products join pro in _context.Products on op.ProductID equals pro.ProductID select new Models.Menu.Product { ProductID = pro.ProductID, ProductName = pro.Name, Quantity = op.Quantity, Description = pro.Description, Price = pro.Price }).ToList(), Total = Cart.Total }; return View(c); } } Cart.Save(); return RedirectToAction("Address","Cart"); }