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