public ActionResult Unit2Project() { // ViewBag.ProductList = Products; ProductContext p = new ProductContext(); return(View(p.GetAll())); }
//private List<Product> Products = new List<Product>() //{ // new Product {id = "100", Name = "Jeans", Price = 59.99}, // new Product {id = "101", Name = "Polo", Price = 49.99} //}; public ActionResult DisplayProduct() { //ViewBag.ProductList = Products; ProductContext p = new ProductContext(); var products = p.GetAll(); return(View(products)); }
public ActionResult OrderForm(FormCollection form) // string fN, string lN, string shipAddr { // from Models/Customer class - using FormData.Models; customers.Add(new Customer(form["fName"], form["lName"], form["shipAdd"])); var context = order.GetAll(); formModel.Add(customers); formModel.Add(context); return(View(formModel)); // orders }
public ActionResult ProcessOrder(FormCollection form) { ViewBag.Name = form["name"]; ViewBag.Address = form["address"]; ViewBag.City = form["city"]; ViewBag.State = form["state"]; ViewBag.Zip = form["zip"]; List <Northwind.Models.Order> orders = new List <Northwind.Models.Order>(); /* loop instead of the GetAll method * Int16 qty; * foreach (var key in form.AllKeys) * { * if (Int16.TryParse(form[key], out qty) && qty > 0) * { * orders.Add(new Order { Prod = p, Qty = qty }); * }; * } */ // initial method to get all products ProductContext productContext = new ProductContext(); List <Northwind.Models.Product> products = productContext.GetAll(); Int16 qty; //ProductContext productContext = new ProductContext(); foreach (var p in products) { //form[key] if (Int16.TryParse(form[p.ProductId], out qty) && qty > 0) { // var p = productContext.Find(key); orders.Add(new Northwind.Models.Order { Prod = p, Qty = qty }); } } Person person = new Person { name = form["name"], address = form["address"], city = form["city"], state = form["state"], zip = form["zip"] }; return(View(orders)); }
public ActionResult ProcessOrder(FormCollection form) { List <Models.Order> orders = new List <Models.Order>(); //we have acces to the form //better than form[p.Id] Int16 qty; /*ProductContext productContext = new ProductContext(); * List<Product> products = productContext.GetAll(); * * * * foreach (var key in form.AllKeys) * { * //not all * //if 0 * if (Int16.TryParse(form[key], out qty) && qty > 0) * { * //orders.Add(new Order { ProductKey = key, Qty = qty }); * var p = productContext.Find(key); * orders.Add(new Order { Prod = p, Qty = qty }); * } * }*/ //it's the dependant on a class ProductContext productContext = new ProductContext(); List <Models.Product> products = productContext.GetAll(); foreach (var p in products) { if (Int16.TryParse(form[p.Id], out qty) && qty > 0) { orders.Add(new Models.Order { Prod = p, Qty = qty }); } //int qty = Convert.ToInt16(form[p.Id]); //orders.Add(new Order { Prod = p, Qty = qty }); } return(View(orders)); }
public async Task <IViewComponentResult> InvokeAsync(string sorting) { try { var products = _productContext.GetAll(); var model = new ProductComponentModel() { Products = products.Take(10).ToList() }; if (sorting == "toprated") { model.Products = products.OrderBy(c => c.Sold); model.WidgetTitle = "Top Rated Products"; } else if (sorting == "popular") { model.Products = products.OrderBy(c => c.Views); model.WidgetTitle = "Propular Products"; } else if (sorting == "featured") { model.Products = products.Where(c => c.Featured); model.WidgetTitle = "Featured Products"; } else if (sorting == "sale") { model.Products = products.Where(c => c.DiscountPercentage > 0); model.WidgetTitle = "Products On Sale"; } else if (sorting == "new") { model.Products = products.Where(c => c.Created > DateTime.Now.AddMonths(2)); model.WidgetTitle = "New Arrivals"; } return(View(model)); } catch (Exception e) { Console.WriteLine(e); throw; } }
public ActionResult DisplayProducts() { //ViewBag.ProductList = Products; //pass in model to view //this is bad and hard to test because it's instantiating in the method //it's the dependent on a class ProductContext p = new ProductContext(); //DatebaseContext db = GetAllDataById(id); //var products = p.GetAll(); //return View(p.GetAll()); var products = p.GetAll(); return(View(products)); }
public ActionResult Products(string id) { ProductContext p = new ProductContext(); //List<Product> products = new List<Product>(); if (string.IsNullOrEmpty(id)) { //products = p.GetAll(); return(View(p.GetAll())); } //return View(p.GetAll().Where(x => x.CatId == id)); //return View(p.Find(id)); return(View(p.FindBy(id))); //return View(products); }
public ActionResult ProcessOrder(FormCollection form) { List <Order> orders = new List <Order>(); ProductContext productContext = new ProductContext(); List <Product> products = productContext.GetAll(); Int16 qty; foreach (var p in products) { if (Int16.TryParse(form[p.id], out qty) && qty > 0) { orders.Add(new Order { Prod = p, Qty = qty }); } } return(View(orders)); }
public ActionResult ProcessOrder(FormCollection form) { customers.Add(new Customer(HttpContext.Request.Form["id_fName"], HttpContext.Request.Form["id_lName"], HttpContext.Request.Form["id_address"])); ProductContext productContext = new ProductContext(); List <Product> products = productContext.GetAll(); Int16 qty = 0; foreach (var p in products) { if (Int16.TryParse(form[p.Id], out qty) && qty > 0) { orders.Add(new Order { Prod = p, Qty = qty }); } } formModel.Add(customers); formModel.Add(orders); return(View(formModel)); }
public List <ProductModel> GetAll() { return(_productContext.GetAll()); }
public ActionResult Unit2Project() { ProductContext productContext = new ProductContext(); return(View(productContext.GetAll())); }