public IDataContent <Company> GetData() { IDataContent <Company> dataContent = new CompanyContent(); dataContent.Headers = Headers; MatchFactory factory = new MatchFactory(); NumberBase concreteNumberType = factory.MatchNumber(NumbersToCheck, Number); if (concreteNumberType != null && concreteNumberType.IsValid(Number)) { try { Number = concreteNumberType.FormatNumber(Number); ISession session = NHibernateManager.BeginSessionTransaction(); dataContent.Data = CompanyDAO.Instance.GetCompanyDataByNumber(Number, session); NHibernateManager.CloseSessionTransaction(); dataContent.Status = StatusEnum.Valid.ToString(); if (dataContent.Data == null) { dataContent.Message = "Brak danych"; dataContent.Status = StatusEnum.Error.ToString(); } } catch (Exception e) { NHibernateManager.CloseSessionTransaction(); throw new Exception(e.Message); } } else { dataContent.Message = "Podany numer jest niepoprawny"; dataContent.Status = StatusEnum.Error.ToString(); } LogManager log = new LogManager(); log.LogData(dataContent); return(dataContent); }
public void LogData <T>(IDataContent <T> data) { Log log = new Log(); log.ErrorMessage = data.Message; log.Status = data.Status; log.LogDate = DateTime.Now; log.HttpHeader = data.Headers; try { ISession session = NHibernateManager.BeginSessionTransaction(); LogDAO.Instance.Save(log, session); NHibernateManager.CommitTransactionAndClose(); } catch (Exception e) { NHibernateManager.RollBackTransaction(); throw new Exception(e.Message); } }