Can this be considered Clean Code / Best Practice?
Posted
by MRFerocius
on Stack Overflow
See other posts from Stack Overflow
or by MRFerocius
Published on 2010-04-06T19:22:37Z
Indexed on
2010/04/06
19:33 UTC
Read the original article
Hit count: 501
Guys, How are you doing today?
I have the following question because I will follow this strategy for all my helpers (to deal with the DB entities)
Is this considered a good practice or is it going to be unmaintainable later?
public class HelperArea : AbstractHelper
{
event OperationPerformed<Area> OnAreaInserting;
event OperationPerformed<Area> OnAreaInserted;
event OperationPerformed<Area> OnExceptionOccured;
public void Insert(Area element)
{
try
{
if (OnAreaInserting != null)
OnAreaInserting(element);
DBase.Context.Areas.InsertOnSubmit(new AtlasWFM_Mapping.Mapping.Area
{
areaDescripcion = element.Description,
areaNegocioID = element.BusinessID,
areaGUID = Guid.NewGuid(),
areaEstado = element.Status,
});
DBase.Context.SubmitChanges();
if (OnAreaInserted != null)
OnAreaInserted(element);
}
catch (Exception ex)
{
LogManager.ChangeStrategy(LogginStrategies.EVENT_VIEWER);
LogManager.LogError(new LogInformation { logErrorType = ErrorType.CRITICAL, logException = ex, logMensaje = "Error inserting Area" });
if (OnExceptionOccured != null)
OnExceptionOccured(elemento);
}
}
I want to know if it is a good way to handle the event on the Exception to let subscribers know that there has been an exception inserting that Area. And the way to log the Exception, is is OK to do it this way?
Any suggestion to make it better?
© Stack Overflow or respective owner