Exemplo n.º 1
0
        public ActionResult List()
        {
            var model = new PlayerEditModel {Team = new PlayerEditTeamModel()};
            PopulateDropdownLists(model);

            return View(model);
        }
Exemplo n.º 2
0
        public ActionResult Create(PlayerEditModel model)
        {
            var player = Mapper.Map<Player>(model);

            DbContext.Players.Add(player);
            DbContext.SaveChanges(User.Identity.GetUserId());

            return Redirect(model.UrlForReturn);
        }
Exemplo n.º 3
0
        public ActionResult Create()
        {
            var model = new PlayerEditModel
                        {
                            Team = new PlayerEditTeamModel(),
                            IsActive = true
                        };
            PopulateDropdownLists(model);

            return View("Edit", model);
        }
Exemplo n.º 4
0
        public ActionResult PoolList()
        {
            var model = new PlayerEditModel {Team = new PlayerEditTeamModel()};

            if (Request.Cookies["lastTeamId"] != null)
            {
                model.Team.TeamId = int.Parse(Request.Cookies["lastTeamId"].Value);
            }

            PopulateDropdownLists(model);

            return View(model);
        }
Exemplo n.º 5
0
 private void PopulateDropdownLists(PlayerEditModel model)
 {
     var teams = DbContext.TeamYears
                          .Where(ty => ty.Year == Consts.CurrentYear && !Consts.InvalidPlayerTeamIds.Contains(ty.TeamId))
                          .OrderBy(ty => ty.DivisionYear.IsInLeague)
                          .ThenBy(ty => ty.FullName)
                          .ToList()
                          .FilterTeamsForUser(User, ty => ty.TeamId)
                          .Select(ty => new SelectListItem {Value = ty.TeamId.ToString(), Text = ty.FullName})
                          .ToList();
     model.Team.ItemSelectList = new SelectList(teams, "Value", "Text", model.Team.TeamId);
 }
Exemplo n.º 6
0
        public ActionResult Edit(int id, PlayerEditModel model)
        {
            var player = DbContext.Players.SingleOrDefault(p => p.PlayerId == id);
            if (player == null || !User.IsTeamIdValidForUser(player.CurrentTeamId))
            {
                return HttpNotFound();
            }

            Mapper.Map(model, player);
            DbContext.SaveChanges(User.Identity.GetUserId());

            return Redirect(model.UrlForReturn);
        }