I work on a project with ASP.NET MVC and , my project architechture is N Layer . I have a method that name's is IsExists in all of Services. belowe I put two of them :
bool IsExists(string title,Guid? parentId, Guid? id=null); // in service 1
bool IsExists(string title, Guid? id = null);// in service n
is there a pattern to avoid repeat them ? I repeated same method by same doing work in all of services
Sample of implement :
public bool IsExists(string title, Guid? parentId, Guid? id = default(Guid?))
{
Expression<Func<AssetGroup, bool>> ex = row => row.Title == title && row.ParentId == parentId;
if (id.HasValue)
ex = row => row.Id != id.Value;
return _groups.Any(ex);
}
*-I call IsExists Method in Create and Edit Methods before saveChanges
Aucun commentaire:
Enregistrer un commentaire