Ejemplo n.º 1
0
        public ActionResult Create(DateTime date)
        {
            var model = new GameEditModel
                        {
                            GameDate = date + TimeSpan.FromHours(date.DayOfWeek == DayOfWeek.Saturday ? 8 : 18.5),
                            GameType = new GameEditTypeModel(),
                            GameStatus = new GameEditStatusModel(),
                            RoadParticipant = new GameParticipantEditModel {TeamYear = new GameEditTeamModel()},
                            HomeParticipant = new GameParticipantEditModel {TeamYear = new GameEditTeamModel()}
                        };
            PopulateDropdownLists(model);

            return View("Edit", model);
        }
Ejemplo n.º 2
0
        public ActionResult Create(GameEditModel model)
        {
            var roadTeam = Mapper.Map<GameParticipant>(model.RoadParticipant);
            var homeTeam = Mapper.Map<GameParticipant>(model.HomeParticipant);
            homeTeam.IsHost = true;

            var game = Mapper.Map<Game>(model);
            game.GameParticipants = new[] {roadTeam, homeTeam};

            if (game.IsFinalized)
            {
                game.AddResultReportFromLeague();
            }

            DbContext.Games.Add(game);
            DbContext.SaveChanges(User.Identity.GetUserId());

            return Redirect(model.UrlForReturn);
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int id, GameEditModel model)
        {
            var game = DbContext.Games.SingleOrDefault(g => g.GameId == id);
            if (game == null)
            {
                return HttpNotFound();
            }

            Mapper.Map(model, game);
            Mapper.Map(model.RoadParticipant, game.RoadParticipant);
            Mapper.Map(model.HomeParticipant, game.HomeParticipant);

            if (game.IsFinalized)
            {
                game.AddResultReportFromLeague();
            }

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

            return Redirect(model.UrlForReturn);
        }
Ejemplo n.º 4
0
        private void PopulateDropdownLists(GameEditModel model)
        {
            model.GameStatus.ItemSelectList = GetGameStatusesSelectListItems(model.GameStatus.GameStatusId);

            var gameTypes = DbContext.GameTypes
                                     .OrderBy(gt => gt.GameTypeId)
                                     .Select(gt => new SelectListItem {Value = gt.GameTypeId.ToString(), Text = gt.Description})
                                     .ToList();
            model.GameType.ItemSelectList = new SelectList(gameTypes, "Value", "Text", model.GameType.GameTypeId);

            var teamYears = DbContext.TeamYears
                                     .Where(ty => ty.Year == model.GameDate.Year)
                                     .OrderBy(ty => ty.FullName)
                                     .Select(ty => new SelectListItem {Value = ty.TeamYearId.ToString(), Text = ty.FullName})
                                     .ToList();
            model.RoadParticipant.TeamYear.ItemSelectList = new SelectList(teamYears, "Value", "Text", model.RoadParticipant.TeamYear.TeamYearId);
            model.HomeParticipant.TeamYear.ItemSelectList = new SelectList(teamYears, "Value", "Text", model.HomeParticipant.TeamYear.TeamYearId);
        }