Exemple #1
0
        public Response Commit()
        {
            try
            {
                return(_context.SaveChanges() > 0 ? Response.Ok : Response.Fail);
            }
            catch (DbUpdateException ex)
            {
                var decodedErrors = EfExceptionHelper.TryDecodeDbUpdateException(ex);

                if (decodedErrors == null)
                {
                    _logger.LogError($"On saving in database. {DateTime.Today}");
                    _mediatorHandler.RaiseNotification(new DomainNotification("Error", ex.Message, NotificationType.Error));
                }

                if (decodedErrors == null)
                {
                    return(Response.Fail);
                }

                foreach (var entityValidationErro in decodedErrors)
                {
                    _logger.LogError($"{entityValidationErro.ErrorMessage}. {DateTime.Today}");
                    _mediatorHandler.RaiseNotification(new DomainNotification("Error", entityValidationErro.ErrorMessage, NotificationType.Error));
                }

                return(Response.Fail);
            }
            catch (Exception ex)
            {
                _context.Dispose();
                _logger.LogError($"On saving in database. {DateTime.Today}");
                _mediatorHandler.RaiseNotification(new DomainNotification("Error", ex.Message, NotificationType.Error));

                return(Response.Fail);
            }
        }
Exemple #2
0
 public void RaiseNotification(string key, string value, NotificationType type)
 {
     _mediator.RaiseNotification(new DomainNotification(key, value, type));
 }