Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.IsAuthenticated)
            {
                int opponentId = Convert.ToInt32(Request.QueryString["opponentId"]);
                RadDatePicker1.MinDate = DateTime.Now.AddDays(1);

                if (!IsPostBack)
                {
                    if (!StoredData.User.TempDivision.Value || !StoredData.User.AccessExpired.Value)
                    {
                        using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
                        {
                            ISingleResult <SelectUserPublicProfileResult> users = dataContext.SelectUserPublicProfile(opponentId);
                            SelectUserPublicProfileResult user = users.First();
                            opponentLabel.Text = user.FirstName + " " + user.LastName;

                            List <TennisCourt> tennisCourts = dataContext.SelectTennisCourtsByEmailId(StoredData.User.EmailId).ToList();
                            locationDropDownList.DataSource     = tennisCourts;
                            locationDropDownList.DataTextField  = "CourtName";
                            locationDropDownList.DataValueField = "CourtId";
                            locationDropDownList.DataBind();

                            locationDropDownList.SelectedValue = StoredData.User.HomeCourt.ToString();
                            ViewState["UserCourtName"]         = locationDropDownList.SelectedItem.Text;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        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;
                    }
                }
            }
        }
Esempio n. 3
0
        private void UpdateMatch()
        {
            int?     matchId          = 0;
            int?     apptId           = 0;
            bool     success          = false;
            int      opponentId       = Convert.ToInt32(Request.QueryString["opponentId"]);
            DateTime selectedDateTime = Convert.ToDateTime(RadDatePicker1.SelectedDate.Value.ToShortDateString() + " " + RadTimePicker1.SelectedDate.Value.ToShortTimeString());

            using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
            {
                using (TransactionScope transactionScope = new TransactionScope())
                {
                    if (string.IsNullOrEmpty(HiddenField1.Value))
                    {
                        dataContext.InsertMatch(selectedDateTime, StoredData.User.HomeCourt, StoredData.User.UserId, opponentId, 1, string.Empty, ref matchId);
                        dataContext.InsertAppointment(StoredData.User.UserId, matchId, string.Format("vs {0} at {1}", opponentLabel.Text, ViewState["UserCourtName"]), selectedDateTime, selectedDateTime.AddHours(3), string.Empty, null, StoredData.User.UserId.ToString(), ref apptId);
                        dataContext.InsertAppointment(opponentId, matchId, string.Format("vs {0} at {1}", StoredData.User.FirstName + " " + StoredData.User.LastName, ViewState["UserCourtName"]), selectedDateTime, selectedDateTime.AddHours(3), string.Empty, null, StoredData.User.UserId.ToString(), ref apptId);
                    }
                    else
                    {
                        dataContext.InsertMatch(selectedDateTime, Convert.ToInt32(HiddenField1.Value), StoredData.User.UserId, opponentId, 1, string.Empty, ref matchId);
                        dataContext.InsertAppointment(StoredData.User.UserId, matchId, string.Format("vs {0} at {1}", opponentLabel.Text, HiddenField2.Value), selectedDateTime, selectedDateTime.AddHours(3), string.Empty, null, StoredData.User.UserId.ToString(), ref apptId);
                        dataContext.InsertAppointment(opponentId, matchId, string.Format("vs {0} at {1}", StoredData.User.FirstName + " " + StoredData.User.LastName, HiddenField2.Value), selectedDateTime, selectedDateTime.AddHours(3), string.Empty, null, StoredData.User.UserId.ToString(), ref apptId);
                    }



                    transactionScope.Complete();
                    success = true;
                }
                if (success)
                {
                    submitButton.Enabled = false;
                    List <SelectUserPublicProfileResult> opponents = dataContext.SelectUserPublicProfile(opponentId).ToList();
                    StringBuilder message = new StringBuilder();
                    message.Append(string.Format("{0} has requested to play a Tennis match with you.\r\n", StoredData.User.FirstName + " " + StoredData.User.LastName));
                    message.Append(string.Format("Following are the details of the match:\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", selectedDateTime.ToShortDateString(), selectedDateTime.ToShortTimeString()));
                    if (string.IsNullOrEmpty(HiddenField1.Value))
                    {
                        message.Append(string.Format("Location: {0}\r\n", locationDropDownList.SelectedItem.Text));
                    }
                    else
                    {
                        message.Append(string.Format("Location: {0}\r\n", HiddenField2.Value.ToString()));
                    }
                    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 reply to your opponent and let them know, if you can or cannot play this match.\r\n\r\n");


                    //if (!SendEmail(opponents[0].EmailId, message, "New Tennis match request"))
                    //{
                    //    StringBuilder stringBuilder = new StringBuilder();
                    //    stringBuilder.Append("radalert('The system was unable to send an email to your opponent about this match request.<br>Please contact you opponent about this match.',250,150,'Match Cancelled!!')");
                    //    ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", "(function(){var f = function(){" + stringBuilder.ToString() + ";Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()", true);
                    //}
                    SendEmail(opponents[0].EmailId, message, "New Tennis match request");

                    string closingScript = "<script type='text/javascript'>Sys.Application.add_load(function () {closeRadWindowAndShowAlert();}); </script> ";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", closingScript, false);
                }
            }
        }
Esempio n. 4
0
        protected void submitButton_Click(object sender, EventArgs e)
        {
            if (validate() && !Convert.ToBoolean(ViewState["Submitted"]))
            {
                if (!noShowCheckBox.Checked)
                {
                    ViewState["Submitted"] = true;
                    int  userTravelPoints     = 0;
                    int  opponentTravelPoints = 0;
                    int  userScorePoints      = 0;
                    int  opponentScorePoints  = 0;
                    int  userWinPoints        = 0;
                    int  opponentWinPoints    = 0;
                    bool userWin            = false;
                    bool opponentWin        = false;
                    int  userWinNumber      = 0;
                    int  userLossNumber     = 0;
                    int  opponentWinNumber  = 0;
                    int  opponentLossNumber = 0;

                    //ScorePoints
                    if (Convert.ToInt32(playerSet3DropDownListSet.SelectedValue) > 0 || Convert.ToInt32(opponentSet3DropDownList.SelectedValue) > 0)
                    {
                        if (Convert.ToInt32(winnerDropDownList.SelectedValue) == StoredData.User.UserId)
                        {
                            userWinPoints      = 3;
                            userWin            = true;
                            userWinNumber      = 1;
                            opponentLossNumber = 1;
                        }
                        else
                        {
                            opponentWinPoints = 3;
                            opponentWin       = true;
                            opponentWinNumber = 1;
                            userLossNumber    = 1;
                        }
                    }
                    else
                    {
                        if (Convert.ToInt32(winnerDropDownList.SelectedValue) == StoredData.User.UserId)
                        {
                            userWinPoints      = 3;
                            userScorePoints    = 1;
                            userWin            = true;
                            userWinNumber      = 1;
                            opponentLossNumber = 1;
                        }
                        else
                        {
                            opponentWinPoints   = 3;
                            opponentScorePoints = 1;
                            opponentWin         = true;
                            opponentWinNumber   = 1;
                            userLossNumber      = 1;
                        }
                    }
                    //Convert match score to string
                    StringBuilder scoreString = new StringBuilder();
                    scoreString.Append(string.Format("{0}-{1},{2}-{3}", playerSet1DropDownListSet.SelectedValue, opponentSet1DropDownList.SelectedValue, playerSet2DropDownListSet.SelectedValue, opponentSet2DropDownList.SelectedValue));
                    if (Convert.ToInt32(playerSet3DropDownListSet.SelectedValue) > 0 || Convert.ToInt32(opponentSet3DropDownList.SelectedValue) > 0)
                    {
                        scoreString.Append(string.Format(",{0}-{1}", playerSet3DropDownListSet.SelectedValue, opponentSet3DropDownList.SelectedValue, playerSet2DropDownListSet.SelectedValue, opponentSet2DropDownList.SelectedValue));
                    }

                    DateTime selectedDateTime = Convert.ToDateTime(RadDatePicker1.SelectedDate.Value.ToShortDateString() + " " + RadTimePicker1.SelectedDate.Value.ToShortTimeString());
                    bool     success          = false;
                    using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
                    {
                        List <SelectUserPublicProfileResult> selectUserPublicProfileResult = dataContext.SelectUserPublicProfile(Convert.ToInt32(opponentIdHiddenField.Value)).ToList();

                        //TravelPoints
                        int selectedCourtId = Convert.ToInt32(locationDropDownList.SelectedItem.Value);
                        if (selectedCourtId != StoredData.User.HomeCourt)
                        {
                            userTravelPoints = 1;
                        }
                        if (selectedCourtId != selectUserPublicProfileResult[0].HomeCourt)
                        {
                            opponentTravelPoints = 1;
                        }


                        //Check travel points
                        int?oppponentTotalTravelPoints = 0;
                        List <SelectTotalTravelPointsByUserIdResult> pastTravelPoints = dataContext.SelectTotalTravelPointsByUserId(StoredData.User.UserId, Convert.ToInt32(opponentIdHiddenField.Value), StoredData.User.Division, ref oppponentTotalTravelPoints).ToList();

                        if (pastTravelPoints.Count > 0)
                        {
                            if (pastTravelPoints[0].TotalTravelPoints == 4)
                            {
                                userTravelPoints = 0;
                            }
                        }
                        if (oppponentTotalTravelPoints.Value == 4)
                        {
                            opponentTravelPoints = 0;
                        }



                        int?matchPointLogId = 0;
                        int?matchId         = null;
                        int?opponentId      = null;
                        using (TransactionScope transactionScope = new TransactionScope())
                        {
                            if (string.IsNullOrEmpty(matchIdHiddenField.Value))
                            {
                                opponentId = Convert.ToInt32(opponentDropDownList.SelectedItem.Value);
                                dataContext.InsertMatch(selectedDateTime, selectedCourtId, StoredData.User.UserId, Convert.ToInt32(opponentDropDownList.SelectedItem.Value), 2, scoreString.ToString(), ref matchId);
                            }
                            else
                            {
                                matchId    = Convert.ToInt32(matchIdHiddenField.Value);
                                opponentId = Convert.ToInt32(opponentIdHiddenField.Value);
                                dataContext.UpdateMatch(matchId.Value, selectedDateTime, selectedCourtId, Convert.ToInt32(MatchStatus.Completed), scoreString.ToString());
                            }

                            dataContext.InsertMatchPointLog(matchId.Value, StoredData.User.UserId, userWin, 1, userTravelPoints, userScorePoints, userWinPoints, ref matchPointLogId);
                            dataContext.InsertMatchPointLog(matchId.Value, opponentId.Value, opponentWin, 1, opponentTravelPoints, opponentScorePoints, opponentWinPoints, ref matchPointLogId);

                            dataContext.UpdatePerformance(StoredData.User.UserId, userWinNumber, userLossNumber, userScorePoints + userTravelPoints + userWinPoints + 1, userTravelPoints);
                            dataContext.UpdatePerformance(opponentId.Value, opponentWinNumber, opponentLossNumber, opponentScorePoints + opponentTravelPoints + opponentWinPoints + 1, opponentTravelPoints);

                            transactionScope.Complete();
                            success = true;
                        }

                        if (selectUserPublicProfileResult.Count > 0)
                        {
                            if (userWin)
                            {
                                SendEmail(selectUserPublicProfileResult[0].EmailId, StoredData.User.FirstName + " " + StoredData.User.LastName, scoreString.ToString());
                            }
                            else
                            {
                                SendEmail(selectUserPublicProfileResult[0].EmailId, opponentDropDownList.SelectedItem.Text, scoreString.ToString());
                            }
                        }
                    }
                    if (success)
                    {
                        string closingScript = "closeRadWindowAndShowAlert('Score successfully submited.')";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", "(function(){var f = function(){" + closingScript + ";Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()", true);
                    }
                }
                else
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append("radconfirm('We are sorry to hear that your opponent did not show up.<br/> We take such incidents very seriously.<br/> Your opponent will receive two penalty points.<br/>Do you want to continue?");

                    stringBuilder.Append("',confirmCallBackFn,400,null,null,'No Show!!')");
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "radconfirm", "(function(){var f = function(){" + stringBuilder.ToString() + ";Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()", true);
                }
            }
        }
        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();
        }