Пример #1
0
        public static bool WritePassedTest(AnsweredQuestions answeredQuestions, People people)
        {
            var test = Api.GetElements<Test>(Parameters.Filter, "[Id]", Parameters.Equal, answeredQuestions.TestId).FirstOrDefault();

            if (test == null)
            {
                return false;
            }

            Api.FillElement(test);

            var passedTest = new PassedTest();

            for (var i = 0; i < test.Questions.Length; i++)
            {
                try
                {
                    passedTest.Replies[test.Questions[i]] = answeredQuestions.Replies[i] ?? "";
                }
                catch
                {
                    passedTest.Replies[test.Questions[i]] = "";
                }
            }

            passedTest.SetPeople(people);
            passedTest.SetTest(test);

            Api.ExecuteCommand(Parameters.Insert, passedTest);

            return true;
        }
Пример #2
0
        public HttpResponseMessage UploadAnsweredQuestions(AnsweredQuestions answeredQuestions)
        {
            People people;

            var hash = AuthHash.GetHash(Request);

            if (hash == null || !Session.Authorizated.TryGetValue(hash.Value, out people))
            {
                return new HttpResponseMessage(HttpStatusCode.BadRequest);
            }

            return Database.WritePassedTest(answeredQuestions, people)
                ? new HttpResponseMessage(HttpStatusCode.OK)
                : new HttpResponseMessage(HttpStatusCode.NotFound);
        }