Пример #1
0
        public ActionResult Game(int id, StatisticsEditModel model)
        {
            var gameParticipant = DbContext.GameParticipants.SingleOrDefault(gp => gp.GameParticipantId == id);
            if (gameParticipant == null || !User.IsTeamIdValidForUser(gameParticipant.TeamYear.TeamId))
            {
                return HttpNotFound();
            }

            var changes = ChangeTracker.GetChangeSets(gameParticipant.StatLines, model.StatLines, e => e.StatLineId, m => m.StatLineId);

            foreach (var pair in changes.CommonItems)
            {
                Mapper.Map(pair.RightItem, pair.LeftItem);
            }

            foreach (var statLineModel in changes.RightOnly)
            {
                gameParticipant.StatLines.Add(Mapper.Map<StatLine>(statLineModel));
            }

            DbContext.StatLines.RemoveRange(changes.LeftOnly);

            DbContext.SaveChanges(User.Identity.GetUserId());

            return Redirect(model.UrlForReturn);
        }
Пример #2
0
        public ActionResult Row(int id)
        {
            if (!User.IsTeamIdValidForUser(id))
            {
                return HttpNotFound();
            }

            var model = new StatisticsEditModel
            {
                StatLines = new List<StatisticsEditStatLineModel>
                {
                    new StatisticsEditStatLineModel
                    {
                        Player = new StatisticsEditPlayerModel()
                    }
                }
            };
            PopulateDropdownLists(model, id, true);

            return PartialView(model);
        }
Пример #3
0
        private void PopulateDropdownLists(StatisticsEditModel model, int teamId, bool includeEmptyOption)
        {
            var playerIds = model.StatLines.Select(sl => sl.Player.PlayerId);
            var playerList = DbContext.Players
                            .Where(p => (p.CurrentTeamId == teamId && p.IsActive) || playerIds.Contains(p.PlayerId))
                            .OrderBy(p => p.LastName)
                            .ThenBy(p => p.FirstName)
                            .ToList()
                            .Select(p => new SelectListItem { Value = p.PlayerId.ToString(), Text = p.FullName })
                            .ToList();

            if (includeEmptyOption)
            {
                playerList.Insert(0, new SelectListItem());
            }

            model.StatLines.ForEach(sl => sl.Player.ItemSelectList = new SelectList(playerList, "Value", "Text", sl.Player.PlayerId));
        }