// GET: Time
        public async Task <ActionResult> Index()
        {
            var response = await connectionApi.GetAllTimes();

            if (response.IsSuccessStatusCode)
            {
                var model = await response.Content.ReadAsAsync <IEnumerable <TimeViewModel> >();

                return(View(model));
            }

            return(View(new List <TimeViewModel>()));
        }
Exemple #2
0
        // GET: Jogo/Create
        public async Task <ActionResult> Create()
        {
            var responseJogos = await connectionApi.GetAllJogos();

            var jogos = await responseJogos.Content.ReadAsAsync <IEnumerable <JogoViewModel> >();

            jogos.Where(j => j.Chave.ToUpper() == Chaves.OITAVAS.ToUpper());

            if (jogos.Where(j => j.Chave.ToUpper() == Chaves.OITAVAS.ToUpper()).Count() == 8)
            {
                return(View("Error"));
            }
            else
            {
                var response = await connectionApi.GetAllTimes();

                if (response.IsSuccessStatusCode)
                {
                    var modelTimes = await response.Content.ReadAsAsync <IEnumerable <TimeViewModel> >();

                    var model            = new JogoCreateEditViewModel();
                    var selectList1      = new List <SelectListItem>();
                    var selectList2      = new List <SelectListItem>();
                    var selectListChaves = new List <SelectListItem>();

                    foreach (var ch in Chaves.ChavesList)
                    {
                        if (ch.ToString().Equals(Chaves.OITAVAS))
                        {
                            var select = new SelectListItem
                            {
                                Value    = ch.ToString(),
                                Text     = ch.ToString(),
                                Selected = ch.ToString() == model.Chave
                            };
                            selectListChaves.Add(select);
                        }
                    }
                    model.Chaves = selectListChaves;

                    foreach (var t in modelTimes)
                    {
                        var time1 = new SelectListItem
                        {
                            Value    = ((int)t.Id).ToString(),
                            Text     = t.Nome,
                            Selected = t.Id == model.TimeId1
                        };
                        var time2 = new SelectListItem
                        {
                            Value    = ((int)t.Id).ToString(),
                            Text     = t.Nome,
                            Selected = t.Id == model.TimeId2
                        };
                        selectList1.Add(time1);
                        selectList2.Add(time2);
                    }
                    model.NameTimeId1 = selectList1;
                    model.NameTimeId2 = selectList2;

                    return(View(model));
                }

                return(View());
            }
        }