Guys,
I have a conceptual question.- I have a Class named ClientDAL that inserts an object on the DataBase (Im using LINQ2SQL).- But before insertinng that class checks that it is not already on the database (check if it exists already on the DB) so I have a try and a if incrementing the ciclomatic complexity.-
My question is, ClientDAL should only handle insertions and the logic to check if already exists somewhere else? This is the code:
public OperationStatus addClient(Client c)
{
try
{
if (!sqlAccess.sqlContext.Clients.Any(x => x.clientName.Equals(c.clienteName)))
{
sqlAccess.sqlContext.Clients.InsertOnSubmit(new Client { clientName = c.clientName });
sqlAccess.sqlContext.SubmitChanges();
return OperationStatus.SUCCESS;
}
else
return OperationStatus.FAILURE;
}
catch { throw; }
}
That is the class that handles the insertion, now I call that method from a Helper Class:
public class ClientHelper
{
ClientDAL cDal;
public ClientHelper()
{
cDal = new ClientDAL();
}
public OperationStatus insertClient(Client client)
{
try
{
return cDal.addClient(client);
}
catch (Exception ex)
{
return OperationStatus.ERROR;
}
}
}
Now the question is, should I handle the validation on the ClientHelper, or perhaps create a private method on the DAL and handle it on the DAL? Create a private method on the Helper calling the DAL? What is the Best OOP solution for this "Where should I put things" problem...
Thanks in advanced :D