Ejemplo n.º 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);
            }
        }