protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { aqufitEntities entities = new aqufitEntities(); if (_compWod == null) { _compWod = new CompetitionWOD() { Id = -1 }; } if (_compWod != null) { if (_compType == 2 && ddlTeamPool.Visible) { // team event.. long teamPoolKey = Convert.ToInt64(ddlTeamPool.SelectedValue); IQueryable <CompetitionRegistration2TeamPool> compPoolQuery = entities.CompetitionRegistrations.Where(r => r.CompetitionRegistration2TeamPool.FirstOrDefault(tp => tp.CompetitionTeamPool.Id == teamPoolKey) != null).Select(r => r.CompetitionRegistration2TeamPool.FirstOrDefault(tp => tp.CompetitionTeamPool.Id == teamPoolKey)); // compAthleteQuery = compAthleteQuery.Where(a => a.UserSetting != null); // select captins to eliminate team duplicates.. compPoolQuery = compPoolQuery.OrderBy(a => a.OverallRank); RadGrid1.DataSource = compPoolQuery.Select(a => new { Id = a.CompetitionRegistration.CompetitionAthletes.FirstOrDefault().Id, AthleteName = a.CompetitionRegistration.TeamName, Sex = "", Rank = a.OverallRank, Score = a.OverallScore, WodScore = (a.CompetitionRegistration.CompetitionAthletes.FirstOrDefault().CompetitionWODResults.FirstOrDefault(w => w.CompetitionWOD.Id == _compWod.Id) != null ? a.CompetitionRegistration.CompetitionAthletes.FirstOrDefault().CompetitionWODResults.FirstOrDefault(w => w.CompetitionWOD.Id == _compWod.Id).Score : -1) } ).ToArray(); } else { IQueryable <CompetitionAthlete> compAthleteQuery = entities.CompetitionAthletes.Where(a => a.CompetitionRegistration.CompetitionCategory.Id == _compType && a.Competition.Id == CompetitionKey).OrderBy(a => a.OverallRank); compAthleteQuery = compAthleteQuery.OrderBy(a => a.OverallRank); RadGrid1.DataSource = compAthleteQuery.Select(a => new { Id = a.Id, AthleteName = a.AthleteName, Sex = a.Sex, Rank = a.OverallRank, Score = a.OverallScore, WodScore = (a.CompetitionWODResults.FirstOrDefault(w => w.CompetitionWOD.Id == _compWod.Id) != null ? a.CompetitionWODResults.FirstOrDefault(w => w.CompetitionWOD.Id == _compWod.Id).Score : -1) } ).ToArray(); } } }
protected void bBack_Click(object sender, EventArgs e) { aqufitEntities entities = new aqufitEntities(); IQueryable <CompetitionWOD> compWodsQuery = entities.CompetitionWODs.Include("WOD.WODType").OrderBy(w => w.Order).Where(w => w.Competition.Id == CompetitionKey && w.CompetitionCategory.Id == _compType); CompetitionWOD back = null; long teamPoolKey = 0; if (Request["tp"] != null) { teamPoolKey = Convert.ToInt64(Request["tp"]); compWodsQuery = compWodsQuery.Where(w => w.CompetitionTeamPool.Id == teamPoolKey); } CompetitionWOD[] compWods = compWodsQuery.ToArray(); if (_compWod == null) { back = compWods[compWods.Count() - 1]; } else { foreach (CompetitionWOD cw in compWods) { if (cw.Id == _compWod.Id) { break; } back = cw; } } if (back != null) { Response.Redirect(ResolveUrl("~/Community/CompetitionScoringAdmin") + "?c=" + CompetitionKey + "&w=" + back.Id + "&t=" + _compType + "&tp=" + teamPoolKey, true); } else { Response.Redirect(ResolveUrl("~/Community/CompetitionScoringAdmin") + "?c=" + CompetitionKey + "&w=-2" + "&t=" + _compType + "&tp=" + teamPoolKey, true); } }
protected void bAjaxPostback_Click(object sender, EventArgs e) { try { Affine.Data.Managers.IDataManager dataMan = Affine.Data.Managers.LINQ.DataManager.Instance; aqufitEntities entities = new aqufitEntities(); switch (hiddenAjaxAction.Value) { case "AddWOD": long wodKey = Convert.ToInt64(hiddenAjaxValue.Value); int compType = Convert.ToInt32(hiddenAjaxValue2.Value); long poolKey = 0; if (compType == (int)Affine.Utils.WorkoutUtil.CompetitionCategory.TEAM) { poolKey = Convert.ToInt32(hiddenAjaxValue3.Value); } WOD wod = entities.WODs.Include("WODType").FirstOrDefault(w => w.Id == wodKey); Competition comp = entities.Competitions.Include("CompetitionWODs").FirstOrDefault(c => c.Id == CompetitionKey); if (wod != null && comp != null) { CompetitionWOD compWod = new CompetitionWOD() { WOD = wod, Order = comp.CompetitionWODs.Count, Competition = comp, CompetitionCategory= entities.CompetitionCategories.FirstOrDefault( c => c.Id == compType ), CompetitionTeamPool = entities.CompetitionTeamPools.FirstOrDefault( tp => tp.Id == poolKey ) }; entities.AddToCompetitionWODs(compWod); entities.SaveChanges(); RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.WorkoutFinder.close(); Aqufit.Page.Actions.refreshGrid("+compType+"); "); } break; case "DeleteWOD": long compWodKey = Convert.ToInt64(hiddenAjaxValue.Value); CompetitionWOD compW = entities.CompetitionWODs.Include("CompetitionCategory").FirstOrDefault(c => c.Id == compWodKey && c.Competition.Id == CompetitionKey); if (compW != null) { RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.refreshGrid(" + compW.CompetitionCategory.Id + "); "); entities.DeleteObject(compW); entities.SaveChanges(); // rebuild the order of the workouts now.. CompetitionWOD[] orderList = entities.CompetitionWODs.Where(c => c.Competition.Id == CompetitionKey).OrderBy( c => c.Order ).ToArray(); int order = 0; foreach (CompetitionWOD cw in orderList) { cw.Order = (order++); } entities.SaveChanges(); } break; case "AddTeamPool": string name = Convert.ToString(hiddenAjaxValue.Value); CompetitionTeamPool pool = new CompetitionTeamPool() { Name = name, Competition = entities.Competitions.FirstOrDefault( c => c.Id == CompetitionKey) }; entities.AddToCompetitionTeamPools(pool); entities.SaveChanges(); RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.TeamPoolWin.close(); Aqufit.Page.Actions.refreshTeamPoolGrid(); "); break; case "LoadTeamPool": long tpKey = Convert.ToInt64(hiddenAjaxValue.Value); string[] teamKeyArray = entities.CompetitionRegistrations.Where(r => r.CompetitionRegistration2TeamPool .FirstOrDefault(c => c.CompetitionTeamPool.Id == tpKey) != null) .Select( r => r.Id ).Cast<string>().ToArray(); string jsTeamArray = "[]"; if (teamKeyArray.Length > 0) { jsTeamArray = "[" + teamKeyArray.Aggregate((i, j) => "" + i + "," + j) + "]"; } RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.TeamPoolManagerWin.loadData(" + jsTeamArray + "); "); break; case "SaveTeamPool": long tPoolKey = Convert.ToInt64(hiddenAjaxValue.Value); CompetitionRegistration2TeamPool[] clearArray = entities.CompetitionRegistration2TeamPool.Where(c => c.CompetitionTeamPool.Id == tPoolKey).ToArray(); foreach (CompetitionRegistration2TeamPool clear in clearArray) { entities.DeleteObject(clear); } entities.SaveChanges(); CompetitionTeamPool tpool = entities.CompetitionTeamPools.FirstOrDefault(tp => tp.Id == tPoolKey); foreach (RadListBoxItem item in RadListBoxPoolDest.Items) { long rId = Convert.ToInt64(item.Value); CompetitionRegistration2TeamPool c2t = new CompetitionRegistration2TeamPool() { CompetitionTeamPool = tpool, CompetitionRegistration = entities.CompetitionRegistrations.FirstOrDefault( r => r.Id == rId ) }; entities.AddToCompetitionRegistration2TeamPool(c2t); } entities.SaveChanges(); RadListBoxTeamSource.DataSource = entities.CompetitionRegistrations.Where(r => r.Competition.Id == CompetitionKey && r.CompetitionCategory.Id == (int)Affine.Utils.WorkoutUtil.CompetitionCategory.TEAM).Select(r => new { Name = r.TeamName, Value = r.Id }).ToArray(); RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.TeamPoolManagerWin.close(); Aqufit.Page.Actions.refreshTeamPoolGrid(); "); break; } } catch (Exception ex) { RadAjaxManager1.ResponseScripts.Add("Aqufit.Page.Actions.ShowFail('ERROR: There was a problem with the action (" + ex.StackTrace.Replace("'","").Replace("\r","").Replace("\n","") + ")');"); } }
/// ----------------------------------------------------------------------------- /// <summary> /// Page_Load runs when the control is loaded /// </summary> /// <remarks> /// </remarks> /// <history> /// </history> /// ----------------------------------------------------------------------------- protected void Page_Load(System.Object sender, System.EventArgs e) { base.Page_Load(sender, e); try { aqufitEntities entities = new aqufitEntities(); if (!Page.IsPostBack && !Page.IsCallback) { baseUrl = ResolveUrl("~/"); ServiceReference service = new ServiceReference("~/DesktopModules/ATI_Base/resources/services/StreamService.asmx"); service.InlineScript = true; ScriptManager.GetCurrent(Page).Services.Add(service); if (Request["a"] != null) { ddlCompSelector.Visible = false; scrollPanel.Attributes["class"] = "scrollPanel"; } } if (Settings["ModuleMode"] != null && string.Compare(Convert.ToString(Settings["ModuleMode"]), "admin", true) == 0) { bool isAdmin = false; if (Request["c"] != null) { // TODO: make sure they are a group admin to the comp.. CompetitionKey = Convert.ToInt64(Request["c"]); Competition comp = entities.Competitions.Include("Group").FirstOrDefault(c => c.Id == CompetitionKey); if (comp != null) { UserFriends admin = entities.UserFriends.FirstOrDefault(f => f.SrcUserSettingKey == UserSettings.Id && f.DestUserSettingKey == comp.Group.Id && f.Relationship <= (int)Affine.Utils.ConstsUtil.Relationships.GROUP_ADMIN); if (admin != null) { isAdmin = true; } } } if (!isAdmin) { Response.Redirect(ResolveUrl("~/") + UserSettings.UserName); } if (Request["t"] != null) { _compType = Convert.ToInt64(Request["t"]); } if (Request["s"] != null) { _compSex = Convert.ToChar(Request["s"]); } if (!Page.IsPostBack && !Page.IsCallback) { ddlCompetitionType.DataSource = entities.CompetitionCategories.Select(c => new { Name = c.Category, Value = c.Id }).ToArray(); ddlCompetitionType.DataValueField = "Value"; ddlCompetitionType.DataTextField = "Name"; ddlCompetitionType.DataBind(); ddlCompetitionType.Items.FindByValue("" + _compType).Selected = true; if (_compType == (int)Affine.Utils.WorkoutUtil.CompetitionCategory.TEAM) { ddlTeamPool.Visible = true; ddlTeamPool.DataSource = entities.CompetitionTeamPools.Where(tp => tp.Competition.Id == CompetitionKey).Select(tp => new { Name = tp.Name, Value = tp.Id }).ToArray(); ddlTeamPool.DataValueField = "Value"; ddlTeamPool.DataTextField = "Name"; ddlTeamPool.DataBind(); if (Request["tp"] != null) { ddlTeamPool.Items.FindByValue(Request["tp"]).Selected = true; } } else { ddlTeamPool.Visible = false; } panelAdmin.Visible = true; panelLiveScore.Visible = false; // ok so at this point we know that they are an admin for the comp... // now lets find what workout they are scoring IQueryable <CompetitionWOD> compWodQuery = entities.CompetitionWODs.OrderBy(w => w.Order).Where(w => w.Competition.Id == CompetitionKey && w.CompetitionCategory.Id == _compType); if (_compType == (int)Affine.Utils.WorkoutUtil.CompetitionCategory.TEAM) { long teamPoolKey = Convert.ToInt64(ddlTeamPool.SelectedValue); compWodQuery = compWodQuery.Where(w => w.CompetitionTeamPool.Id == teamPoolKey); } CompetitionWOD compWod = compWodQuery.Where(c => c.CompetitionWODResults.Count() > 0).Select(w => w).ToArray().Reverse().FirstOrDefault(); if (compWod == null) { compWod = compWodQuery.FirstOrDefault(); } if (Request["w"] != null) { long cwId = Convert.ToInt64(Request["w"]); if (cwId == -1) { // this is now a final scoring.. bAdvance.Visible = false; litWodName.Text = "Final Score<span style=\"padding-right: 150px;\"> </span>"; hiddenCompWodKey.Value = "-1"; return; } else if (cwId == -2) { // allow this to fall through and setup first wod.. bBack.Visible = false; cwId = compWod.Id; } compWod = entities.CompetitionWODs.FirstOrDefault(w => w.Id == cwId); } if (compWod == null) { // TODO: send a message that they need to setup some workouts.. } hiddenCompWodKey.Value = "" + compWod.Id; } long comWodKey = Convert.ToInt64(hiddenCompWodKey.Value); _compWod = entities.CompetitionWODs.Include("WOD").Include("WOD.WODType").FirstOrDefault(w => w.Competition.Id == CompetitionKey && w.Id == comWodKey); if (_compWod != null) { litWodName.Text = "" + _compWod.WOD.Name; } } else { // Live Score board... if (!Page.IsPostBack && !Page.IsCallback) { if (Request["c"] != null) { CompetitionKey = Convert.ToInt64(Request["c"]); } hiddenAjaxCompCategoryKey.Value = "" + (int)Affine.Utils.WorkoutUtil.CompetitionCategory.IND_MALE; hiddenTeamPoolKey.Value = "0"; CompetitionTeamPool[] teamPools = entities.CompetitionTeamPools.Where(p => p.Competition.Id == CompetitionKey).ToArray(); ddlCompSelector.Items.Add(new ListItem() { Text = "Individual - Mens", Value = "{cat:1, tp:0}" }); ddlCompSelector.Items.Add(new ListItem() { Text = "Individual - Womens", Value = "{cat:3, tp:0}" }); int ind = 0; foreach (CompetitionTeamPool team in teamPools) { ddlCompSelector.Items.Add(new ListItem() { Text = "Team - " + team.Name, Value = "{cat:2, tp:" + (ind++) + "}" }); } } } } catch (Exception exc) //Module failed to load { Exceptions.ProcessModuleLoadException(this, exc); } }
protected void bAdvance_Click(object sender, EventArgs e) { aqufitEntities entities = new aqufitEntities(); IQueryable <CompetitionWOD> compWodQuery = entities.CompetitionWODs.Include("WOD.WODType").OrderBy(w => w.Order).Where(w => w.Competition.Id == CompetitionKey && w.CompetitionCategory.Id == _compType); IQueryable <CompetitionAthlete> athleteQuery = entities.CompetitionAthletes.Where(a => a.Competition.Id == CompetitionKey && a.CompetitionRegistration.CompetitionCategory.Id == _compType); long teamPool = 0; if (_compType == (int)Affine.Utils.WorkoutUtil.CompetitionCategory.TEAM) { teamPool = Convert.ToInt64(ddlTeamPool.SelectedValue); // TODO: here is this super lame "captin" check again with a.UserSetting != null athleteQuery = athleteQuery.Where(a => a.UserSetting != null && a.CompetitionRegistration.CompetitionRegistration2TeamPool.FirstOrDefault(tp => tp.CompetitionTeamPool.Id == teamPool) != null); compWodQuery = compWodQuery.Where(w => w.CompetitionTeamPool.Id == teamPool); } CompetitionWOD[] compWods = compWodQuery.ToArray(); CompetitionAthlete[] athletes = athleteQuery.ToArray(); foreach (CompetitionAthlete athlete in athletes) { athlete.OverallScore = 0; athlete.OverallRank = 0; } entities.SaveChanges(); CompetitionWOD next = null; double lastScore = 0; for (int i = 0; i < compWods.Length; i++) { CompetitionWOD cwod = compWods[i]; IQueryable <CompetitionWODResult> resultQuery = entities.CompetitionWODResults.Include("CompetitionAthlete").Where(w => w.CompetitionWOD.Id == cwod.Id); if (cwod.WOD.WODType.Id == (int)Affine.Utils.WorkoutUtil.WodType.TIMED) { resultQuery = resultQuery.OrderBy(w => w.Score); } else { resultQuery = resultQuery.OrderByDescending(w => w.Score); } int score = 1; int inc = 1; foreach (CompetitionWODResult res in resultQuery) { if (res.Score != lastScore) { score = inc; res.Rank = score; res.CompetitionAthlete.OverallScore += score; } else { res.Rank = score; res.CompetitionAthlete.OverallScore += score; } lastScore = res.Score; inc++; } // TODO: will need to add the POINTS to this as well CompetitionAthlete[] dnf = athletes.Except(resultQuery.Select(w => w.CompetitionAthlete).ToArray()).ToArray(); foreach (CompetitionAthlete athlete in dnf) { athlete.OverallScore += score; } if (cwod.Id == _compWod.Id) { if ((i + 1) < compWods.Length) { next = compWods[i + 1]; } break; } } entities.SaveChanges(); IQueryable <CompetitionAthlete> athleteRankerQuery = entities.CompetitionAthletes.Where(a => a.Competition.Id == CompetitionKey && a.CompetitionRegistration.CompetitionCategory.Id == _compType).OrderBy(a => a.OverallScore); double lastRank = 0; int rank = 1; int count = 1; IDictionary <long, CompetitionRegistration2TeamPool> hash = new Dictionary <long, CompetitionRegistration2TeamPool>(); if (_compType == (int)Affine.Utils.WorkoutUtil.CompetitionCategory.TEAM) { // TODO: this a.UserSetting != null (sux) .. it is the way of determining the captin on the team.. and thus a single team element. athleteRankerQuery = athleteRankerQuery.Where(a => a.CompetitionRegistration.CompetitionRegistration2TeamPool.FirstOrDefault(tp => tp.CompetitionTeamPool.Id == teamPool) != null && a.UserSetting != null); CompetitionRegistration2TeamPool[] teamArray = entities.CompetitionRegistration2TeamPool.Include("CompetitionRegistration.CompetitionAthletes").Where(r2t => r2t.CompetitionTeamPool.Id == teamPool).ToArray(); foreach (CompetitionRegistration2TeamPool team in teamArray) { hash.Add(new KeyValuePair <long, CompetitionRegistration2TeamPool>(team.CompetitionRegistration.CompetitionAthletes.First().Id, team)); } } CompetitionAthlete[] athleteRanker = athleteRankerQuery.ToArray(); foreach (CompetitionAthlete athlete in athleteRanker) { if (lastRank != athlete.OverallScore) { rank = count; athlete.OverallRank = rank++; } else { athlete.OverallRank = rank - 1; } lastRank = athlete.OverallScore; count++; if (hash.ContainsKey(athlete.Id)) { hash[athlete.Id].OverallRank = athlete.OverallRank; hash[athlete.Id].OverallScore = athlete.OverallScore; } } entities.SaveChanges(); if (next != null) { Response.Redirect(ResolveUrl("~/Community/CompetitionScoringAdmin") + "?c=" + CompetitionKey + "&w=" + next.Id + "&t=" + _compType + "&tp=" + teamPool, true); } else { Response.Redirect(ResolveUrl("~/Community/CompetitionScoringAdmin") + "?c=" + CompetitionKey + "&w=-1" + "&t=" + _compType + "&tp=" + teamPool, true); } }
protected void bAjaxPostback_Click(object sender, EventArgs e) { try { Affine.Data.Managers.IDataManager dataMan = Affine.Data.Managers.LINQ.DataManager.Instance; aqufitEntities entities = new aqufitEntities(); switch (hiddenAjaxAction.Value) { case "updateAthleteScore": CompetitionWODResult res = null; try { long compAthlete = Convert.ToInt64(hiddenAjaxValue.Value); long compWodKey = Convert.ToInt64(hiddenCompWodKey.Value); CompetitionAthlete athlete = entities.CompetitionAthletes.FirstOrDefault(a => a.Id == compAthlete && a.Competition.Id == CompetitionKey); CompetitionWOD compWod = entities.CompetitionWODs.Include("WOD").Include("WOD.WODType").FirstOrDefault(w => w.Id == compWodKey && w.Competition.Id == CompetitionKey && w.CompetitionCategory.Id == _compType); // check if we have a score yet.. if (athlete != null && compWod != null) { res = entities.CompetitionWODResults.FirstOrDefault(r => r.CompetitionAthlete.Id == compAthlete && r.CompetitionWOD.Id == compWodKey); double score = 0; if (compWod.WOD.WODType.Id == (int)Affine.Utils.WorkoutUtil.WodType.TIMED) { string[] ts = hiddenAjaxValue2.Value.Split(':'); double seconds = 0.0; if (ts.Length == 3) { seconds = Convert.ToDouble(ts[0]) * 60 * 60 + Convert.ToDouble(ts[1]) * 60 + Convert.ToDouble(ts[2]); } else if (ts.Length == 2) { seconds = Convert.ToDouble(ts[0]) * 60 + Convert.ToDouble(ts[1]); } else if (ts.Length == 1) { seconds = Convert.ToDouble(ts[0]); } else { seconds = Convert.ToDouble(hiddenAjaxValue2.Value); } score = Affine.Utils.UnitsUtil.unitsToSystemDefualt(seconds, UnitsUtil.MeasureUnit.UNIT_SEC); // TODO: switch between units.. } else if (compWod.WOD.WODType.Id == (int)Affine.Utils.WorkoutUtil.WodType.MAX_WEIGHT) { score = Convert.ToDouble(hiddenAjaxValue2.Value); score = Affine.Utils.UnitsUtil.unitsToSystemDefualt(score, UnitsUtil.MeasureUnit.UNIT_LBS); // TODO: switch between units.. } else { score = Convert.ToDouble(hiddenAjaxValue2.Value); } if (res == null) { res = new CompetitionWODResult() { CompetitionWOD = compWod, CompetitionAthlete = athlete, WOD = compWod.WOD }; } res.Score = score; entities.SaveChanges(); } } catch (Exception) { if (res != null) { entities.DeleteObject(res); entities.SaveChanges(); } } break; } } catch (Exception ex) { RadAjaxManager1.ResponseScripts.Add("Aqufit.Page.Actions.ShowFail('ERROR: There was a problem with the action (" + ex.StackTrace.Replace("'", "").Replace("\r", "").Replace("\n", "") + ")');"); } }
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { aqufitEntities entities = new aqufitEntities(); if (_compWod == null) { _compWod = new CompetitionWOD() { Id = -1 }; } if (_compWod != null) { if (_compType == 2 && ddlTeamPool.Visible) { // team event.. long teamPoolKey = Convert.ToInt64(ddlTeamPool.SelectedValue); IQueryable<CompetitionRegistration2TeamPool> compPoolQuery = entities.CompetitionRegistrations.Where(r => r.CompetitionRegistration2TeamPool.FirstOrDefault(tp => tp.CompetitionTeamPool.Id == teamPoolKey) != null).Select(r => r.CompetitionRegistration2TeamPool.FirstOrDefault(tp => tp.CompetitionTeamPool.Id == teamPoolKey)); // compAthleteQuery = compAthleteQuery.Where(a => a.UserSetting != null); // select captins to eliminate team duplicates.. compPoolQuery = compPoolQuery.OrderBy(a => a.OverallRank); RadGrid1.DataSource = compPoolQuery.Select(a => new { Id = a.CompetitionRegistration.CompetitionAthletes.FirstOrDefault().Id, AthleteName = a.CompetitionRegistration.TeamName, Sex = "", Rank = a.OverallRank, Score = a.OverallScore, WodScore = (a.CompetitionRegistration.CompetitionAthletes.FirstOrDefault().CompetitionWODResults.FirstOrDefault(w => w.CompetitionWOD.Id == _compWod.Id) != null ? a.CompetitionRegistration.CompetitionAthletes.FirstOrDefault().CompetitionWODResults.FirstOrDefault(w => w.CompetitionWOD.Id == _compWod.Id).Score : -1) } ).ToArray(); } else { IQueryable<CompetitionAthlete> compAthleteQuery = entities.CompetitionAthletes.Where(a => a.CompetitionRegistration.CompetitionCategory.Id == _compType && a.Competition.Id == CompetitionKey ).OrderBy(a => a.OverallRank); compAthleteQuery = compAthleteQuery.OrderBy(a => a.OverallRank); RadGrid1.DataSource = compAthleteQuery.Select(a => new { Id = a.Id, AthleteName = a.AthleteName, Sex = a.Sex, Rank = a.OverallRank, Score = a.OverallScore, WodScore = (a.CompetitionWODResults.FirstOrDefault(w => w.CompetitionWOD.Id == _compWod.Id) != null ? a.CompetitionWODResults.FirstOrDefault(w => w.CompetitionWOD.Id == _compWod.Id).Score : -1) } ).ToArray(); } } }
/// ----------------------------------------------------------------------------- /// <summary> /// Page_Load runs when the control is loaded /// </summary> /// <remarks> /// </remarks> /// <history> /// </history> /// ----------------------------------------------------------------------------- protected void Page_Load(System.Object sender, System.EventArgs e) { base.Page_Load(sender, e); try { aqufitEntities entities = new aqufitEntities(); if (!Page.IsPostBack && !Page.IsCallback) { baseUrl = ResolveUrl("~/"); ServiceReference service = new ServiceReference("~/DesktopModules/ATI_Base/resources/services/StreamService.asmx"); service.InlineScript = true; ScriptManager.GetCurrent(Page).Services.Add(service); if (Request["a"] != null) { ddlCompSelector.Visible = false; scrollPanel.Attributes["class"] = "scrollPanel"; } } if (Settings["ModuleMode"] != null && string.Compare(Convert.ToString( Settings["ModuleMode"]), "admin", true) == 0) { bool isAdmin = false; if (Request["c"] != null) { // TODO: make sure they are a group admin to the comp.. CompetitionKey = Convert.ToInt64(Request["c"]); Competition comp = entities.Competitions.Include("Group").FirstOrDefault(c => c.Id == CompetitionKey); if (comp != null) { UserFriends admin = entities.UserFriends.FirstOrDefault(f => f.SrcUserSettingKey == UserSettings.Id && f.DestUserSettingKey == comp.Group.Id && f.Relationship <= (int)Affine.Utils.ConstsUtil.Relationships.GROUP_ADMIN); if (admin != null) { isAdmin = true; } } } if (!isAdmin) { Response.Redirect(ResolveUrl("~/") + UserSettings.UserName); } if (Request["t"] != null) { _compType = Convert.ToInt64(Request["t"]); } if (Request["s"] != null) { _compSex = Convert.ToChar(Request["s"]); } if (!Page.IsPostBack && !Page.IsCallback) { ddlCompetitionType.DataSource = entities.CompetitionCategories.Select(c => new { Name = c.Category, Value = c.Id }).ToArray(); ddlCompetitionType.DataValueField = "Value"; ddlCompetitionType.DataTextField = "Name"; ddlCompetitionType.DataBind(); ddlCompetitionType.Items.FindByValue("" + _compType).Selected = true; if (_compType == (int)Affine.Utils.WorkoutUtil.CompetitionCategory.TEAM) { ddlTeamPool.Visible = true; ddlTeamPool.DataSource = entities.CompetitionTeamPools.Where(tp => tp.Competition.Id == CompetitionKey).Select(tp => new { Name = tp.Name, Value = tp.Id }).ToArray(); ddlTeamPool.DataValueField = "Value"; ddlTeamPool.DataTextField = "Name"; ddlTeamPool.DataBind(); if (Request["tp"] != null) { ddlTeamPool.Items.FindByValue(Request["tp"]).Selected = true; } } else { ddlTeamPool.Visible = false; } panelAdmin.Visible = true; panelLiveScore.Visible = false; // ok so at this point we know that they are an admin for the comp... // now lets find what workout they are scoring IQueryable<CompetitionWOD> compWodQuery = entities.CompetitionWODs.OrderBy(w => w.Order).Where(w => w.Competition.Id == CompetitionKey && w.CompetitionCategory.Id == _compType); if (_compType == (int)Affine.Utils.WorkoutUtil.CompetitionCategory.TEAM) { long teamPoolKey = Convert.ToInt64( ddlTeamPool.SelectedValue ); compWodQuery = compWodQuery.Where(w => w.CompetitionTeamPool.Id == teamPoolKey); } CompetitionWOD compWod = compWodQuery.Where(c => c.CompetitionWODResults.Count() > 0).Select( w => w).ToArray().Reverse().FirstOrDefault(); if (compWod == null) { compWod = compWodQuery.FirstOrDefault(); } if (Request["w"] != null) { long cwId = Convert.ToInt64(Request["w"]); if (cwId == -1) { // this is now a final scoring.. bAdvance.Visible = false; litWodName.Text = "Final Score<span style=\"padding-right: 150px;\"> </span>"; hiddenCompWodKey.Value = "-1"; return; } else if (cwId == -2) { // allow this to fall through and setup first wod.. bBack.Visible = false; cwId = compWod.Id; } compWod = entities.CompetitionWODs.FirstOrDefault(w => w.Id == cwId); } if (compWod == null) { // TODO: send a message that they need to setup some workouts.. } hiddenCompWodKey.Value = "" + compWod.Id; } long comWodKey = Convert.ToInt64(hiddenCompWodKey.Value); _compWod = entities.CompetitionWODs.Include("WOD").Include("WOD.WODType").FirstOrDefault(w => w.Competition.Id == CompetitionKey && w.Id == comWodKey ); if (_compWod != null) { litWodName.Text = "" + _compWod.WOD.Name; } } else { // Live Score board... if (!Page.IsPostBack && !Page.IsCallback) { if (Request["c"] != null) { CompetitionKey = Convert.ToInt64(Request["c"]); } hiddenAjaxCompCategoryKey.Value = "" + (int)Affine.Utils.WorkoutUtil.CompetitionCategory.IND_MALE; hiddenTeamPoolKey.Value = "0"; CompetitionTeamPool[] teamPools = entities.CompetitionTeamPools.Where(p => p.Competition.Id == CompetitionKey).ToArray(); ddlCompSelector.Items.Add(new ListItem() { Text = "Individual - Mens", Value = "{cat:1, tp:0}" }); ddlCompSelector.Items.Add(new ListItem() { Text = "Individual - Womens", Value = "{cat:3, tp:0}" }); int ind = 0; foreach (CompetitionTeamPool team in teamPools) { ddlCompSelector.Items.Add(new ListItem() { Text = "Team - " + team.Name, Value = "{cat:2, tp:" + (ind++) + "}" }); } } } } catch (Exception exc) //Module failed to load { Exceptions.ProcessModuleLoadException(this, exc); } }
protected void bAjaxPostback_Click(object sender, EventArgs e) { try { Affine.Data.Managers.IDataManager dataMan = Affine.Data.Managers.LINQ.DataManager.Instance; aqufitEntities entities = new aqufitEntities(); switch (hiddenAjaxAction.Value) { case "AddWOD": long wodKey = Convert.ToInt64(hiddenAjaxValue.Value); int compType = Convert.ToInt32(hiddenAjaxValue2.Value); long poolKey = 0; if (compType == (int)Affine.Utils.WorkoutUtil.CompetitionCategory.TEAM) { poolKey = Convert.ToInt32(hiddenAjaxValue3.Value); } WOD wod = entities.WODs.Include("WODType").FirstOrDefault(w => w.Id == wodKey); Competition comp = entities.Competitions.Include("CompetitionWODs").FirstOrDefault(c => c.Id == CompetitionKey); if (wod != null && comp != null) { CompetitionWOD compWod = new CompetitionWOD() { WOD = wod, Order = comp.CompetitionWODs.Count, Competition = comp, CompetitionCategory = entities.CompetitionCategories.FirstOrDefault(c => c.Id == compType), CompetitionTeamPool = entities.CompetitionTeamPools.FirstOrDefault(tp => tp.Id == poolKey) }; entities.AddToCompetitionWODs(compWod); entities.SaveChanges(); RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.WorkoutFinder.close(); Aqufit.Page.Actions.refreshGrid(" + compType + "); "); } break; case "DeleteWOD": long compWodKey = Convert.ToInt64(hiddenAjaxValue.Value); CompetitionWOD compW = entities.CompetitionWODs.Include("CompetitionCategory").FirstOrDefault(c => c.Id == compWodKey && c.Competition.Id == CompetitionKey); if (compW != null) { RadAjaxManager1.ResponseScripts.Add(" Aqufit.Page.Actions.refreshGrid(" + compW.CompetitionCategory.Id + "); "); entities.DeleteObject(compW); entities.SaveChanges(); // rebuild the order of the workouts now.. CompetitionWOD[] orderList = entities.CompetitionWODs.Where(c => c.Competition.Id == CompetitionKey).OrderBy(c => c.Order).ToArray(); int order = 0; foreach (CompetitionWOD cw in orderList) { cw.Order = (order++); } entities.SaveChanges(); } break; case "AddTeamPool": string name = Convert.ToString(hiddenAjaxValue.Value); CompetitionTeamPool pool = new CompetitionTeamPool() { Name = name, Competition = entities.Competitions.FirstOrDefault(c => c.Id == CompetitionKey) }; entities.AddToCompetitionTeamPools(pool); entities.SaveChanges(); RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.TeamPoolWin.close(); Aqufit.Page.Actions.refreshTeamPoolGrid(); "); break; case "LoadTeamPool": long tpKey = Convert.ToInt64(hiddenAjaxValue.Value); string[] teamKeyArray = entities.CompetitionRegistrations.Where(r => r.CompetitionRegistration2TeamPool .FirstOrDefault(c => c.CompetitionTeamPool.Id == tpKey) != null) .Select(r => r.Id).Cast <string>().ToArray(); string jsTeamArray = "[]"; if (teamKeyArray.Length > 0) { jsTeamArray = "[" + teamKeyArray.Aggregate((i, j) => "" + i + "," + j) + "]"; } RadAjaxManager1.ResponseScripts.Add("Aqufit.Windows.TeamPoolManagerWin.loadData(" + jsTeamArray + "); "); break; case "SaveTeamPool": long tPoolKey = Convert.ToInt64(hiddenAjaxValue.Value); CompetitionRegistration2TeamPool[] clearArray = entities.CompetitionRegistration2TeamPool.Where(c => c.CompetitionTeamPool.Id == tPoolKey).ToArray(); foreach (CompetitionRegistration2TeamPool clear in clearArray) { entities.DeleteObject(clear); } entities.SaveChanges(); CompetitionTeamPool tpool = entities.CompetitionTeamPools.FirstOrDefault(tp => tp.Id == tPoolKey); foreach (RadListBoxItem item in RadListBoxPoolDest.Items) { long rId = Convert.ToInt64(item.Value); CompetitionRegistration2TeamPool c2t = new CompetitionRegistration2TeamPool() { CompetitionTeamPool = tpool, CompetitionRegistration = entities.CompetitionRegistrations.FirstOrDefault(r => r.Id == rId) }; entities.AddToCompetitionRegistration2TeamPool(c2t); } entities.SaveChanges(); RadListBoxTeamSource.DataSource = entities.CompetitionRegistrations.Where(r => r.Competition.Id == CompetitionKey && r.CompetitionCategory.Id == (int)Affine.Utils.WorkoutUtil.CompetitionCategory.TEAM).Select(r => new { Name = r.TeamName, Value = r.Id }).ToArray(); RadAjaxManager1.ResponseScripts.Add(" Aqufit.Windows.TeamPoolManagerWin.close(); Aqufit.Page.Actions.refreshTeamPoolGrid(); "); break; } } catch (Exception ex) { RadAjaxManager1.ResponseScripts.Add("Aqufit.Page.Actions.ShowFail('ERROR: There was a problem with the action (" + ex.StackTrace.Replace("'", "").Replace("\r", "").Replace("\n", "") + ")');"); } }