private Occurance BuildOccerence(LoggedErrorDTO error)
 {
     return(new Occurance {
         StackTrace = error.StackTrace,
         Time = error.Time
     });
 }
        private ExceptionLog BuildExceptionLog(LoggedErrorDTO error)
        {
            var message = db.Messages.FirstOrDefault(m => m.Text == error.Message);

            if (message == null)
            {
                message = new Message {
                    Text = error.Message
                }
            }
            ;

            var helpLink = db.HelpLinks.FirstOrDefault(hl => hl.Link == error.HelpLink);

            if (helpLink == null && error.HelpLink != null)
            {
                helpLink = new HelpLink {
                    Link = error.HelpLink
                }
            }
            ;

            var source = db.Sources.FirstOrDefault(s => s.Application == error.Source);

            if (source == null && error.Source != null)
            {
                source = new Source {
                    Application = error.Source
                }
            }
            ;

            //var data = db.Data.Where(d => d.DataEntries.)

            var exceptionType = db.ExceptionTypes.FirstOrDefault(e => e.Name == error.ExceptionType);

            if (exceptionType == null)
            {
                exceptionType = new ExceptionType {
                    Name = error.ExceptionType
                }
            }
            ;

            var loggedException = new ExceptionLog();

            loggedException.Message       = message;
            loggedException.HelpLink      = helpLink;
            loggedException.Source        = source;
            loggedException.ExceptionType = exceptionType;
            return(loggedException);
        }
    }
}
        public void LogError(LoggedErrorDTO error)
        {
            var loggedException = BuildExceptionLog(error);
            var occurance       = BuildOccerence(error);

            occurance.ExceptionLog = loggedException;
            occurance.SessionId    = error.SessionId;

            db.Occurances.Add(occurance);

            try {
                db.SaveChanges();
            } catch (Exception e) {
                throw e;
            }
        }