示例#1
0
 public BaseController()
 {
     RestApiCallService = new RestApiCallService(
         ConfigurationManager.AppSettings["x-rapidapi-base-url"],
         ConfigurationManager.AppSettings["x-rapidapi-host"],
         ConfigurationManager.AppSettings["x-rapidapi-key"]);
 }
示例#2
0
        // GET: Games
        public ActionResult Index(GamesFilterViewModel model, string season, int page)
        {
            model.Season   = model.Season ?? season;
            model.Page     = model.Page ?? page;
            model.PageSize = model.PageSize ?? 25;
            ViewBag.Season = season;
            ViewBag.Page   = page;
            if (!ModelState.IsValid)
            {
                return(View(GameContentViewModel.Empty));
            }

            try
            {
                //throw new NotImplementedException();
                var resource = string.Format("games?seasons[]={0}&page={1}&per_page={2}",
                                             model.Season, model.Page, model.PageSize);


                var restReponse    = RestApiCallService.Call(resource);
                var response       = JsonConvert.DeserializeObject <ApiGameContent>(restReponse.Content);
                var gamesListModel = Mapper.Map <GameContentViewModel>(response);

                var st = response.Data.Where(x => x.Id == 1);

                return(View(gamesListModel));
            }
            catch (Exception exception)
            {
                // TODO: logging
                ModelState.AddModelError("", "A aparut o eroare.");
                return(View(GameContentViewModel.Empty));
            }
        }
示例#3
0
        // GET: Teams
        public ActionResult Details(TeamsFilterViewModel model, int id)
        {
            model.Id = model.Id ?? id;

            if (!ModelState.IsValid)
            {
                return(View(TeamContentViewModel.Empty));
            }

            try
            {
                var     resource    = string.Format("teams/{0}", model.Id);
                var     restReponse = RestApiCallService.Call(resource);
                ApiTeam response    = JsonConvert.DeserializeObject <ApiTeam>(restReponse.Content);
                ViewBag.Abbreviation = response.Abbreviation;
                ViewBag.City         = response.City;
                ViewBag.Conference   = response.Conference;
                ViewBag.Division     = response.Division;
                ViewBag.FullName     = response.FullName;
                ViewBag.Id           = response.Id;
                ViewBag.Name         = response.Name;
                GetPlayers(response.Id);

                return(View());
            }
            catch (Exception exception)
            {
                // TODO: logging
                ModelState.AddModelError("", "A aparut o eroare.");
                return(View(TeamContentViewModel.Empty));
            }
        }
示例#4
0
 public void GetPlayers(int?id)
 {
     try
     {
         var resourcePlayers    = string.Format("players");
         var restReponsePlayers = RestApiCallService.Call(resourcePlayers);
         var responsePlayers    = JsonConvert.DeserializeObject <ApiPlayerContent>(restReponsePlayers.Content);
         ViewBag.playersAtTeam = responsePlayers.Data.Where(s => s.Team.Id == id);
     }
     catch (Exception exception)
     {
     }
 }