public IActionResult Place(PredictionViewModel vm) { string username = HttpContext.Session.GetString("Account"); if (username != null) { Prediction p = new Prediction(); p.Competition = CompRepo.GetCompetition(vm.Competition_id); p.User = UserRepo.GetUser(username); int position = 1; foreach (int id in vm.Driver_id) { PredictionComponent pc = new PredictionComponent(); pc.Driver_id = id; pc.Position = position; position++; p.Components.Add(pc); } try { repo.Place(p); return(RedirectToAction("Index", "Prediction")); } catch (Exception) { return(View("Error")); } } return(RedirectToAction("LogIn", "User")); }
public ActionResult AddUserInCompetition(long competitionID) { UserInCompetition userInCompetition = new UserInCompetition() { CompetitionID = competitionID }; using (CompetitionRepository repository = new CompetitionRepository()) { userInCompetition.Competition = repository.GetCompetition(competitionID); } return(View(userInCompetition)); }
public List <Prediction> GetAllPredictions(User u) { using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(PredictionQueries.GetAllPredictions(u), connection); connection.Open(); try { using (SqlDataReader reader = command.ExecuteReader()) { CompetitionRepository compRepo = new CompetitionRepository(new CompetitionRepositorySQLContext()); List <Prediction> list = new List <Prediction>(); while (reader.Read()) { Prediction p = new Prediction(); p.ID = (int)reader["prediction_id"]; p.Name = (string)reader["name"]; p.User = u; p.Competition = compRepo.GetCompetition((int)reader["competition_id"]); p.Components = GetPredictionComponents(p.ID); p.Checked = false; foreach (var component in p.Components) { if (component.Checked == true) { p.Points = (int)reader["points"]; p.Checked = true; } } list.Add(p); } return(list); } } catch (SqlException e) { throw e; } } }
public IActionResult Details(int id) { try { DetailsViewModel vm = new DetailsViewModel(); vm.Competition = repo.GetCompetition(id); vm.Drivers = repo.GetDrivers(); ViewBag.Reactions = repo.GetReactions(id); if (vm.Competition.Date < DateTime.Now) { vm.Results = repo.GetResultsFromRace(vm.Competition.ID); } ViewBag.CompetitionData = vm; PredictionViewModel p = new PredictionViewModel(); return(View(p)); } catch (Exception) { return(View("Error")); } }
public ActionResult EditCompetition(long competitionID) { Competition competition = null; if (competitionID > 0) { using (CompetitionRepository repository = new CompetitionRepository()) { competition = repository.GetCompetition(competitionID); if (competition == null) { throw new ApplicationException(string.Format("Unable to retrieve Competition object for competitionID: ", competitionID)); } competition.UseDefaultImage = competition.IsUsingDefaultImage(); competition.CompetitionProgressBars = ControllerHelpers.GetCompetitionProgressBars(repository, competitionID); ViewBag.AllowEdit = (IsUserAdmin || competition.CreatorUserID == UserID); } } else { competition = new Competition() { IsActive = true }; ViewBag.AllowEdit = true; } //if another method redirected to here show the purr message if (TempData[ControllerHelpers.PURR] != null) { ViewBag.Purr = TempData[ControllerHelpers.PURR]; TempData[ControllerHelpers.PURR] = null; } return(View(competition)); }
public ShowStageModel(uint id) { stage = StageRepository.GetStage(id); competition = CompetitionRepository.GetCompetition(stage.Competition_ID); }
public ShowShooterInCompetitionModel(uint shooterId, uint competitionId) { shooter = ShooterRepository.GetShooter(shooterId); competition = CompetitionRepository.GetCompetition(competitionId); }
public ShowCompetitionModel(uint id) { competition = CompetitionRepository.GetCompetition(id); }