protected void Page_Load(object sender, EventArgs e) { if (Request.IsAuthenticated) { int opponentId = Convert.ToInt32(Request.QueryString["opponentId"]); int matchId = Convert.ToInt32(Request.QueryString["matchId"]); matchIdHiddenField.Value = matchId.ToString(); opponentIdHiddenField.Value = opponentId.ToString(); if (!Page.IsPostBack) { using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext()) { ISingleResult <SelectUserPublicProfileResult> users = dataContext.SelectUserPublicProfile(opponentId); SelectUserPublicProfileResult user = users.First(); ISingleResult <SelectMatchResult> matches = dataContext.SelectMatch(matchId); SelectMatchResult match = matches.First(); ISingleResult <SelectMatchPointLogsByMatchIdResult> matchResults = dataContext.SelectMatchPointLogsByMatchId(matchId); SelectMatchPointLogsByMatchIdResult matchResult = matchResults.First(); string winner = string.Empty; if (matchResult.UserId == StoredData.User.UserId) { if (matchResult.Win) { winner = StoredData.User.FirstName + " " + StoredData.User.LastName; } else { winner = user.FirstName + " " + user.LastName; } } else { if (matchResult.Win) { winner = user.FirstName + " " + user.LastName; } else { winner = StoredData.User.FirstName + " " + StoredData.User.LastName; } } matchLabel.Text = string.Format("{0} vs {1} on {2} {3}. Winner: {4} ({5})", StoredData.User.FirstName + " " + StoredData.User.LastName, user.FirstName + " " + user.LastName, match.MatchDate.ToShortDateString(), match.MatchDate.ToShortTimeString(), winner, match.Score); ISingleResult <SelectMatchPointLogsByMatchIdUserIdResult> ratings = dataContext.SelectMatchPointLogsByMatchIdUserId(matchId, StoredData.User.UserId); SelectMatchPointLogsByMatchIdUserIdResult rating = ratings.First(); ownBackhandRadSlider.Value = rating.OwnBackhand.Value; ownCourtCoverageRadSlider.Value = rating.OwnCourtCoverage.Value; ownDropRadSlider.Value = rating.OwnDrop.Value; ownForehandRadSlider.Value = rating.OwnForehand.Value; ownOverheadRadSlider.Value = rating.OwnOverhead.Value; ownServeRadSlider.Value = rating.OwnServe.Value; ownVolleyRadSlider.Value = rating.OwnVolley.Value; opponentBackhandRadSlider.Value = rating.OpponentBackhand.Value; opponentCourtCoverageRadSlider.Value = rating.OpponentCourtCoverage.Value; opponentDropRadSlider.Value = rating.OpponentDrop.Value; opponentForehandRadSlider.Value = rating.OpponentForehand.Value; opponentOverheadRadSlider.Value = rating.OpponentOverhead.Value; opponentServeRadSlider.Value = rating.OpponentServe.Value; opponentVolleyRadSlider.Value = rating.OpponentVolley.Value; } } } }
protected void Schedule_AjaxRequest(object sender, AjaxRequestEventArgs e) { List <DLL.Appointment> appointments = new List <DLL.Appointment>(); if (e.Argument == "RefreshScheduler") { bool opponentAvailabilitySet = false; if (playersRadGrid.SelectedItems.Count > 0) { int opponentId = Convert.ToInt32(playersRadGrid.SelectedItems[0].OwnerTableView.DataKeyValues[playersRadGrid.SelectedItems[0].ItemIndex]["UserId"]); appointments = GetAppointments(StoredData.User.UserId, opponentId, out opponentAvailabilitySet); } else { appointments = GetAppointments(StoredData.User.UserId, -1, out opponentAvailabilitySet); } } else if (e.Argument == "DeleteSchedule") { if (ViewState["DeletedAppointment"] != null) { Telerik.Web.UI.Appointment deletedAppointment = (Telerik.Web.UI.Appointment)ViewState["DeletedAppointment"]; using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext()) { //Find match by the deleted appointment id List <SelectMatchByAppointmentIdResult> selectMatchByAppointmentIdResult = dataContext.SelectMatchByAppointmentId(Convert.ToInt32(deletedAppointment.ID)).ToList(); int?matchId = null; //If there are matches by the appointment id if (selectMatchByAppointmentIdResult.Count > 0) { int opponentId = 0; matchId = selectMatchByAppointmentIdResult[0].MatchId; if (selectMatchByAppointmentIdResult[0].User1 == StoredData.User.UserId) { opponentId = selectMatchByAppointmentIdResult[0].User2.Value; } else { opponentId = selectMatchByAppointmentIdResult[0].User1.Value; } //If a score has already been submitted for the match, then don't delete it. Else delete it. List <SelectMatchPointLogsByMatchIdResult> selectMatchPointLogsByMatchIdResult = dataContext.SelectMatchPointLogsByMatchId(Convert.ToInt32(matchId)).ToList(); if (selectMatchPointLogsByMatchIdResult.Count > 0) { RadAjaxManager.GetCurrent(Page).ResponseScripts.Add(@"radalert('A score has been submitted for this match.<br>This match cannot be deleted.',250,150,'Unable To Delete');"); } else { dataContext.DeleteAppointmentsByMatchId(matchId); //Send email List <SelectUserPublicProfileResult> opponents = dataContext.SelectUserPublicProfile(opponentId).ToList(); StringBuilder message = new StringBuilder(); message.Append("Your opponent has requested the following match to be cancelled\r\n\r\n"); message.Append(string.Format("Players: {0} vs {1}\r\n", StoredData.User.FirstName + " " + StoredData.User.LastName, opponents[0].FirstName + " " + opponents[0].LastName)); message.Append(string.Format("Date & Time: {0} @ {1}\r\n", deletedAppointment.Start.ToShortDateString(), deletedAppointment.Start.ToShortTimeString())); message.Append(string.Format("Your opponent's Phone Number: {0}\r\n", StoredData.User.Phone)); message.Append(string.Format("Your opponent's Email Id: {0}\r\n\r\n", StoredData.User.EmailId)); message.Append("Please respond to this request as soon as you can"); if (!SendEmail(opponents[0].EmailId, message, "Tennis Match cancellation request")) { RadAjaxManager.GetCurrent(Page).ResponseScripts.Add(@"radalert('System was unable to send an email to your opponent about this change<br>Please contact your opponent regarding this update.',250,150,'Error!!');"); } else { RadAjaxManager.GetCurrent(Page).ResponseScripts.Add(@"radalert('Although an email has been sent requesting the cancellation of this match, please contact your opponent to confirm.',250,150,'Match Cancelled!!');"); } } } } } } else { string[] arguments = e.Argument.Split('|'); int gridRowId = Convert.ToInt32(arguments[0]); GridDataItem gridDataItem = playersRadGrid.Items[gridRowId]; int opponentId = Convert.ToInt32(gridDataItem.OwnerTableView.DataKeyValues[gridRowId]["UserId"]); bool opponentAvailabilitySet = false; appointments = GetAppointments(StoredData.User.UserId, opponentId, out opponentAvailabilitySet); if (!opponentAvailabilitySet) { RadAjaxManager.GetCurrent(Page).ResponseScripts.Add(@"radalert('The selected player has not set his/her availability.',250,150,'Availability Not Set!!');"); } } RadScheduler1.DataSource = appointments; RadScheduler1.Rebind(); }