public T InsertOpt(T item, bool saveImmediately = true)
        {
            try
            {
                item = _repository.Insert(item, saveImmediately);

                if (_historyWriter != null)
                {
                    _historyWriter.Write(item, _user.Id, Globals.HistoryActions.Create, null, "Created");
                }
            }
            catch (DbEntityValidationException ex)
            {
                var sb = new StringBuilder();
                foreach (var failure in ex.EntityValidationErrors)
                {
                    sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType());
                    foreach (var error in failure.ValidationErrors)
                    {
                        sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                        sb.AppendLine();
                    }
                }

                throw new Exception(sb.ToString());
            }
            catch (Exception ex)
            {
                if (_appServices.HandleException(ex, ExceptionCategory.Data))
                {
                    throw;
                }
            }
            return(item);
        }
        public void Record(string phrase)
        {
            var historyItem = new HistoryItem()
            {
                Phrase     = phrase,
                OccurredAt = _dateTimeProvider.UtcNow()
            };

            _writer.Write(historyItem);
        }