public EditGameViewModel MapModelToViewModel(EditGameModel editGameModel) { return new EditGameViewModel { GameId = editGameModel.GameId, HomeTeamId = editGameModel.HomeTeamId, AwayTeamId = editGameModel.AwayTeamId, HomeScore = editGameModel.HomeScore, AwayScore = editGameModel.AwayScore, GameDate = editGameModel.GameDate, FixtureTime = editGameModel.FixtureTime, Teams = editGameModel.Teams.Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Text }).ToList() }; }
public void SetDomainFromModel(EditGameModel editGameModel, Game game) { game.GameId = editGameModel.GameId; game.HomeTeamId = editGameModel.HomeTeamId; game.AwayTeamId = editGameModel.AwayTeamId; game.HomeScore = editGameModel.HomeScore; game.AwayScore = editGameModel.AwayScore; game.GameDateTime = editGameModel.GameDate; }
public void SaveEditGameModel(EditGameModel editGameModel) { if (editGameModel.GameId == 0) { Game game = new Game { HomeTeamId = editGameModel.HomeTeamId, AwayTeamId = editGameModel.AwayTeamId, HomeScore = editGameModel.HomeScore, AwayScore = editGameModel.AwayScore, GameDateTime = editGameModel.GameDate }; _gameRepository.InsertGame(game); } else { Game game = _gameRepository.GetGame(editGameModel.GameId); _mapper.SetDomainFromModel(editGameModel, game); _gameRepository.UpdateGame(game); } }