Exemplo n.º 1
0
        public static void UpdateScoreResponseNoSave(IFormsRepository formsRepo, int formResultId, string itemVariableIdent, double response)
        {
            //if response exists already...
            def_ResponseVariables rv = formsRepo.GetResponseVariablesByFormResultIdentifier(formResultId, itemVariableIdent);

            if (rv != null)
            {
                rv.rspValue = response.ToString();
            }

            //if not...
            def_ItemVariables iv = formsRepo.GetItemVariableByIdentifier(itemVariableIdent);

            if (iv == null)
            {
                throw new Exception("could not find itemVariable with identifier \"" + itemVariableIdent + "\"");
            }
            def_ItemResults ir = formsRepo.GetItemResultByFormResItem(formResultId, iv.itemId);

            if (ir == null)
            {
                ir = new def_ItemResults()
                {
                    itemId        = iv.itemId,
                    formResultId  = formResultId,
                    dateUpdated   = DateTime.Now,
                    sessionStatus = 0
                };
                formsRepo.AddItemResult(ir);
            }
            rv = ir.def_ResponseVariables.FirstOrDefault(trv => trv.itemVariableId == iv.itemVariableId);
            if (rv == null)
            {
                rv = new def_ResponseVariables()
                {
                    itemResultId   = ir.itemResultId,
                    itemVariableId = iv.itemVariableId,
                    rspValue       = response.ToString()
                };
                formsRepo.AddResponseVariable(rv);
            }
            else
            {
                rv.rspValue = response.ToString();
            }
        }
Exemplo n.º 2
0
        public static string ImportFormResultJSON(IFormsRepository formsRepo, string json)
        {
            string result = String.Empty;

            try
            {
                var dFormResults = fastJSON.JSON.Parse(json);
                Dictionary <string, Object> resDict = (Dictionary <string, Object>)dFormResults;

                ////add the def_FormResults object to the database, which will assign and return a formResultId
                //int formRsltId = formsRepo.AddFormResult((def_FormResults) dFormResults);

                def_FormResults formResult = new def_FormResults()
                {
                    formId        = Convert.ToInt32(resDict["formId"]),
                    dateUpdated   = DateTime.Now,
                    formStatus    = Convert.ToByte(resDict["formStatus"]),
                    sessionStatus = Convert.ToByte(resDict["sessionStatus"])
                };

                int formRsltId = formsRepo.AddFormResult(formResult);

                List <Object> itemObjectList = (List <Object>)resDict["def_ItemResults"];
                foreach (Object o in itemObjectList)
                {
                    Dictionary <string, object> dict        = (Dictionary <string, object>)o;
                    def_ItemResults             itemResults = new def_ItemResults
                    {
                        formResultId  = formRsltId,
                        itemId        = Convert.ToInt32(dict["itemId"]),
                        sessionStatus = Convert.ToInt32(dict["sessionStatus"]),
                        dateUpdated   = Convert.ToDateTime(dict["dateUpdated"])
                    };

                    int itemResultId = formsRepo.AddItemResult(itemResults);

                    List <Object> respVarObjectList = (List <Object>)dict["def_ResponseVariables"];

                    foreach (Object r in respVarObjectList)
                    {
                        Dictionary <string, object> rDict = (Dictionary <string, object>)r;

                        DateTime?date;
                        if (rDict["rspDate"] == null)
                        {
                            date = null;
                        }
                        else
                        {
                            date = Convert.ToDateTime(rDict["rspDate"]);
                        }

                        def_ResponseVariables dResponseVariables = new def_ResponseVariables
                        {
                            itemResultId   = itemResultId,
                            itemVariableId = Convert.ToInt32(rDict["itemVariableId"]),
                            rspInt         = Convert.ToInt32(rDict["rspInt"]),
                            rspFloat       = Convert.ToDouble(rDict["rspFloat"]),
                            rspDate        = date,
                            rspValue       = Convert.ToString(rDict["rspValue"])
                        };

                        formsRepo.AddResponseVariableNoSave(dResponseVariables);
                    }
                }

                formsRepo.Save();

                //pass the formResultId to the return value container
                result = formRsltId.ToString();

                AccessLogging.InsertAccessLogRecord(formsRepo, formRsltId, (int)AccessLogging.accessLogFunctions.IMPORT, "Imported assessment from JSON.");
            }
            catch (Exception excptn)
            {
                Debug.WriteLine("Def3WebServices.LoadFormResultJSON exception:" + excptn.Message);
            }

            return(result);
        }
Exemplo n.º 3
0
        public static void AddField(IFormsRepository formsRepo, string itemIdentifier, def_FormResults formResult, string fieldName, string value)
        {
            int itemId = 0;

            try
            {
                itemId = formsRepo.GetItemByIdentifier(itemIdentifier).itemId;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: Add Field to form: " + ex.Message);
                return;
            }

            def_ItemResults itemResult = formsRepo.GetItemResultByFormResItem(formResult.formResultId, itemId);

            if (itemResult == null)
            {
                itemResult = new def_ItemResults();

                itemResult.itemId        = itemId;
                itemResult.formResultId  = formResult.formResultId;
                itemResult.dateUpdated   = DateTime.Now;
                itemResult.sessionStatus = 0;

                formsRepo.AddItemResult(itemResult);
            }

            def_ResponseVariables relatedFormResultRV = null;

            try
            {
                relatedFormResultRV = formsRepo.GetResponseVariablesByFormResultIdentifier(formResult.formResultId, fieldName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            def_ItemVariables itemVariableRelated = formsRepo.GetItemVariableByIdentifier(fieldName);


            if (itemVariableRelated != null)
            {
                if (relatedFormResultRV != null)
                {
                    relatedFormResultRV.rspValue = value;

                    formsRepo.ConvertValueToNativeType(itemVariableRelated, relatedFormResultRV);
                }
                else
                {
                    relatedFormResultRV = new def_ResponseVariables();

                    relatedFormResultRV.itemResultId = itemResult.itemResultId;

                    relatedFormResultRV.itemVariableId = itemVariableRelated.itemVariableId;

                    relatedFormResultRV.rspValue = value;

                    formsRepo.ConvertValueToNativeType(itemVariableRelated, relatedFormResultRV);

                    formsRepo.AddResponseVariableNoSave(relatedFormResultRV);
                }
            }

            formsRepo.Save();
        }