public void Save(string ticker, string source, bool quarterly, string description)
        {
            var factory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["StockScreenerConnection"].ConnectionString, SqlServerDialect.Provider);

            factory.Run(db => db.CreateTable <DiscountCashFlowHeader>(overwrite: false));
            factory.Run(db => db.CreateTable <DiscountCashFlowYear>(overwrite: false));

            using (IDbConnection db = factory.OpenDbConnection())
            {
                var headers = db.Select <DiscountCashFlowHeader>(h => h.Ticker == ticker && h.Source == source && h.IsQuarterly == quarterly);
                db.Delete <DiscountCashFlowHeader>(h => h.Ticker == ticker && h.Source == source && h.IsQuarterly == quarterly);

                if (null != headers)
                {
                    foreach (var h in headers)
                    {
                        db.Delete <DiscountCashFlowYear>(y => y.DiscoutCashFlowHeaderId == h.Id);
                    }
                }

                // create header
                DiscountCashFlowHeader header = new DiscountCashFlowHeader
                {
                    Ticker                 = ticker,
                    IsQuarterly            = quarterly,
                    Source                 = source,
                    Description            = description,
                    StartingFcF            = this.FreeCashFlow,
                    GrowthRate             = this.GrowthRate,
                    DiscountRate           = this.DiscountRate,
                    TerminalGrowthRate     = this.TerminalGrowthRate,
                    NetDebt                = this.NetDebt,
                    SharesOutstanding      = this.SharesOutstanding,
                    GrowthTerminalValue    = this.GrowthTerminalValue,
                    TenYearTerminalValue   = this.TenYearTerminalValue,
                    GrowthEnterpriseValue  = this.GrowthEnterpriseValue,
                    TenYearEnterpriseValue = this.TenYearEnterpriseValue
                };
                db.Insert(header);
                header.Id = (int)db.GetLastInsertId();


                // create yearly records
                foreach (int i in this.FutureFreeCashFlow.Keys)
                {
                    DiscountCashFlowYear dcfy = new DiscountCashFlowYear
                    {
                        DiscoutCashFlowHeaderId     = header.Id,
                        FutureFreeCashFlow          = this.FutureFreeCashFlow[i],
                        PresentFreeCashFlow         = this.PresentFreeCashFlow[i],
                        TerminalFreeCashFlow        = this.TerminalFreeCashFlow[i],
                        TerminalPresentFreeCashFlow = this.TerminalPresentFreeCashFlow[i]
                    };

                    db.Insert(dcfy);
                }
            }
        }
        public void Save(string ticker, string source, bool quarterly, string description)
        {
            var factory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["StockScreenerConnection"].ConnectionString, SqlServerDialect.Provider);
            factory.Run(db => db.CreateTable<DiscountCashFlowHeader>(overwrite: false));
            factory.Run(db => db.CreateTable<DiscountCashFlowYear>(overwrite: false));

            using (IDbConnection db = factory.OpenDbConnection())
            {
                var headers = db.Select<DiscountCashFlowHeader>(h => h.Ticker == ticker && h.Source == source && h.IsQuarterly == quarterly);
                db.Delete<DiscountCashFlowHeader>(h => h.Ticker == ticker && h.Source == source && h.IsQuarterly == quarterly);

                if (null != headers)
                {
                    foreach (var h in headers)
                    {
                        db.Delete<DiscountCashFlowYear>(y => y.DiscoutCashFlowHeaderId == h.Id);
                    }
                }

                // create header
                DiscountCashFlowHeader header = new DiscountCashFlowHeader
                {
                    Ticker = ticker,
                    IsQuarterly = quarterly,
                    Source = source,
                    Description = description,
                    StartingFcF = this.FreeCashFlow,
                    GrowthRate = this.GrowthRate,
                    DiscountRate = this.DiscountRate,
                    TerminalGrowthRate = this.TerminalGrowthRate,
                    NetDebt = this.NetDebt,
                    SharesOutstanding = this.SharesOutstanding,
                    GrowthTerminalValue = this.GrowthTerminalValue,
                    TenYearTerminalValue = this.TenYearTerminalValue,
                    GrowthEnterpriseValue = this.GrowthEnterpriseValue,
                    TenYearEnterpriseValue = this.TenYearEnterpriseValue
                };
                db.Insert(header);
                header.Id = (int) db.GetLastInsertId();

                // create yearly records
                foreach (int i in this.FutureFreeCashFlow.Keys)
                {
                    DiscountCashFlowYear dcfy = new DiscountCashFlowYear
                    {
                        DiscoutCashFlowHeaderId = header.Id,
                        FutureFreeCashFlow = this.FutureFreeCashFlow[i],
                        PresentFreeCashFlow = this.PresentFreeCashFlow[i],
                        TerminalFreeCashFlow = this.TerminalFreeCashFlow[i],
                        TerminalPresentFreeCashFlow = this.TerminalPresentFreeCashFlow[i]
                    };

                    db.Insert(dcfy);
                }
            }
        }