public IActionResult Addorders(Order neworder) { List <string> temp_errors = new List <string>(); if (ModelState.IsValid) { ViewBag.price = productsFactory.Extract_Price(neworder.product_id); double price = ViewBag.price * neworder.quantity; int extracted_quantity = productsFactory.Extract_Qunatity(neworder.product_id); if (neworder.quantity > extracted_quantity) { temp_errors.Add("Only " + extracted_quantity + " left"); TempData["errors"] = temp_errors; return(RedirectToAction("Orders")); } productsFactory.AddOrder(neworder, price); productsFactory.Update_qty(neworder.product_id, neworder.quantity); return(RedirectToAction("Orders")); } foreach (var error in ModelState.Values) { if (error.Errors.Count > 0) { temp_errors.Add(error.Errors[0].ErrorMessage); } } TempData["errors"] = temp_errors; return(RedirectToAction("Orders")); }