Beispiel #1
0
        protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
        {
            if (e.Argument == "true")
            {
                if (!StoredData.User.AccessExpired.Value && !StoredData.User.TempDivision.Value)
                {
                    bool success = false;
                    using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
                    {
                        int?     matchPointLogId  = 0;
                        int?     matchId          = null;
                        int?     opponentId       = null;
                        DateTime selectedDateTime = Convert.ToDateTime(RadDatePicker1.SelectedDate.Value.ToShortDateString() + " " + RadTimePicker1.SelectedDate.Value.ToShortTimeString());
                        using (TransactionScope transactionScope = new TransactionScope())
                        {
                            if (string.IsNullOrEmpty(matchIdHiddenField.Value))
                            {
                                opponentId = Convert.ToInt32(opponentDropDownList.SelectedItem.Value);
                                dataContext.InsertMatch(selectedDateTime, Convert.ToInt32(locationDropDownList.Text), StoredData.User.UserId, Convert.ToInt32(opponentDropDownList.SelectedItem.Value), 2, "0-0,0-0", ref matchId);
                            }
                            else
                            {
                                matchId    = Convert.ToInt32(matchIdHiddenField.Value);
                                opponentId = Convert.ToInt32(opponentIdHiddenField.Value);
                                dataContext.UpdateMatch(matchId.Value, selectedDateTime, Convert.ToInt32(locationDropDownList.Text), Convert.ToInt32(MatchStatus.Completed), "0-0,0-0");
                            }

                            dataContext.InsertMatchPointLog(matchId.Value, StoredData.User.UserId, true, 1, 0, 0, 3, ref matchPointLogId);
                            dataContext.InsertMatchPointLog(matchId.Value, opponentId.Value, false, 0, 0, 0, 0, ref matchPointLogId);

                            dataContext.UpdatePerformance(StoredData.User.UserId, 1, 0, 4, 0);
                            dataContext.UpdatePerformance(opponentId.Value, 0, 1, 0, 0);

                            dataContext.UpdateUserWarningByUserId(opponentId.Value, 2);

                            transactionScope.Complete();
                            success = true;
                        }
                    }
                    if (success)
                    {
                        string closingScript = "<script type='text/javascript'>Sys.Application.add_load(function () {closeRadWindowAndShowAlert('No show successfully recorded.');}); </script> ";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", closingScript, false);
                    }
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "EnableButton", "changeButtonState('false');", true);
            }
        }
Beispiel #2
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);
                }
            }
        }