This is my Business Layer Code public void UpdateRecords() {
int resultCountries = 0
int resultState = 0
int resultDistrict = 0
int resultCity = 0
DataTable dt = dataAccess.GetRecords();
foreach(DataRow dr in dt.Rows)
{
int PersonId = Convert.ToInt32(dr["PersonId"].ToString());
resultCountries = dataAccess.UpdateCountries(PersonId);
if(resultCountries > 0)
{
dataAccess.UpdateMessage(personId,"Country Updated Successfully");
resultState = UpdateState(personId);
if(resultState > 0)
{
dataAccess.UpdateMessage(personId,"State Updated Successfully");
resultDistrict = UpdateDistrict(personId);
if(resultDistrict > 0)
{
dataAccess.UpdateMessage(personId,"District Updated Successfully");
resultCity = UpdateCity(personId);
if(resutlCity > 0)
{
dataAccess.UpdateMessage(personId,"City Updated Successfully");
continue;
}
else if(resutlCity == 0)
{
dataAccess.UpdateMessage(personId,"City Not Updated Successfully");
continue;
}
else
{
dataAccess.UpdateMessage(personId,"Some error occured while updating city...");
continue;
}
}
else if(resultDistrict == 0)
{
dataAccess.UpdateMessage(personId,"District not Updated Successfully");
continue;
}
else
{
dataAccess.UpdateMessage(personId,"Some error occured while updating district..");
continue;
}
}
else if(resultState == 0)
{
dataAccess.UpdateMessage(personId,"State not Updated Successfully");
continue;
}
else
{
dataAccess.UpdateMessage(personId,"Some error occured while updating state..");
continue;
}
}
else if(resultCountries == 0)
{
dataAccess.UpdateMessage(personId,"Country not Updated Successfully");
continue;
}
else
{
dataAccess.UpdateMessage(personId,"Some error occured");
continue;
}
}
}
From business Layer I am calling data access layer methods,UpdateCountries,UpdateState,UpdateDistrict,UpdateCity which are updating country, state,district,city against personId in person table.
If country update is successful,state is updated otherwise log the error in db and update next record. Same is done for state,district,city. But here there are lots of if else used,kindly let me know how to replace if else in code. Do not want to use switch case or ternary operator,also not allowed to use stored procedure. The dataaccess layer methods return integer value of 1 if update is successfull,0 if condition is not satisfied,-1 if error.
Aucun commentaire:
Enregistrer un commentaire