private List <StandingDto> GetPrivateTournamentStanding(Ext_PrivateTournament pvtTournament) { using (var db = Global.GetConnection()) { var standing = from ptp in db.Ext_PrivateTournamentParticipant where ptp.PrivateTournamentGUID == pvtTournament.GUID && (ptp.IsAccepted ?? false) && (ptp.Inti_Team.IsActive ?? false) && (ptp.Inti_Team.IsPaid ?? false) select new StandingDto { GUID = ptp.Inti_Team.GUID, TeamName = ptp.Inti_Team.Name, Manager = ptp.Inti_Team.Sys_User.FirstName + " " + ptp.Inti_Team.Sys_User.LastName, Points = (ptp.Inti_Team.Inti_TeamPointEvents.Where(tpe => ((pvtTournament.IsLimitedInTime ?? false) && tpe.Inti_MatchPointEvent.Inti_Match.MatchDate >= pvtTournament.StartDate && tpe.Inti_MatchPointEvent.Inti_Match.MatchDate <= (pvtTournament.EndDate ?? tpe.Inti_MatchPointEvent.Inti_Match.MatchDate)) || (!(pvtTournament.IsLimitedInTime ?? false) && tpe.Inti_MatchPointEvent.Inti_Match.TourDay >= (pvtTournament.StartDay ?? tpe.Inti_MatchPointEvent.Inti_Match.TourDay) && tpe.Inti_MatchPointEvent.Inti_Match.TourDay <= (pvtTournament.EndDay ?? tpe.Inti_MatchPointEvent.Inti_Match.TourDay))) .Count() > 0 ? ((ptp.Inti_Team.Inti_TeamPointEvents.Where(tpe => ((pvtTournament.IsLimitedInTime ?? false) && tpe.Inti_MatchPointEvent.Inti_Match.MatchDate >= pvtTournament.StartDate && tpe.Inti_MatchPointEvent.Inti_Match.MatchDate <= (pvtTournament.EndDate ?? tpe.Inti_MatchPointEvent.Inti_Match.MatchDate)) || (!(pvtTournament.IsLimitedInTime ?? false) && tpe.Inti_MatchPointEvent.Inti_Match.TourDay >= (pvtTournament.StartDay ?? tpe.Inti_MatchPointEvent.Inti_Match.TourDay) && tpe.Inti_MatchPointEvent.Inti_Match.TourDay <= (pvtTournament.EndDay ?? tpe.Inti_MatchPointEvent.Inti_Match.TourDay))) .Sum(tpe => tpe.Inti_MatchPointEvent.Points))) : 0) }; return(standing.OrderByDescending(x => x.Points).ToList()); } }
/// <summary> /// Load the standing of a private tournamnet /// </summary> /// <param name="pvtTournament"></param> public void LoadPrivateTournamentStanding(Ext_PrivateTournament pvtTournament) { using (var db = Global.GetConnection()) { lblHeader.Text = pvtTournament.Name; var description = Server.HtmlEncode(pvtTournament.Description).Replace("\n", "<BR/>"); description += " "; description += (pvtTournament.IsLimitedInTime ?? false) ? String.Format("Gäller matcher mellan {0} och {1}", (pvtTournament.StartDate ?? SessionProps.SelectedTournament.EndRegistration).ToShortDateString(), (pvtTournament.EndDate ?? SessionProps.SelectedTournament.EndRegistration.AddYears(1)) .ToShortDateString()) : String.Format("Gäller matcher mellan omgång {0} och {1}", (pvtTournament.StartDay ?? 1), (pvtTournament.EndDay ?? SessionProps.SelectedTournament.NmbrOfDays)); lblDescription.Text = description.Trim(); BindStanding(GetPrivateTournamentStanding(pvtTournament)); } }
protected void btnSave_Click(object sender, EventArgs e) { //validering //måste ha ett namn if (Name.Text.Trim().Length == 0) { lblMessage.Text = "Din utmaning måste ha ett namn"; return; } DateTime startDate = DateTime.Now; DateTime endDate = DateTime.Now; //om datumavgränsning, måste vara giltiga datum if (rblDateLimitation.SelectedValue == "datum") { if (!DateTime.TryParse(StartDate.Text, out startDate)) { lblMessage.Text = "Startdatum måste vara ett giltigt datum"; return; } if (!DateTime.TryParse(EndDate.Text, out endDate)) { lblMessage.Text = "Slutdatum måste vara ett giltigt datum"; return; } if (startDate >= endDate) { lblMessage.Text = "Startdatum måste vara före slutdatum"; return; } } //insert or update? var tournamentGUID = this.GetRedirectParameter("tournamentGUID", false); if (tournamentGUID == null) { //insert using (var db = Global.GetConnection()) { var myTournament = new Ext_PrivateTournament(); myTournament.UserGUID = SessionProps.UserGuid; myTournament.TournamentGUID = SessionProps.SelectedTournament.GUID; myTournament.Name = Name.Text; myTournament.Description = Description.Text; myTournament.IsVisibleForAll = IsVisibleForAll.Checked; myTournament.IsOpenForAll = false; if (rblDateLimitation.SelectedValue == "datum") { myTournament.IsLimitedInTime = true; myTournament.StartDate = startDate; myTournament.EndDate = endDate; } else { myTournament.IsLimitedInTime = false; myTournament.StartDay = drpStartDay.SelectedIndex + 1; myTournament.EndDay = drpEndDay.SelectedIndex + 1; } db.Ext_PrivateTournament.InsertOnSubmit(myTournament); db.SubmitChanges(); WebControlManager.RedirectWithQueryString("MyTournamentEdit.aspx", new string[] { "tournamentGUID" }, new string[] { myTournament.GUID.ToString() }); } } else { using (var db = Global.GetConnection()) { var myTournament = db.Ext_PrivateTournament.Single(t => t.GUID == new Guid(tournamentGUID.ToString())); myTournament.Name = Name.Text; myTournament.Description = Description.Text; myTournament.IsVisibleForAll = IsVisibleForAll.Checked; if (rblDateLimitation.SelectedValue == "datum") { myTournament.IsLimitedInTime = true; myTournament.StartDate = startDate; myTournament.EndDate = endDate; } else { myTournament.IsLimitedInTime = false; myTournament.StartDay = drpStartDay.SelectedIndex + 1; myTournament.EndDay = drpEndDay.SelectedIndex + 1; } db.SubmitChanges(); } } }