public T Insert(T entity)
        {
            try
            {
                _databaseContext.Add(entity);
                _databaseContext.SaveChanges();

                return(entity);
            }
            catch (Exception ex)
            {
                _logger.LogError("Error while inserting entity.", ex);
                throw;
            }
        }
Example #2
0
        public T Insert(T entity, bool createEvent = true)
        {
            try
            {
                _databaseContext.Add(entity);
                _databaseContext.SaveChanges();
                if (createEvent)
                {
                    _logger.LogDebug("Publish insert event for " + entity.Id);
                    _messageBroker.Publish(InsertQueue, new EntityInsertEvent <TEvent>()
                    {
                        EmmitedServerId = _serverDescriptor.Id,
                        Entity          = CreateEventModel(entity)
                    });
                }

                return(entity);
            }
            catch (Exception ex)
            {
                _logger.LogError("Error while inserting entity.", ex);
                throw;
            }
        }