public ActionResult FormDone(string formHash)
        {
            // whole form gets posted but we just want the instance code
            //string instanceCode = Request.Form["
            Survey survey = m_db.Surveys.FirstOrDefault(s => s.FormHash == formHash);
            if (survey == null)
                throw new ApplicationException(string.Format("Could not find Survey with formHash {0}", formHash));

            // if its a get, return a view now
            string httpVerb = HttpContext.Request.HttpMethod.ToUpper();
            if (httpVerb == "GET")
                return View("FormDoneGet");

            string instanceCode =  Request.Form[survey.InstanceCodeFieldID];
            if (string.IsNullOrEmpty(instanceCode))
                throw new ApplicationException(string.Format("Webhook received empty {0} value for survey {1}",
                    survey.InstanceCodeFieldID, survey.FormHash));

            Filling filling = m_db.Fillings.FirstOrDefault(f => f.InstanceCode == instanceCode);
            if (filling == null)
                throw new ApplicationException(string.Format("Could not find Filling with instanceCode {0} for survey {1}",
                    instanceCode, formHash));

            var codeGen = new CodeGenerator();
            filling.PavlovCode = codeGen.MakePavlovCode();
            m_db.MarkModified(filling);
            m_db.SaveChanges();

            return View();
        }
        //
        // GET: /Filling/
        public ActionResult Index(string surveyKey)
        {
            var survMatch = m_db.Surveys.FirstOrDefault(s => s.SurveyKey == surveyKey);
            if (survMatch == null)
                return View("NotFound");

            var newFill = new Filling();
            m_db.Fillings.Add(newFill);
            newFill.Survey = survMatch;
            m_db.SaveChanges();
            var cg = new CodeGenerator();
            newFill.InstanceCode = cg.MakeInstanceCode(survMatch.SurveyID, newFill.FillingID);
            m_db.MarkModified(newFill);
            m_db.SaveChanges();

            var m = new FillInstance()
            {
                FillingID = newFill.FillingID,
                SubDomain = survMatch.SubDomain,
                FormHash = survMatch.FormHash,
                InstanceCode = newFill.InstanceCode,
                InstanceCodeFieldID = survMatch.InstanceCodeFieldID
            };

            return View(m);
        }
        public void MakePavlovCode_Varies()
        {
            var cg1 = new CodeGenerator();
            var pavlov1 = cg1.MakePavlovCode();

            var cg2 = new CodeGenerator();
            var pavlov2 = cg2.MakePavlovCode();

            Assert.IsNotNull(pavlov1);
            Assert.IsNotNull(pavlov2);
            Assert.AreEqual(6, pavlov1.Length);
            Assert.AreNotEqual(pavlov2, pavlov1, "generated strings should be different");
        }