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); }
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); }
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); }
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); }