Static methods for Biz layer (ASP.Net)
Dear All, Actually I have done all my Biz(business layer) and DAL CRUD Opprations using static methodes and I just send my error messages to my log table
a sample of biz layer
public static bool Delete(Guid LogGroupID)
{
using (DAL.ChroXEntities db = new ChroX.DAL.ChroXEntities())
{
var q = (from lg in db.LogGroupSet
where (lg.LogGroupID == LogGroupID)
select lg).FirstOrDefault();
开发者_C百科 if (q != null)
{
try
{
db.DeleteObject(q);
db.SaveChanges();
return true;
}
catch (Exception ex)
{
GeneralClass.LogError(ex);
}
}
return false;
}
}
so what should i do to propagate an user friendly error to my users? thanks for ever, Kiarash
User friendly all depends on the context so from your biz-layer you should simply re-throw your exception
catch (Exception ex)
{
GeneralClass.LogError(ex);
throw;
}
Then higher up in your hireachy where you're actually calling your Delete method from, you should again have a try-catch statement but here in your catch you should extract the message and write it out to the user, either as html, a ajax-popup or whatever. As i said, user friendly all depends on the context, which you haven't told us much about here.
精彩评论