public IEnumerable<Product> AllProducts() { using (var db2 = new AfricanCraftsContext()) { var products = (from b in db2.Product orderby b.Name select b).ToList(); return products; //yield return new Product(); } }
// // GET: /Product/ public ActionResult Index() { ViewBag.SyncOrAsync = "Synchronous"; List<Product> productList = new List<Product>(); using (var db = new AfricanCraftsContext()) { // Display all Blogs from the database var products = from b in db.Product orderby b.Name select b; productList.AddRange(products); } return View(productList); }
public ActionResult Create(Product productCol) { try { using (var db = new AfricanCraftsContext()) { var product = new Product { Name = productCol.Name, Description = productCol.Description, UserName = User.Identity.Name }; db.Product.Add(product); db.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }