Beispiel #1
0
 public virtual HandlerResult <List <TEntity> > Execute()
 {
     try
     {
         logger.LogDebug($"Get all {typeof(TEntity).Name}");
         var result = repository.GetAll().ToList();
         return(HandlerResultFactory.GetSuccessResult(result));
     }
     catch (Exception ex)
     {
         logger.LogError(ex, $"{typeof(TEntity).Name}");
         return(HandlerResultFactory.GetFailResult <List <TEntity> >(ex));
     }
 }
Beispiel #2
0
 public virtual HandlerResult <TEntity> Execute(int id)
 {
     try
     {
         logger.LogDebug($"Get {typeof(TEntity).Name} {id}");
         var result = repository.Get(id);
         return(HandlerResultFactory.GetSuccessResult(result));
     }
     catch (Exception ex)
     {
         logger.LogError(ex, $"{typeof(TEntity).Name}");
         return(HandlerResultFactory.GetFailResult <TEntity>(ex));
     }
 }
Beispiel #3
0
 public virtual HandlerResult Execute(TEntity entity)
 {
     try
     {
         logger.LogDebug($"Add {typeof(TEntity).Name}: {entity}");
         repository.Add(entity);
         repository.SaveChanges();
         return(HandlerResultFactory.GetSuccessResult());
     }
     catch (Exception ex)
     {
         logger.LogError(ex, $"{typeof(TEntity).Name}");
         return(HandlerResultFactory.GetFailResult(ex.Message));
     }
 }
Beispiel #4
0
 public virtual HandlerResult Execute(int id)
 {
     try
     {
         logger.LogDebug($"Remove {typeof(TEntity).Name} {id}");
         repository.Remove(id);
         repository.SaveChanges();
         return(HandlerResultFactory.GetSuccessResult());
     }
     catch (Exception ex)
     {
         logger.LogError(ex, $"{typeof(TEntity).Name}");
         return(HandlerResultFactory.GetFailResult(ex.Message));
     }
 }