// GET: Cart public ActionResult Index() { CartModel model = new CartModel(); if (User.Identity.IsAuthenticated) { int orderId = int.Parse(Request.Cookies["OrderId"].Value); using (WebStoreDatabaseEntities e = new WebStoreDatabaseEntities()) { var cart = e.OrderHeaders.Single(x => x.OrderId == orderId); model.Products = cart.OrderDetails.Select(x => new ProductModel { Name = x.Product.ProductName, Price = x.Product.Price, Quantity = x.OrderOty, ID = x.ProductId, LineTotal = (x.Product.Price * x.OrderOty) }).ToArray(); model.Subtotal = model.Products.Sum(x => x.LineTotal); } } else { return(RedirectToAction("Login", "Account")); } return(View(model)); }
public ActionResult Index(ProductModel model) { // TODO: Add product to cart in database. using (WebStoreDatabaseEntities e = new WebStoreDatabaseEntities()) { //create line item OrderDetail detail = new OrderDetail(); detail.OrderOty = model.Quantity; detail.ProductId = model.ID; OrderHeader header = new OrderHeader(); header.OrderDate = DateTime.UtcNow; //(ternary expression) Are there order headers? if yes, then do the thing, else = 1. header.OrderId = e.OrderHeaders.Any() ? e.OrderHeaders.Max(x => x.OrderId) + 1 : 1; detail.OrderId = header.OrderId; //Adds detail to order details header.OrderDetails.Add(detail); //TODO: Make sure people are registered and use THEIR customer ID. header.CustomerId = e.Customers.First().CustomerId; header.SubTotal = model.Price * model.Quantity; detail.LineTotal = header.SubTotal; e.OrderHeaders.Add(header); e.SaveChanges(); } return(RedirectToAction("Index", "Cart")); }
public ActionResult Index() { AccountDetailsModel model = new AccountDetailsModel(); using (WebStoreDatabaseEntities e = new WebStoreDatabaseEntities()) { var user = e.Customers.Single(x => x.Email == User.Identity.Name); //connect db with model model.FirstName = user.FirstName; model.LastName = user.LastName; } return(View(model)); }
public ActionResult Index(AccountDetailsModel model) { if (ModelState.IsValid) { using (WebStoreDatabaseEntities e = new WebStoreDatabaseEntities()) { var user = e.Customers.Single(x => x.Email == User.Identity.Name); //connects model to db user.FirstName = model.FirstName; user.LastName = model.LastName; } } return(View(model)); }
public ActionResult Index() { ProductModel[] model = { }; using (WebStoreDatabaseEntities e = new WebStoreDatabaseEntities()) { model = e.Products.Where(x => x.Featured == 1).Select(x => new ProductModel { ID = x.ProductId, Name = x.ProductName, Image = x.Image, Price = x.Price }).ToArray(); } return(View(model)); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { if (WebMatrix.WebData.WebSecurity.Login(model.Email, model.Password, true)) { //gets CustID based on email and issues persistant auth cookie using (WebStoreDatabaseEntities e = new WebStoreDatabaseEntities()) { var user = e.Customers.Single(x => x.Email == model.Email); FormsAuthentication.SetAuthCookie(user.CustomerId.ToString(), true); } } return(RedirectToAction("Index", "Home")); } return(View(model)); }
public ActionResult Index(ProductModel model) { //TODO: new entity (using), create line item, create the header, add new line item to header, using (WebStoreDatabaseEntities e = new WebStoreDatabaseEntities()) { //save cart as cookie so we can use this order on the checkout page Response.Cookies.Add(new HttpCookie("orderId", 1.ToString()) { Expires = DateTime.Now.AddMinutes(15) }); // TODO: finish creating line item, etc... //model.ID = e.OrderDetails. e.SaveChanges(); } return(RedirectToAction("Index", "Checkout")); }
// GET: Checkout public ActionResult Index() { CheckoutModel model = new CheckoutModel(); // TODO: check this order id = cust's order id int orderId = int.Parse(Request.Cookies["OrderId"].Value); using (WebStoreDatabaseEntities e = new WebStoreDatabaseEntities()) { var cart = e.OrderHeaders.Single(x => x.OrderId == orderId); //gets shipping method for display model.ShippingList = e.Shippings.Select(x => x.Method).ToList(); var shipPrice = e.Shippings.Single(x => x.Method == model.ShippingMethod).Price; model.TotalDue = cart.SubTotal + shipPrice; // TODO: eventually add state tax, but for now assume the ship price includes some type of tax } return(View(model)); }
// GET: ProductList public ActionResult Index() { List <ProductModel> model = null; using (WebStoreDatabaseEntities e = new WebStoreDatabaseEntities()) { //products are a db type. change them to a ProductModel using lambda expressions. model = e.Products.Select(x => new ProductModel { ID = x.ProductId, Name = x.ProductName, Description = x.Description, Image = x.Image, Price = x.Price }).ToList(); } return(View(model)); }
public ActionResult Index(CheckoutModel model) { if (ModelState.IsValid) { // TODO: if check out... using (WebStoreDatabaseEntities entities = new WebStoreDatabaseEntities()) { int orderNumber = int.Parse(Request.Cookies["OrderId"].Value); var orderHeader = entities.OrderHeaders.Single(x => x.OrderId == orderNumber); //looks at shipping table, gets method that equals model.method, then finds the ID for that method. var shipMethod = entities.Shippings.Single(x => x.Method == model.ShippingMethod).ShippingMethodId; var address = entities.Addresses.FirstOrDefault( x => x.Line1 == model.ShippingAddress1 && x.Line2 == model.ShippingAddress2 && x.City == model.ShippingCity && x.State == model.ShippingState && x.Zipcode == model.ShippingZipcode); if (address == null) { address = new Address { AddressId = entities.Addresses.Max(x => x.AddressId) + 1, Line1 = model.ShippingAddress1, Line2 = model.ShippingAddress2, City = model.ShippingCity, State = model.ShippingState, Zipcode = model.ShippingZipcode, }; entities.Addresses.Add(address); } orderHeader.ShipToAddress = address.AddressId; entities.SaveChanges(); } return(RedirectToAction("Index", "Receipt")); } else { return(View(model)); } }
// GET: Product public ActionResult Index(int?id) { ProductModel model = new ProductModel(); using (WebStoreDatabaseEntities e = new WebStoreDatabaseEntities()) { var product = e.Products.Single(x => x.ProductId == id); if (id != null) { model.Name = product.ProductName; model.Image = product.Image; model.Description = product.Description; model.Price = product.Price; model.Quantity = 1; } else { new HttpNotFoundResult("Product Not Found"); } } return(View(model)); }