Пример #1
0
        public async Task <JsonResult> Create_Answer(TestQuestionAnswerDTO model)
        {
            string error     = null;
            int    id        = 0;
            var    errorList = ModelState.Where(n => n.Value.Errors.Any()).ToDictionary(
                kvp => kvp.Key,
                kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray()
                );

            try
            {
                if (!ModelState.IsValid && errorList.Count > 0)
                {
                    throw new Exception(string.Join(',', errorList.First().Value));
                }

                id = await TestService.Answer_AddAsync(model);
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            return(Json(new { id, error, errorList }));
        }
Пример #2
0
 public EditAnswerPageViewModel(UserDTO user, int?id, int questionId)
 {
     User       = user;
     QuestionId = questionId;
     Answer     = new TestQuestionAnswerDTO();
     new Task(async() => await GetBusyWith(FetchData(id))).Start();
 }
Пример #3
0
        public async Task <int> Answer_AddAsync(TestQuestionAnswerDTO answer)
        {
            var obj = _mapper.Map <TestQuestionAnswerDTO, TestQuestionAnswer>(answer);

            DB.TestQuestionAnswerRepository.Add(obj);
            await DB.SaveChangesAsync();

            return(obj.TestQuestionAnswerId);
        }
Пример #4
0
        public async Task FetchData(int?id)
        {
            if (id == null || id == 0)
            {
                Answer = new TestQuestionAnswerDTO()
                {
                    QuestionId = QuestionId
                };
                return;
            }
            HttpClient client   = new HttpClient();
            var        response = await client.GetStringAsync(String.Format(@"tests/findanswer?login={0}&password={1}&id={2}".ToUrl(), User.Login, User.Password, id));

            if (response != null)
            {
                TestQuestionAnswerDTO answer = JsonConvert.DeserializeObject <TestQuestionAnswerDTO>(response);
                if (answer != null)
                {
                    Answer = answer;
                }
            }
            IsNotBusy = true;
        }
Пример #5
0
        public string FindAnswer(string login, string password, int id)
        {
            using MyContext context = new MyContext();
            var user = AuthHelper.FindUser(login, password, context);

            if (user == null)
            {
                return(null);
            }
            var answer = context.TestQuestionAnswers.FirstOrDefault(tqa => tqa.Id == id);

            if (answer == null)
            {
                return(null);
            }
            var answerDTO = new TestQuestionAnswerDTO()
            {
                Id      = answer.Id,
                IsRight = answer.IsRight,
                Text    = answer.Text
            };

            return(answerDTO.ToJson());
        }