I am a novice programmer. I have a few single value return "gets" that return ID's that looks like this:
Controller.GetCustomerIDByCustomerName(item.Customer.ToLower().Trim(), out int CustomerID);
Controller.GetCustomerIDByCustomerName(item.FinalCustomer.ToLower().Trim(), out int FinalCustomerID);
Controller.GetHaulierIDByName(item.HaulierName.ToLower().Trim(), out int HaulierID);
Controller.GetCustomerDepotIDByName(item.DepotName.ToLower().Trim(), CustomerID, out int CustomerDepotID);
I want to check that CustomerID/ FinalCustomerID etc... have value before continuing with the code. I'm not sure what the best/ most efficient way to do this is.
What I have tried:
I have tried a method that checks on the data:
private bool ValidData()
{
bool ReturnValue = true;
if (CustomerID == null)
{
cGlobal.ShowWarningMessage("Customer Required", "Customer Required");
ReturnValue = false;
}
if (ReturnValue)
{
if (FinalCustomerID == null)
{
cGlobal.ShowWarningMessage("Final Customer Required");
ReturnValue = false;
}
}
if (ReturnValue)
{
if (HaulierID == null)
{
cGlobal.ShowWarningMessage("Haulier Required");
ReturnValue = false;
}
}
if (ReturnValue)
{
if (CustomerDepotID == null)
{
cGlobal.ShowWarningMessage("Customer Depot Required");
ReturnValue = false;
}
}
return ReturnValue;
}
and then declaring the variables at the top of the page like so:
public int? CustomerID;
public int? FinalCustomerID;
public int? HaulierID;
public int? CustomerDepotID;
However this doesn't work.
Any advice on how to do this would be appreciated.