public ActionResult Add(int id, [Bind("ProductName,Description,Price,OrderLimit,Quantity")] ProductViewModel productVM, IFormCollection collection) { // get the current id from tempdata to ensure the user hasn't modified the id that the page put out int tdId = (int)TempData.Peek("Location"); if (tdId != id) { // *ER add error message return(RedirectToAction(nameof(Index))); } // check modelstate if (!ModelState.IsValid) { return(View(productVM)); } try { // check to see if product with name exists if (_productRepository.Exists(productVM.ProductName)) { // is an existing product in the database, update it (should i do this here? This is going to update for all stores) Product product = new Product(productVM.ProductName, 1, productVM.Price, productVM.Description, productVM.OrderLimit); _productRepository.UpdateProduct(product); _locationRepository.AddInventory(product.Name, id, productVM.Quantity); } else { // is a new product Product product = new Product(productVM.ProductName, 1, productVM.Price, productVM.Description, productVM.OrderLimit); _productRepository.Add(product); _locationRepository.AddInventory(product.Name, id, productVM.Quantity); } return(RedirectToAction(nameof(Details), new { id })); } catch { return(View(productVM)); } }