private EntityServiceResult <TEntity> RunWithValidation(TEntity entity, Func <TEntity> func) { var result = new EntityServiceResult <TEntity>(); result.Success = false; if (Validate(entity)) { result = EntityServiceResult <TEntity> .Run(func); if (result.Exception != null) { ModelState.AddError("Exception", result.Exception.ToString()); } } return(result); }
private EntityServiceResult <TEntity> RunWithValidation(EntityModel <TEntity> model, TEntity entity, Func <TEntity, TEntity> func) { var result = new EntityServiceResult <TEntity>(); result.Success = false; try { if (entity == null) { //model -> to entity entity = model.ModelToEntity <TEntity>(); } else { //model -> to entity entity = model.ModelToEntity <TEntity>(entity); } //validate if (Validate(entity)) { result = EntityServiceResult <TEntity> .Run(() => { return(func(entity)); }); if (result.Exception != null) { ModelState.AddError("Exception", result.Exception.ToString()); } } } catch (Exception ex) { ModelState.AddError("Exception", ex.ToString()); result.Exception = ex; } return(result); }