public ActionResult Command(Command cmd) { if (cmd.product.qteprod < cmd.qteprod) { ModelState.AddModelError("quantity not enough", "not enough quantity in the stock"); } if (ModelState.IsValid) { //if modelstate is valid then add_command check service command for more informations IserviceCommand spc = new serviceCommand(); spc.add_commande(cmd); } return(View()); }
public ActionResult Command(Command cmd) { bool stock = false; bool error = false; bool success = false; ViewData.Clear(); if (cmd.phone2 == null) { ModelState.AddModelError("", "phone2 required"); } IserviceProduct ps = new serviceProduct(); Product p = ps.GetById(cmd.idprod); if (p.qteprod < cmd.qteprod) { ModelState.AddModelError("quantity not enough", "not enough quantity in the stock"); stock = true; return(RedirectToAction("Details/" + cmd.idprod, "Products", new { stock = stock })); } if (ModelState.IsValid) { //if modelstate is valid then add_command check service command for more informations IserviceCommand spc = new serviceCommand(); spc.add_commande(cmd); success = true; return(RedirectToAction("Details/" + cmd.idprod, "Products", new { success = success })); } else { error = true; return(RedirectToAction("Details/" + cmd.idprod, "Products", new { error = error })); } }