public ActionResult Details(int id) { try { List <Score> scoresList = new List <Score>(); ScoresDBContext scoresDBContext = new ScoresDBContext(); DataSet dsMatchPlayerScores = new DataSet(); dsMatchPlayerScores = scoresDBContext.GetMatchPlayersScores(id); Matches matches = new Matches(); matches.Location = Convert.ToString(dsMatchPlayerScores.Tables[0].Rows[0]["Location"]); matches.MatchDate = Convert.ToDateTime(dsMatchPlayerScores.Tables[0].Rows[0]["MatchDate"]); matches.Player1Name = Convert.ToString(dsMatchPlayerScores.Tables[0].Rows[0]["Player1Name"]); matches.Player2Name = Convert.ToString(dsMatchPlayerScores.Tables[0].Rows[0]["Player2Name"]); matches.WinnerName = Convert.ToString(dsMatchPlayerScores.Tables[0].Rows[0]["WinnerName"]); for (int i = 0; i < dsMatchPlayerScores.Tables[0].Rows.Count; i++) { Score score = new Score(); score.Set1Score = Convert.ToInt32(dsMatchPlayerScores.Tables[0].Rows[i]["Set1Score"]); score.Set2Score = Convert.ToInt32(dsMatchPlayerScores.Tables[0].Rows[i]["Set2Score"]); score.Set3Score = Convert.ToInt32(dsMatchPlayerScores.Tables[0].Rows[i]["Set3Score"]); scoresList.Add(score); } matches.scoreList = scoresList; return(View(matches)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Scores", "Index"))); } }
public Matches getMatchData(int id) { Matches matches = new Matches(); List <Score> scoresList = new List <Score>(); ScoresDBContext scoresDBContext = new ScoresDBContext(); DataSet dsMatchPlayerScores = new DataSet(); dsMatchPlayerScores = scoresDBContext.GetMatchPlayersScores(id); matches.playerNames = getPlayersList(); matches.Location = Convert.ToString(dsMatchPlayerScores.Tables[0].Rows[0]["Location"]); matches.MatchDate = Convert.ToDateTime(dsMatchPlayerScores.Tables[0].Rows[0]["MatchDate"]); matches.Player1ID = Convert.ToInt32(dsMatchPlayerScores.Tables[0].Rows[0]["Player1ID"]); matches.Player2ID = Convert.ToInt32(dsMatchPlayerScores.Tables[0].Rows[0]["Player2ID"]); matches.WinnerID = Convert.ToInt32(dsMatchPlayerScores.Tables[0].Rows[0]["WinnerID"]); matches.Player1Name = Convert.ToString(dsMatchPlayerScores.Tables[0].Rows[0]["Player1Name"]); matches.Player2Name = Convert.ToString(dsMatchPlayerScores.Tables[0].Rows[0]["Player2Name"]); matches.WinnerName = Convert.ToString(dsMatchPlayerScores.Tables[0].Rows[0]["WinnerName"]); for (int i = 0; i < dsMatchPlayerScores.Tables[0].Rows.Count; i++) { Score score = new Score(); score.Set1Score = Convert.ToInt32(dsMatchPlayerScores.Tables[0].Rows[i]["Set1Score"]); score.Set2Score = Convert.ToInt32(dsMatchPlayerScores.Tables[0].Rows[i]["Set2Score"]); score.Set3Score = Convert.ToInt32(dsMatchPlayerScores.Tables[0].Rows[i]["Set3Score"]); scoresList.Add(score); } matches.scoreList = scoresList; return(matches); }
public ActionResult Create(Matches matches) { try { // To validate Winner is one of the selected player if (matches.WinnerID == matches.Player1ID || matches.WinnerID == matches.Player2ID) { if (ModelState.IsValid) { MatchesDBContext matchesDBContext = new MatchesDBContext(); int MatchID = matchesDBContext.InsertMatchDetails(matches); matches.MatchID = MatchID; ScoresDBContext scoresDBContext = new ScoresDBContext(); int result = scoresDBContext.InsertScores(matches); if (result == 1 || result == -1) { return(RedirectToAction("Save")); } } return(RedirectToAction("Index")); } else { matches.playerNames = getPlayersList(); return(View(matches)); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Matches", "Create"))); } }
public ActionResult Edit(Matches matches) { try { if (ModelState.IsValid) { matches.MatchID = Convert.ToInt32(TempData["MatchID"]); ScoresDBContext scoresDBContext = new ScoresDBContext(); scoresDBContext.UpdateScores(matches); MatchesDBContext matchesDBContext = new MatchesDBContext(); int result = matchesDBContext.UpdateMatchDetails(matches); if (result == 1) { return(RedirectToAction("Save")); } return(RedirectToAction("Index")); } Matches objMatches = new Matches(); objMatches = getMatchData(Convert.ToInt32(TempData["MatchID"])); return(View(objMatches)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Matches", "Edit"))); } }