public ActionResult Create(CompetitionViewModel competition)
        {
            var response = Client.PostAsJsonAsync("competitions", Mapper.Map<CompetitionViewModel, PostCompetition>(competition)).Result;

            switch (response.StatusCode)
            {
                case HttpStatusCode.Created:
                    return RedirectToAction("Index");
                case HttpStatusCode.BadRequest:
                    AddModelErrors(response);
                    return View(competition);
            }

            return ErrorView(response);
        }
Example #2
0
        public ActionResult Create(CompetitionViewModel competition)
        {
            var response = _client.PostAsJsonAsync("competitions", competition).Result;

            switch (response.StatusCode)
            {
                case HttpStatusCode.Created:
                    return RedirectToAction("Index");
                case HttpStatusCode.BadRequest:
                    foreach (var item in response.Content.ReadAsAsync<dynamic>().Result.Items)
                    {
                        ModelState.AddModelError(item.PropertyName.Value, item.Message.Value);
                    }

                    return View(competition);
            }

            return ErrorView(response);
        }
        public ActionResult Edit(Guid id, CompetitionViewModel competition)
        {
            var response = Client.PutAsJsonAsync("competitions/" + id, Mapper.Map<CompetitionViewModel, PutCompetition>(competition)).Result;

            switch (response.StatusCode)
            {
                case HttpStatusCode.OK:
                    return RedirectToAction("Index");
                case HttpStatusCode.BadRequest:
                    AddModelErrors(response);

                    return View(competition);
            }

            return ErrorView(response);
        }
Example #4
0
        public ActionResult Edit(Guid id)
        {
            var response = _client.GetAsync("competitions/" + id).Result;

            if (response.IsSuccessStatusCode)
            {
                dynamic competition = response.Content.ReadAsAsync<dynamic>().Result;
                var viewModel = new CompetitionViewModel()
                {
                    ClosingDate = competition.ClosingDate,
                    CompetitionKey = competition.CompetitionKey,
                    ID = competition.ID,
                    Question = competition.Question
                };

                for (int i = 0; i < competition.PossibleAnswers.Count; i++)
                {
                    var pa = competition.PossibleAnswers[i];
                    viewModel.Answers.Add(pa.AnswerText.ToString());

                    if (pa.IsCorrectAnswer.Value)
                    {
                        viewModel.CorrectAnswer = i;
                    }
                }

                return View(viewModel);
            }

            return ErrorView(response);
        }