I am using if
else
statements:
public ActionResult Process(int? inventoryCheck, int? POCheck, int? PromotionCheck)
{
//var result = db.ValidInventory(2);
//1. When inventory is low:
if (inventoryCheck != null && POCheck == null && PromotionCheck == null)
{
db.ValidInventory(inventoryCheck);
}
//2. When PO is not generated
else if (POCheck != null && inventoryCheck == null && PromotionCheck == null)
{
db.ValidInventory(POCheck);
}
//3. For Promotion
else if (POCheck == null && inventoryCheck == null && PromotionCheck != null)
{
db.ValidInventory(PromotionCheck);
}
else if (inventoryCheck != null && POCheck != null && PromotionCheck == null)
{
//4. When Inventory is low and PO is not generated
inventoryCheck = 4;
db.ValidInventory(inventoryCheck);
}
else if (inventoryCheck != null && POCheck == null && PromotionCheck != null)
{
//5.When inventory is low and Promotion Check
inventoryCheck = 5;
db.ValidInventory(inventoryCheck);
}
else if (inventoryCheck == null && POCheck != null && PromotionCheck != null)
{
//6. When PO is not generated and Promotion Check
inventoryCheck = 6;
db.ValidInventory(inventoryCheck);
}
else if (inventoryCheck != null && POCheck != null && PromotionCheck != null)
{
//7. When PO is not generated and Promotion Check and inventory is low
inventoryCheck = 6;
db.ValidInventory(inventoryCheck);
}
return RedirectToAction("BackAnalysis");
}
Here more conditions are present, then I have to add more if
else
blocks.
How can I optimize it?
db.ValidInventory()
method? \$\endgroup\$