// parse data values to correct table prior saving
        private void ParseDataHelper(vinsuree_data_all data)
        {
            try
            {
                // car_main
                _car.car_year  = data.car_year.GetValueOrDefault();
                _car.car_make  = data.car_make;
                _car.car_model = data.car_model;

                // insuree_main
                _main.first_name  = data.first_name;
                _main.last_name   = data.last_name;
                _main.create_date = DateTime.Now;

                // insuree_info
                _info.email = data.email;
                _info.dob   = data.dob.GetValueOrDefault();
                _info.state = ext.ValidateParseStateCode(data.state); // validate
                _info.zip   = data.zip.GetValueOrDefault();

                // insuree_hist
                _hist.dui = data.dui;
                // TO DO _hist.tickets = data.tickets.GetValueOrDefault();

                // insuree_quote
                _quote.coverage_type = data.coverage_type;
                _quote.curr_quote    = data.curr_quote = ext.CalcQuote(data);
                // WIP _quote.prev_quote = data.prev_quote;
            }
            catch (Exception ex) { throw new Exception(ex.Message); }
        }
        public bool DataUpdate(db_insuranceEntities_ db, [Bind(Exclude = "insuree_key")] vinsuree_data_all data, int key)
        {
            bool res = false; // default to fail

            db.SaveChanges();

            return(res);
        }
        static HomeController()
        {
            // instantiate data objects
            _db    = new db_insuranceEntities_();
            _vdata = new vinsuree_data_all();

            // instantiate controller(s)
            _data = new WebAppDataController();
            _ext  = new WebAppExtController();
        }
        public bool DataInsert(db_insuranceEntities_ db, vinsuree_data_all data)
        {
            bool res = true; // default to pass

            ParseDataHelper(data);
            SetTableValHelper(db);

            try { db.SaveChanges(); }
            catch (DbEntityValidationException ex) { throw new Exception(ex.Message); }

            return(res);
        }
        public ActionResult Create(vinsuree_data_all rec)
        {
            bool pass;

            pass = _ext.CheckFieldVals(rec); // validate req fields are populated
            if (!pass)
            {
                ViewBag.ErrorMessage = "All fields required for record creation."; return(View("Error"));
            }

            pass = _data.DataInsert(_db, rec); // insert record to db
            if (!pass)
            {
                ViewBag.ErrorMessage = "Error on record creation at WebAppDataController.DataInsert()"; return(View("Error"));
            }

            return(View());
        }
        // validate cshtml fields are populated
        public bool CheckFieldVals(vinsuree_data_all data)
        {
            bool res = true; // default to valid

            PropertyInfo[] props = typeof(vinsuree_data_all).GetProperties();

            var _props = new List <PropertyInfo>(props);

            _props.RemoveRange(13, 2); // remove quote vals
            _props.ToArray();

            foreach (PropertyInfo prop in _props)
            {
                object value = prop.GetValue(data, null);
                if (value == null)
                {
                    return(res = false);
                }
            }

            return(res);
        }
        public string CalcQuote(vinsuree_data_all data)
        {
            decimal quote = 50.00M; // default quote val

            // age logic
            quote = (DateTime.Now.Year - data.dob.Value.Year > 25) ? quote + 25.00M : quote;
            quote = (DateTime.Now.Year - data.dob.Value.Year < 18) ? quote + 25.00M : quote;
            quote = (DateTime.Now.Year - data.dob.Value.Year > 100) ? quote + 25.00M : quote;

            // automobile logic
            quote = (data.car_year < 2000) ? quote + 25.00M : quote;
            quote = (data.car_year > 2015) ? quote + 25.00M : quote;
            quote = (data.car_make.ToLower() == "porsche") ? quote + 25.00M : quote;
            quote = (data.car_make.ToLower() == "porsche" && data.car_model.Contains("carrera")) ? quote + 25.00M : quote;

            // risk logic
            //TO DO quote = (data.tickets > 4) ? quote + (data.tickets * 10).Value : quote;
            //TO DO quote = (data.dui > 0) ? quote + (Decimal.Multiply(quote, .25M)): quote;
            quote = (data.coverage_type.ToLower() == "full") ? quote + (Decimal.Multiply(quote, .25M)) : quote;

            return(quote.ToString());
        }
        public bool DataDelete(db_insuranceEntities_ db, vinsuree_data_all data, int key)
        {
            bool res = false; // default to fail

            return(res);
        }
        public bool DataSelect(db_insuranceEntities_ db, vinsuree_data_all data, int key) // single record select
        {
            bool res = false;                                                             // default to fail

            return(res);
        }
        public bool DataSelect(db_insuranceEntities_ db, vinsuree_data_all data) // load all applicable records
        {
            bool res = false;                                                    // default to fail

            return(res);
        }