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 SetEstimatedResults() { if (DateTime.Now >= new DateTime(2020, 6, 12, 21, 0, 0)) { return(View("OverDeadlineView")); } if (EstimatedResultController.GetEstimatedResultModelsForUser(User.Identity.GetUserId()).Any()) { return(View("JustOnceView")); } try { ViewBag.Matches = MatchesController.GetMatches(); ViewBag.EstimatedResults = new EstimatedResultForUser (EstimatedResultController.GetEstimatedResultModelsForUser(User.Identity.GetUserId())); ViewBag.Message = "OK"; } catch (Exception ex) { ViewBag.Message = ex.Message; } return(View("SetResultsView")); }
public ActionResult Index() { if (!Request.IsAuthenticated) { return(View()); } try { ViewBag.Matches = MatchesController.GetMatches(); ViewBag.EstimatedResults = new EstimatedResultForUser (EstimatedResultController.GetEstimatedResultModelsForUser(User.Identity.GetUserId())); ViewBag.Ranking = RankingController.GetRanking(); ViewBag.Users = new Users(HttpContext.GetOwinContext() .GetUserManager <Identity.ApplicationUserManager>() .Users.ToList()); ViewBag.Message = "OK"; } catch (Exception ex) { ViewBag.Message = ex.Message; } return(View()); }
public ActionResult Index() { ViewBag.Message = "Admin page"; ViewBag.Users = HttpContext.GetOwinContext() .GetUserManager <Identity.ApplicationUserManager>() .Users.ToList(); ViewBag.Matches = MatchesController.GetMatches(); return(View()); }
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")); }
private void CreateRows(List <ApplicationUser> users) { int row = 0; int col = 0; //ViewBag.EstimatedResults = new EstimatedResultForUser(EstimatedResultController.GetEstimatedResultModels()); List <MatchModel> matches = MatchesController.GetMatches(); Dictionary <int, string> helpUsers = new Dictionary <int, string>(); //table header TipsTableRow header = new TipsTableRow(row); header.AddCell(col, string.Empty); col++; header.AddCell(col, string.Empty); col++; foreach (ApplicationUser user in users) { helpUsers.Add(col, user.Id); header.AddCell(col, user.UserName); col++; } this.rows.Add(header); row++; int colOverAll = users.Count + 2; //table data foreach (MatchModel match in matches) { col = 2; TipsTableRow tipRow = new TipsTableRow(row); tipRow.AddCell(0, match.TeamOne); tipRow.AddCell(1, match.TeamTwo); for (int i = 2; i < colOverAll; i++) { string userId = helpUsers[i]; var model = EstimatedResultController.GetEstimatedResultModelForUserAndMatch(userId, match.Id); string content = model != null?model.ToString() : string.Empty; tipRow.AddCell(col, content); col++; } this.rows.Add(tipRow); row++; } this.Rows = this.rows.Count; this.Columns = colOverAll; }
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()); }