private List <DLL.Appointment> GetAppointments(int userId, int opponentId, out bool opponentAvailabilitySet) { List <DLL.Appointment> appointments = new List <DLL.Appointment>(); opponentAvailabilitySet = false; using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext()) { appointments = dataContext.SelectAppointmentsByUserIdOpponentId(StoredData.User.UserId, opponentId).ToList(); //Get availability for current user List <SelectAvailabilitiesByUserIdResult> availability = dataContext.SelectAvailabilitiesByUserId(StoredData.User.UserId).ToList(); if (availability.Count > 0) { appointments = CombineAppointmentsWithAvailability(availability, appointments, StoredData.User.UserId); } //Get availability for opponent List <SelectAvailabilitiesByUserIdResult> opponentAvailability = dataContext.SelectAvailabilitiesByUserId(opponentId).ToList(); if (opponentAvailability.Count > 0) { appointments = CombineAppointmentsWithAvailability(opponentAvailability, appointments, opponentId); opponentAvailabilitySet = true; } } return(appointments); }
protected void Page_Load(object sender, EventArgs e) { if (!Request.IsAuthenticated) { Response.Redirect(WebConfigurationManager.AppSettings["LoginPageURL"].ToString()); } Guid userId = new Guid(Request.QueryString["UserId"]); using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext()) { ISingleResult <SelectUserPublicProfileByProfileIdResult> users = dataContext.SelectUserPublicProfileByProfileId(userId); SelectUserPublicProfileByProfileIdResult user = users.First(); userLabel.Text = user.FirstName + " " + user.LastName; //Load Image if (user.ProfileImageName.HasValue) { profileImage.ImageUrl = string.Format("~/ProfileImages/{0}.jpg", user.ProfileImageName.ToString()); } divisionLabel.Text = user.Division; homeCourtLabel.Text = user.CourtName; ntrpRankingLabel.Text = user.NTRPRanking.ToString(); ageGroupLabel.Text = user.AgeGroup; racquetHandLabel.Text = user.RacquetHand; favoriteShotLabel.Text = user.FavoriteShot; racquetLabel.Text = user.Racquet; if (!StoredData.User.TempDivision.Value || (user.DivisionId != StoredData.User.Division) || !StoredData.User.AccessExpired.Value) { emailHyperLink.Text = user.EmailId; emailHyperLink.NavigateUrl = string.Format("mailto:{0}", user.EmailId); phoneLabel.Text = user.Phone; facebookHyperLink.Text = user.Facebook; facebookHyperLink.NavigateUrl = user.Facebook; linkedInHyperLink.Text = user.LinkedIn; linkedInHyperLink.NavigateUrl = user.LinkedIn; myspaceHyperLink.Text = user.MySpace; myspaceHyperLink.NavigateUrl = user.MySpace; orkutHyperLink.Text = user.Orkut; orkutHyperLink.NavigateUrl = user.Orkut; } List <Performance> performances = dataContext.SelectPerformanceByUserId(user.UserId).ToList(); Performance seasonPerformance = performances.Find(p => p.DivisionId == user.DivisionId); seasonWinsLabel.Text = string.Format("{0}W - {1}L", seasonPerformance.Win, seasonPerformance.Loss); seasonPointsLabel.Text = seasonPerformance.TotalPoints.ToString(); overallWinsLabel.Text = string.Format("{0}W - {1}L", performances.Sum(p => p.Win), performances.Sum(p => p.Loss)); overallPointsLabel.Text = performances.Sum(p => p.TotalPoints).ToString(); if (!StoredData.User.TempDivision.Value) { List <GetUpcomingMatchesResult> upcomingMatches = dataContext.GetUpcomingMatches(user.UserId).ToList(); upcomingMatchesRadGrid.DataSource = upcomingMatches; upcomingMatchesRadGrid.DataBind(); List <GetPreviousMatchesResult> previousMatches = dataContext.GetPreviousMatches(user.UserId).ToList(); previousMatchesRadGrid.DataSource = previousMatches; previousMatchesRadGrid.DataBind(); int upcomingMatchCount = Convert.ToInt32(upcomingMatches.Count(p => p.UserId == StoredData.User.UserId)); int previousMatchCount = Convert.ToInt32(previousMatches.Count(p => p.UserId == StoredData.User.UserId)); } //Get availability List <SelectAvailabilitiesByUserIdResult> availabilities = dataContext.SelectAvailabilitiesByUserId(user.UserId).ToList(); SetAvailabilities(availabilities); if (StoredData.User.TempDivision.Value || StoredData.User.AccessExpired.Value) { matchRequestLinkButton.Enabled = false; } else { List <SelectDivisionResult> selectDivisionResult = dataContext.SelectDivision(StoredData.User.Division.Value).ToList(); foreach (SelectDivisionResult result in selectDivisionResult) { if (result.StartDate > DateTime.Now) { matchRequestLinkButton.Enabled = false; } } } //TODO: Have to uncomment these lines below //if ((upcomingMatchCount + previousMatchCount) < 2) matchRequestLinkButton.Attributes.Add("onClick", string.Format("openRadWindow('{0}'); return false;", user.UserId)); //else //matchRequestLinkButton.Attributes.Add("onClick", "alert('You have already played two matches against this player for the season. You cannot play against a player more than twice.');return false;"); //matchRequestLinkButton.PostBackUrl = WebConfigurationManager.AppSettings["MatchRequestPath"].ToString(); } }
protected void Page_Load(object sender, EventArgs e) { if (!Request.IsAuthenticated) { Response.Redirect(WebConfigurationManager.AppSettings["LoginPageURL"].ToString()); } sundayUnavailableCheckBox.Attributes.Add("onclick", "clearTextBoxes(this);"); mondayUnavailableCheckBox.Attributes.Add("onclick", "clearTextBoxes(this);"); tuesdayUnavailableCheckBox.Attributes.Add("onclick", "clearTextBoxes(this);"); wednesdayUnavailableCheckBox.Attributes.Add("onclick", "clearTextBoxes(this);"); thursdayUnavailableCheckBox.Attributes.Add("onclick", "clearTextBoxes(this);"); fridayUnavailableCheckBox.Attributes.Add("onclick", "clearTextBoxes(this);"); saturdayUnavailableCheckBox.Attributes.Add("onclick", "clearTextBoxes(this);"); sundayFromRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); sundayToRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); mondayFromRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); mondayToRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); tuesdayFromRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); tuesdayToRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); wednesdayFromRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); wednesdayToRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); thursdayFromRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); thursdayToRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); fridayFromRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); fridayToRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); saturdayFromRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); saturdayToRadTimePicker.Attributes.Add("onkeypress", "clearCheckBox(this);"); using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext()) { if (!Page.IsPostBack) { List <SelectAvailabilitiesByUserIdResult> availability = dataContext.SelectAvailabilitiesByUserId(StoredData.User.UserId).ToList(); if (availability.Count > 0) { if (availability[0].SundayStart.HasValue) { sundayFromRadTimePicker.SelectedDate = availability[0].SundayStart; } if (availability[0].SundayEnd.HasValue) { sundayToRadTimePicker.SelectedDate = availability[0].SundayEnd; } if (availability[0].SundayUnavailable.HasValue) { sundayUnavailableCheckBox.Checked = availability[0].SundayUnavailable.Value; } if (availability[0].MondayStart.HasValue) { mondayFromRadTimePicker.SelectedDate = availability[0].MondayStart; } if (availability[0].MondayEnd.HasValue) { mondayToRadTimePicker.SelectedDate = availability[0].MondayEnd; } if (availability[0].MondayUnavailable.HasValue) { mondayUnavailableCheckBox.Checked = availability[0].MondayUnavailable.Value; } if (availability[0].TuesdayStart.HasValue) { tuesdayFromRadTimePicker.SelectedDate = availability[0].TuesdayStart; } if (availability[0].TuesdayEnd.HasValue) { tuesdayToRadTimePicker.SelectedDate = availability[0].TuesdayEnd; } if (availability[0].TuesdayUnavailable.HasValue) { tuesdayUnavailableCheckBox.Checked = availability[0].TuesdayUnavailable.Value; } if (availability[0].WednesdayStart.HasValue) { wednesdayFromRadTimePicker.SelectedDate = availability[0].WednesdayStart; } if (availability[0].WednesdayEnd.HasValue) { wednesdayToRadTimePicker.SelectedDate = availability[0].WednesdayEnd; } if (availability[0].WednesdayUnavailable.HasValue) { wednesdayUnavailableCheckBox.Checked = availability[0].WednesdayUnavailable.Value; } if (availability[0].ThursdayStart.HasValue) { thursdayFromRadTimePicker.SelectedDate = availability[0].ThursdayStart; } if (availability[0].ThursdayEnd.HasValue) { thursdayToRadTimePicker.SelectedDate = availability[0].ThursdayEnd; } if (availability[0].ThursdayUnavailable.HasValue) { thursdayUnavailableCheckBox.Checked = availability[0].ThursdayUnavailable.Value; } if (availability[0].FridayStart.HasValue) { fridayFromRadTimePicker.SelectedDate = availability[0].FridayStart; } if (availability[0].FridayEnd.HasValue) { fridayToRadTimePicker.SelectedDate = availability[0].FridayEnd; } if (availability[0].FridayUnavailable.HasValue) { fridayUnavailableCheckBox.Checked = availability[0].FridayUnavailable.Value; } if (availability[0].SaturdayStart.HasValue) { saturdayFromRadTimePicker.SelectedDate = availability[0].SaturdayStart; } if (availability[0].SaturdayEnd.HasValue) { saturdayToRadTimePicker.SelectedDate = availability[0].SaturdayEnd; } if (availability[0].SaturdayUnavailable.HasValue) { saturdayUnavailableCheckBox.Checked = availability[0].SaturdayUnavailable.Value; } ViewState["AvailabilityPresent"] = true; } } } }
protected void submitButton_Click(object sender, EventArgs e) { if (validate()) { DateTime selectedDateTime = Convert.ToDateTime(RadDatePicker1.SelectedDate.Value.ToShortDateString() + " " + RadTimePicker1.SelectedDate.Value.ToShortTimeString()); int opponentId = Convert.ToInt32(Request.QueryString["opponentId"]); bool timeValid = true; using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext()) { //Get opponents availability List <SelectAvailabilitiesByUserIdResult> availability = dataContext.SelectAvailabilitiesByUserId(opponentId).ToList(); if (availability.Count > 0) { //Find day of week for currently selected date and get opponents availability for that date. DateTime availabilityStart = selectedDateTime; DateTime availabilityEnd = selectedDateTime; bool unavailable = false; switch (selectedDateTime.DayOfWeek) { case DayOfWeek.Sunday: if (availability[0].SundayStart.HasValue) { availabilityStart = availability[0].SundayStart.Value; availabilityEnd = availability[0].SundayEnd.Value; } else if (availability[0].SundayUnavailable.HasValue) { unavailable = availability[0].SundayUnavailable.Value; } break; case DayOfWeek.Monday: if (availability[0].MondayStart.HasValue) { availabilityStart = availability[0].MondayStart.Value; availabilityEnd = availability[0].MondayEnd.Value; } else if (availability[0].MondayUnavailable.HasValue) { unavailable = availability[0].MondayUnavailable.Value; } break; case DayOfWeek.Tuesday: if (availability[0].TuesdayStart.HasValue) { availabilityStart = availability[0].TuesdayStart.Value; availabilityEnd = availability[0].TuesdayEnd.Value; } else if (availability[0].TuesdayUnavailable.HasValue) { unavailable = availability[0].TuesdayUnavailable.Value; } break; case DayOfWeek.Wednesday: if (availability[0].WednesdayStart.HasValue) { availabilityStart = availability[0].WednesdayStart.Value; availabilityEnd = availability[0].WednesdayEnd.Value; } else if (availability[0].WednesdayUnavailable.HasValue) { unavailable = availability[0].WednesdayUnavailable.Value; } break; case DayOfWeek.Thursday: if (availability[0].ThursdayStart.HasValue) { availabilityStart = availability[0].ThursdayStart.Value; availabilityEnd = availability[0].ThursdayEnd.Value; } else if (availability[0].ThursdayUnavailable.HasValue) { unavailable = availability[0].ThursdayUnavailable.Value; } break; case DayOfWeek.Friday: if (availability[0].FridayStart.HasValue) { availabilityStart = availability[0].FridayStart.Value; availabilityEnd = availability[0].FridayEnd.Value; } else if (availability[0].FridayUnavailable.HasValue) { unavailable = availability[0].FridayUnavailable.Value; } break; case DayOfWeek.Saturday: if (availability[0].SaturdayStart.HasValue) { availabilityStart = availability[0].SaturdayStart.Value; availabilityEnd = availability[0].SaturdayEnd.Value; } else if (availability[0].SaturdayUnavailable.HasValue) { unavailable = availability[0].SaturdayUnavailable.Value; } break; } //If availability data exists if (availabilityStart != selectedDateTime) { availabilityStart = Convert.ToDateTime(selectedDateTime.ToShortDateString() + " " + availabilityStart.ToShortTimeString()); availabilityEnd = Convert.ToDateTime(selectedDateTime.ToShortDateString() + " " + availabilityEnd.ToShortTimeString()); //If opponents availability conflicts currently selected date and time then show error if (selectedDateTime < availabilityStart || selectedDateTime >= availabilityEnd) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("radalert('The start time for the match is in conflict with your opponents availability. Please pick another time.')"); ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", "(function(){var f = function(){" + stringBuilder.ToString() + ";Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()", true); timeValid = false; } } //If your opponent is unavailable for the whole day. else if (unavailable) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("radalert('The start time for the match is in conflict with your opponents availability. Please pick another time.')"); ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", "(function(){var f = function(){" + stringBuilder.ToString() + ";Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()", true); timeValid = false; } } if (timeValid) { //Find appointments for both user and opponents that conflict with the time selected List <SelectAppointmentsByUserIdDateResult> appointments = dataContext.SelectAppointmentsByUserIdDate(StoredData.User.UserId, opponentId, selectedDateTime).ToList(); if (appointments.Count > 0) { StringBuilder stringBuilder = new StringBuilder(); if (appointments[0].UserId == StoredData.User.UserId) { stringBuilder.Append("radconfirm('You may have a conflict with one or more events in your schedule.<br>Do you want to continue?',confirmCallBackFn)"); } else { stringBuilder.Append("radconfirm('You may have a conflict with one or more events in your opponents schedule.<br>Do you want to continue?',confirmCallBackFn)"); } ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", "(function(){var f = function(){" + stringBuilder.ToString() + ";Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()", true); timeValid = false; } } if (timeValid) { UpdateMatch(); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "EnableButton", "changeButtonState('false');", true); } } } }
private bool OpponentAvailable(int opponentId, DateTime selectedDateTime) { bool isTimeValid = true; using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext()) { //Get opponents availability List <SelectAvailabilitiesByUserIdResult> availability = dataContext.SelectAvailabilitiesByUserId(opponentId).ToList(); if (availability.Count > 0) { //Find day of week for currently selected date and get opponents availability for that date. DateTime availabilityStart = selectedDateTime; DateTime availabilityEnd = selectedDateTime; switch (selectedDateTime.DayOfWeek) { case DayOfWeek.Sunday: if (availability[0].SundayStart.HasValue) { availabilityStart = availability[0].SundayStart.Value; availabilityEnd = availability[0].SundayEnd.Value; } else if (availability[0].SundayUnavailable.Value) { isTimeValid = false; } break; case DayOfWeek.Monday: if (availability[0].MondayStart.HasValue) { availabilityStart = availability[0].MondayStart.Value; availabilityEnd = availability[0].MondayEnd.Value; } else if (availability[0].MondayUnavailable.Value) { isTimeValid = false; } break; case DayOfWeek.Tuesday: if (availability[0].TuesdayStart.HasValue) { availabilityStart = availability[0].TuesdayStart.Value; availabilityEnd = availability[0].TuesdayEnd.Value; } else if (availability[0].TuesdayUnavailable.Value) { isTimeValid = false; } break; case DayOfWeek.Wednesday: if (availability[0].WednesdayStart.HasValue) { availabilityStart = availability[0].WednesdayStart.Value; availabilityEnd = availability[0].WednesdayEnd.Value; } else if (availability[0].WednesdayUnavailable.Value) { isTimeValid = false; } break; case DayOfWeek.Thursday: if (availability[0].ThursdayStart.HasValue) { availabilityStart = availability[0].ThursdayStart.Value; availabilityEnd = availability[0].ThursdayEnd.Value; } else if (availability[0].ThursdayUnavailable.Value) { isTimeValid = false; } break; case DayOfWeek.Friday: if (availability[0].FridayStart.HasValue) { availabilityStart = availability[0].FridayStart.Value; availabilityEnd = availability[0].FridayEnd.Value; } else if (availability[0].FridayUnavailable.Value) { isTimeValid = false; } break; case DayOfWeek.Saturday: if (availability[0].SaturdayStart.HasValue) { availabilityStart = availability[0].SaturdayStart.Value; availabilityEnd = availability[0].SaturdayEnd.Value; } else if (availability[0].SaturdayUnavailable.Value) { isTimeValid = false; } break; } //If availability data exists if (availabilityStart != selectedDateTime) { availabilityStart = Convert.ToDateTime(selectedDateTime.ToShortDateString() + " " + availabilityStart.ToShortTimeString()); availabilityEnd = Convert.ToDateTime(selectedDateTime.ToShortDateString() + " " + availabilityEnd.ToShortTimeString()); //If opponents availability conflicts currently selected date and time then show error if (selectedDateTime < availabilityStart || selectedDateTime >= availabilityEnd) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("radalert('The start time for the match is in conflict with your opponents availability. Please pick another time.')"); ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", "(function(){var f = function(){" + stringBuilder.ToString() + ";Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()", true); isTimeValid = false; } } else if (!isTimeValid) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("radalert('The start time for the match is in conflict with your opponents availability. Please pick another time.')"); ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert1", "(function(){var f = function(){" + stringBuilder.ToString() + ";Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()", true); } } } return(isTimeValid); }