public ActionResult GameImport() { try { List <Record> loadData = this.LoadData(); int counter = 1; foreach (Record r in loadData) { ResultModel resultModel = new ResultModel() { Id = counter, ValueOne = -1, ValueTwo = -1, Date = r.Result }; ResultController.AddResult(resultModel); MatchesController.AddMatch(new MatchModel() { TeamOne = r.One, TeamTwo = r.Two, ResultId = counter, Result = resultModel }); } ResultController.SaveChanges(); MatchesController.SaveChanges(); } catch (Exception e) { ViewBag.Message = e.Message; return(View("Index")); } ViewBag.Message = "Succesfull load." + Environment.NewLine + MatchesController.Count() + " were loaded"; return(View("GameImportView")); }
public ActionResult DeleteMatch(int matchId) { var match = MatchesController.GetMatches().First(x => x.Id == matchId); if (ResultController.GetResult(match.ResultId).IsImported == 1) { ResultController.DeleteResultForMatch(match.ResultId); } MatchesController.DeleteMatch(matchId); return(RedirectToAction("Index", "Admin")); }
public async Task <string> Import() { Dictionary <int, ResultModel> newResults = new Dictionary <int, ResultModel>(); try { List <AdminController.Record> loadData = await this.LoadData(); foreach (AdminController.Record r in loadData) { if (!MatchesController.MatchExists(r.One, r.Two)) { continue; } MatchModel match = MatchesController.GetMatch(r.One, r.Two); int resultId = match.ResultId; int matchId = match.Id; ResultModel result = ResultController.GetResult(resultId); if (this.ParseForResult(result, r.Result)) { newResults.Add(matchId, result); } } if (newResults.Count > 0) { log.Info($"New results were loaded. Count: {newResults.Count}"); new PointsCounter().CountPoints(newResults); ResultController.SaveChanges(); } } catch (Exception e) { log.Error("error in loading data", e); return(e.Message); } return(newResults.Count.ToString()); }
public string Import() { Dictionary <int, ResultModel> newResults = new Dictionary <int, ResultModel>(); try { List <Record> loadData = this.LoadData(); foreach (Record r in loadData) { if (!MatchesController.MatchExists(r.One, r.Two)) { continue; } MatchModel match = MatchesController.GetMatch(r.One, r.Two); int resultId = match.ResultId; int matchId = match.Id; ResultModel result = ResultController.GetResult(resultId); if (this.ParseForResult(result, r.Result)) { newResults.Add(matchId, result); } } if (newResults.Count > 0) { pointsCounter.CountPoints(newResults); ResultController.SaveChanges(); } } catch (Exception e) { log.Error("Error in importing results"); return(e.Message); } return(newResults.Count.ToString()); }