public ActionResult Create([Bind(Include = "ID,Firstname,MiddleName,Lastname,EmailAddress,Phone,Address1,Address2,City,State,ZipCode")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create([Bind(Include = "ID,ProdName,ProdDescription,Price,ProdAttributes")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
protected override void Seed(WlBhcDB context) { //base.Seed(context); context.Products.AddRange(new Product[] { new Product { ProdName = "iPhone XR", Price = 899.99d, ProdDescription = "iPhone XR Samrt Phone", ProdAttributes = "Gold, 64GB" }, new Product { ProdName = "iPhone Xs", Price = 1099.99d, ProdDescription = "iPhone XS Samrt Phone", ProdAttributes = "Silver, 128GB" }, new Product { ProdName = "iPhoneX", Price = 799.99d, ProdDescription = "iPhone XS Samrt Phone", ProdAttributes = "Silver, 32GB" }, new Product { ProdName = "Samsung Galaxy 8", Price = 999.99d, ProdDescription = "Samsung Galaxy 8 Smart Phone", ProdAttributes = "Sky Blue, 128GB" }, new Product { ProdName = "Samsung Note 7", Price = 999.99d, ProdDescription = "Samsung Note 7 Smart Phone", ProdAttributes = "Red, 64GB" }, new Product { ProdName = "Google Pixel 3XL", Price = 899.99d, ProdDescription = "Google Pixel 3XL Smart Phone", ProdAttributes = "Black, 128GB" }, new Product { ProdName = "Google Pixel 3A", Price = 799.99d, ProdDescription = "Google Pixel 3A Smart Phone", ProdAttributes = "Pink, 128GB" }, new Product { ProdName = "Kinston SD Card", Price = 19.99d, ProdDescription = "Kinston SD Memory Card", ProdAttributes = "Regualr, 32GB" }, new Product { ProdName = "Boss HeadPhone", Price = 219.99d, ProdDescription = "Boss Wireless HeadPhone", ProdAttributes = "Silver" } });; context.SaveChanges(); }
public ActionResult Create([Bind(Include = "ProductID,Quantity,OrderPrice")] Order order, [Bind(Include = "Firstname,MiddleName,Lastname,EmailAddress,Phone,Address1,Address2,City,State,ZipCode")] Customer customer, int ProductID, double OrderPrice) { if (TryValidateModel(customer) && TryValidateModel(order)) { order.ProductID = ProductID; var pd = db.Products.Where(p => p.ID == ProductID).FirstOrDefault(); db.Customers.Add(customer); db.SaveChanges(); order.CustomerID = customer.ID; order.OrderedDate = DateTime.Now; //if (pd != null) order.OrderPrice = OrderPrice; db.Order.Add(order); db.SaveChanges(); return(RedirectToAction($"Details/{order.ID}")); } return(RedirectToAction("Create")); }