/// <summary>
        /// Saves all pending changes
        /// </summary>
        /// <returns>The number of objects in an Added, Modified, or Deleted state</returns>
        public async Task <IEntityResult> SaveAsync(string requestId, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                _logger.LogInformation(_localizer[RepositoryResource.StartSaveDate], requestId);
                int returnValue;
                returnValue = await _dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

                if (returnValue >= 0)
                {
                    _logger.LogInformation(_localizer[RepositoryResource.SaveDataSuccess], requestId);
                    return(EntitySuccessResult.Success(returnValue));
                }
                else
                {
                    _logger.LogInformation(_localizer[RepositoryResource.SaveChangesFailure], requestId);
                    return(EntityErrorResult.Failure(EntityError.DbUpdateFailure));
                }
            }
            catch (DbUpdateConcurrencyException ex)
            {
                _logger.LogError(
                    new EventId(EntityError.ConcurrencyFailure.Code, EntityError.ConcurrencyFailure.Error), ex,
                    _localizer[RepositoryResource.ConcurrencyFailure], requestId);
                return(EntityErrorResult.Failure(EntityError.DbUpdateFailure));
            }
            catch (DbUpdateException ex)
            {
                _logger.LogError(
                    new EventId(EntityError.DbUpdateFailure.Code, EntityError.DbUpdateFailure.Error), ex,
                    _localizer[RepositoryResource.SaveDataFailure], requestId);
                return(EntityErrorResult.Failure(EntityError.DbUpdateFailure));
            }
            catch (Exception ex)
            {
                _logger.LogError(
                    new EventId(EntityError.DbUpdateFailure.Code, EntityError.DbUpdateFailure.Error), ex,
                    _localizer[RepositoryResource.SaveDataFailure], requestId);
                return(EntityErrorResult.Failure(EntityError.UnknownFailure));
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Saves all pending changes
 /// </summary>
 /// <returns>The number of objects in an Added, Modified, or Deleted state</returns>
 public IEntityResult Save(string requestId)
 {
     try
     {
         _logger.LogInformation(_localizer[RepositoryResource.StartSaveDate], requestId);
         int returnValue;
         returnValue = _dbContext.SaveChanges();
         if (returnValue >= 0)
         {
             _logger.LogInformation(_localizer[RepositoryResource.SaveDataSuccess], requestId);
             return(EntitySuccessResult.Success(returnValue));
         }
         else
         {
             _logger.LogInformation(_localizer[RepositoryResource.SaveChangesFailure], requestId);
             return(EntityErrorResult.Failure(EntityError.DbUpdateFailure));
         }
     }
     catch (DbUpdateConcurrencyException ex)
     {
         _logger.LogError(
             new EventId(EntityError.ConcurrencyFailure.Code, EntityError.ConcurrencyFailure.Error), ex,
             _localizer[RepositoryResource.ConcurrencyFailure], requestId);
         return(EntityErrorResult.Failure(EntityError.DbUpdateFailure));
     }
     catch (DbUpdateException ex)
     {
         _logger.LogError(
             new EventId(EntityError.DbUpdateFailure.Code, EntityError.DbUpdateFailure.Error), ex,
             _localizer[RepositoryResource.SaveDataFailure], requestId);
         return(EntityErrorResult.Failure(EntityError.DbUpdateFailure));
     }
     catch (Exception ex)
     {
         _logger.LogError(
             new EventId(EntityError.DbUpdateFailure.Code, EntityError.DbUpdateFailure.Error), ex,
             _localizer[RepositoryResource.SaveDataFailure], requestId);
         return(EntityErrorResult.Failure(EntityError.UnknownFailure));
     }
 }