public ActionResult Create(Product product) { if (ModelState.IsValid) { ProductContext.Products.Add(product); //You can implement an add method in javascript to add a new item here return RedirectToAction("Index"); } return View(product); }
public ActionResult Edit(Product product) { if (ModelState.IsValid) { //Update the record itself and let .NET do the reference work so that the collection will be updated automaticly Product productToUpdate = ProductContext.Products.Find(x => x.Id == product.Id); productToUpdate.Name = product.Name; productToUpdate.Description = product.Description; productToUpdate.Price = product.Price; //We need to let all users know about this update //First we get the Context of the catalog hub IHubContext catalogHub = GlobalHost.ConnectionManager.GetHubContext<Catalog>(); //Now we invoke an product update to all connections/clients of this hub. catalogHub.Clients.All.productUpdate(product); return RedirectToAction("Index"); } return View(product); }