public ActionResult Index(MyTeamViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Team MUST be loaded first, then ALL the values copied over
                Team team = teamService.Get(model.Team.Id);
                TryUpdateModel(team, "Team"); // Should copy all values from model to team
                team.GameDay = dayOfWeekService.Get(model.DayOfWeekId.Value);
                teamService.Update(team);

                teamService.Commit();
                SuccessMessage(FormMessages.SaveSuccess);
            }

            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    Console.Out.WriteLine(error.ErrorMessage);
                }
            }


            model.DaysOfWeek = new SelectList(dayOfWeekService.Get(), "Id", "Day", model.DayOfWeekId);

            return(View(model));
        }
        public ActionResult Create()
        {
            MyTeamViewModel model = new MyTeamViewModel();

            PopulateStaticDate(model);

            return(View(model));
        }
        public ActionResult Edit(int id)
        {
            MyTeamViewModel model = new MyTeamViewModel();

            model.Team = teamService.Get(id);

            PopulateStaticDate(model);

            return(View(model));
        }
        public ActionResult Index()
        {
            User            user  = membershipService.GetLoggedInUser();
            MyTeamViewModel model = new MyTeamViewModel();

            model.Team       = teamService.Get(user.Team.Id);
            model.DaysOfWeek = new SelectList(dayOfWeekService.Get(), "Id", "Day", model.Team.GameDay.Id);

            return(View(model));
        }
Example #5
0
        public ActionResult MyTeam()
        {
            if (User.Identity.IsAuthenticated)
            {
                CustomPrincipal customPrincipal = (CustomPrincipal)User;
                if (customPrincipal == null || (customPrincipal.TeamId == 0))
                {
                    return(RedirectToAction("MyTeamRegister"));
                }
                TeamModel team = GetTeam(((CustomPrincipal)User).TeamId);

                var userList = TeamMembers(((CustomPrincipal)User).TeamId);

                team.Users = userList;

                MyTeamViewModel teamView = new MyTeamViewModel
                {
                    Team_Name = team.Team_Name,
                    Users     = team.Users
                };

                foreach (UserModel user in userList)
                {
                    if (user.User_ID == team.Team_Leader)
                    {
                        teamView.Team_Leader = user.First_Name + " " + user.Last_Name;
                    }
                }

                for (int i = 0; i < userList.Count; i++)
                {
                    UserModel user = userList[i];
                    if (user.User_ID == team.Team_Leader)
                    {
                        teamView.Users.Remove(user);
                    }
                }

                ViewBag.Team_Name   = teamView.Team_Name;
                ViewBag.Team_Leader = teamView.Team_Leader;

                return(View(teamView.Users));
            }

            return(RedirectToAction("MyTeamRegister"));
        }
        public ActionResult Edit(MyTeamViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Team MUST be loaded first, then ALL the values copied over
                Team team = teamService.Get(model.Team.Id);
                TryUpdateModel(team, "Team");                 // Should copy all values from model to team
                team.GameDay = dayOfWeekService.Get(model.DayOfWeekId.Value);
                teamService.Update(team);

                teamService.Commit();
                SuccessMessage(FormMessages.SaveSuccess);
                return(RedirectToAction("Index"));
            }

            PopulateStaticDate(model);

            return(View(model));
        }
        public ActionResult Create(MyTeamViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.DayOfWeekId.HasValue)
                {
                    model.Team.GameDay = dayOfWeekService.Get(model.DayOfWeekId.Value);
                }

                // TODO FIX GameeDay is NOT being saved
                teamService.Save(model.Team);
                teamService.Commit();

                SuccessMessage(FormMessages.SaveSuccess);
                return(RedirectToAction("Index"));
            }

            PopulateStaticDate(model);

            return(View(model));
        }
 private void PopulateStaticDate(MyTeamViewModel model)
 {
     model.DaysOfWeek = new SelectList(dayOfWeekService.Get(), "Id", "Day", model.Team.GameDay.Id);
 }
Example #9
0
        public async Task <IActionResult> Index()
        {
            ViewData["Title"] = "My Team";

            var viewModel = new MyTeamViewModel();

            HttpClientHandler handler = new HttpClientHandler();

            int currentGwId = await GetCurrentGameWeekId();

            if (Request.Cookies["teamId"] == null)
            {
                teamId = await GetTeamId();
            }
            else
            {
                teamId = Convert.ToInt32(Request.Cookies["teamId"]);
            }

            var response = await _httpClient.GetAuthAsync(CreateHandler(handler), $"my-team/{teamId}");

            if (!response.IsSuccessStatusCode)
            {
                return(RedirectToAction("Error", "Home"));
            }

            //look for 404 error here

            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();

            var myTeamJSON = JObject.Parse(content);

            MyTeam myTeam = JsonConvert.DeserializeObject <MyTeam>(myTeamJSON.ToString());

            //var teamPicksJSON = AllChildren(myTeamJSON)
            //    .First(c => c.Type == JTokenType.Array && c.Path.Contains("picks"))
            //    .Children<JObject>();

            //JObject transfersObject = (JObject)myTeamJSON["transfers"];
            //TransferInfo transferInfo = transfersObject.ToObject<TransferInfo>();

            List <Pick>           teamPicks         = new List <Pick>();
            List <Pick>           teamPicksLastWeek = new List <Pick>();
            List <Transfer>       transfers         = new List <Transfer>();
            List <PlayerPosition> positions         = new List <PlayerPosition>();

            //foreach (JObject result in teamPicksJSON)
            //{
            //    Pick p = result.ToObject<Pick>();
            //    teamPicks.Add(p);
            //}

            if (currentGwId > 1)
            {
                teamPicksLastWeek = await GetLastWeeksTeam(teamPicksLastWeek, teamId, currentGwId);

                foreach (var p in myTeam.picks)
                {
                    if (teamPicksLastWeek.FindAll(x => x.element == p.element).Count == 0)
                    {
                        p.IsNewTransfer = true;
                    }
                }
            }

            int gameweekId  = currentGwId;
            var eventStatus = await GetEventStatus();

            var lastEvent       = eventStatus.status.LastOrDefault();
            var isEventFinished = false;

            if (lastEvent != null)
            {
                if (lastEvent.bonus_added && eventStatus.leagues != "Updating")
                {
                    isEventFinished = true;
                }
            }

            transfers = await GetTeamTransfers(teamId);

            positions = await GetPlayerPositionInfo();

            myTeam.picks = await AddPlayerSummaryDataToTeam(myTeam.picks, gameweekId);

            myTeam.picks = await AddPlayerGameweekDataToTeam(myTeam.picks, gameweekId);

            myTeam.picks = await CalculateTotalPointsContributed(myTeam.picks, transfers, gameweekId);

            myTeam.picks = myTeam.picks.OrderBy(x => x.position).ToList();
            FPLTeam teamDetails = await GetTeamInfo(teamId);

            var entryHistory = await GetEntryHistory(teamId, currentGwId);

            var completeEntryHistory = new CompleteEntryHistory();

            completeEntryHistory = await GetCompleteEntryHistory(completeEntryHistory, teamId);

            entryHistory = await AddExtraDatatoEntryHistory(entryHistory, completeEntryHistory);

            entryHistory.BuyingPower = CalculateTeamBuyingPower(myTeam.picks, entryHistory);

            viewModel.MyTeam      = myTeam;
            viewModel.CurrentGwId = gameweekId;
            //viewModel.Picks = teamPicks;
            viewModel.Team        = teamDetails;
            viewModel.Positions   = positions;
            viewModel.TotalPoints = teamDetails.summary_overall_points ?? 0;
            //viewModel.TransferInfo = transferInfo;
            viewModel.IsEventFinished      = isEventFinished;
            viewModel.EntryHistory         = entryHistory;
            viewModel.CompleteEntryHistory = completeEntryHistory;
            viewModel.EventStatus          = eventStatus;

            return(View(viewModel));
        }