Exemplo n.º 1
0
        public ActionResult ResolverTarefa(ResolucaoViewModel viewModel)
        {
            var resolucao = Mapper.Map <Resolucao>(viewModel);

            foreach (var questao in resolucao.Questoes)
            {
                questao.IdAluno = Convert.ToInt32(User.Identity.Name);
            }

            using (var client = new WebClient()) {
                client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                try {
                    client.UploadString(APIUrl.SalvarRespostasDeTarefa(), "POST",
                                        JsonConvert.SerializeObject(resolucao));

                    return(RedirectToAction("Index"));
                } catch (WebException ex) {
                    ModelState.AddModelError(string.Empty, ex.Message);
                    return(RedirectToAction("ResolverTarefa", new { IdTarefa = viewModel.IdTarefa }));
                }
            }
        }