Ejemplo n.º 1
0
        protected int SetVariable(string n, string name, string value)
        {
            if (elements[name].Write == false)
            {
                throw new CmiReadWriteOnlyException(Translations.Interactions_SetValue_Requested_variable_is_read_only);
            }

            int number;

            int.TryParse(n, out number);

            List <TblVarsInteractions> list = ServerModel.DB.Query <TblVarsInteractions>(
                new AndCondition(
                    new CompareCondition <int>(
                        DataObject.Schema.LearnerSessionRef,
                        new ValueCondition <int>(LearnerSessionId), COMPARE_KIND.EQUAL),
                    new CompareCondition <string>(
                        DataObject.Schema.Name,
                        new ValueCondition <string>(name), COMPARE_KIND.EQUAL),
                    new CompareCondition <int>(
                        DataObject.Schema.Number,
                        new ValueCondition <int>(number), COMPARE_KIND.EQUAL)));

            if (list.Count > 0)
            {
                list[0].Value = value;
                ServerModel.DB.Update <TblVarsInteractions>(list[0]);

                return(list[0].ID);
            }
            else
            {
                TblVarsInteractions lsv = new TblVarsInteractions
                {
                    LearnerSessionRef = LearnerSessionId,
                    Name   = name,
                    Value  = value,
                    Number = number
                };

                return(ServerModel.DB.Insert <TblVarsInteractions>(lsv));
            }
        }
Ejemplo n.º 2
0
        protected int SetVariable(string n, string name, string value)
        {
            if (elements[name].Write == false)
            {
              throw new CmiReadWriteOnlyException(Translations.Interactions_SetValue_Requested_variable_is_read_only);
            }

            int number;
            int.TryParse(n, out number);

            List<TblVarsInteractions> list = ServerModel.DB.Query<TblVarsInteractions>(
                        new AndCondition(
                            new CompareCondition<int>(
                                DataObject.Schema.LearnerSessionRef,
                                new ValueCondition<int>(LearnerSessionId), COMPARE_KIND.EQUAL),
                            new CompareCondition<string>(
                                DataObject.Schema.Name,
                                new ValueCondition<string>(name), COMPARE_KIND.EQUAL),
                            new CompareCondition<int>(
                                DataObject.Schema.Number,
                                new ValueCondition<int>(number), COMPARE_KIND.EQUAL)));

            if (list.Count > 0)
            {
                list[0].Value = value;
                ServerModel.DB.Update<TblVarsInteractions>(list[0]);

                return list[0].ID;
            }
            else
            {
                TblVarsInteractions lsv = new TblVarsInteractions
                {
                    LearnerSessionRef = LearnerSessionId,
                    Name = name,
                    Value = value,
                    Number = number
                };

                return ServerModel.DB.Insert<TblVarsInteractions>(lsv);
            }
        }