예제 #1
0
        protected void UsersTeams_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            GridView _gridView = (GridView)sender;

            // Get the selected index and the command name

            int    _selectedIndex = int.Parse(e.CommandArgument.ToString());
            string _commandName   = e.CommandName;

            switch (_commandName)
            {
            case ("Click"):
                _gridView.SelectedIndex = _selectedIndex;

                if (Id == SessionProps.UserGuid)
                {
                    WebControlManager.RedirectWithQueryString("UserTeamEdit.aspx", new string[] { "teamGUID" }, new string[] { _gridView.SelectedValue.ToString() });
                    //WebControlManager.RedirectWithQueryString("/UserTeam/UserTeamEdit_js.aspx", new string[] { "teamGUID" }, new string[] { _gridView.SelectedValue.ToString() });
                }
                else
                {
                    WebControlManager.RedirectWithQueryString("TeamView.aspx", new string[] { "teamGUID" }, new string[] { _gridView.SelectedValue.ToString() });
                }

                break;
            }
        }
예제 #2
0
        protected void btnCreateForumItem_Click(object sender, EventArgs e)
        {
            var categoryGUID = this.GetRedirectParameter("categoryGUID", false);

            if (categoryGUID != null && !String.IsNullOrEmpty(SessionProps.UserName) &&
                SessionProps.HasPermission("USER") &&
                Header.Text.Trim().Length > 0 && Body.Text.Trim().Length > 0)
            {
                using (var db = Global.GetConnection())
                {
                    var forum = new Ext_Forum();
                    forum.Header            = Header.Text;
                    forum.Body              = Body.Text;
                    forum.PostedDate        = DateTime.Now;
                    forum.ForumCategoryGUID = new Guid(categoryGUID.ToString());
                    forum.UserGUID          = SessionProps.UserGuid;

                    db.Ext_Forum.InsertOnSubmit(forum);

                    db.SubmitChanges();

                    WebControlManager.RedirectWithQueryString("ForumViewThread.aspx", new string[] { "threadGUID" }, new string[] { forum.GUID.ToString() });
                }
            }
            else
            {
                lblMessage.Text =
                    "Det gick inte att spara inlägget. Är du inloggad? Har du fyllt i både rubrik och brödtext?";
            }
        }
예제 #3
0
        protected void grdPrivateTournaments_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            GridView _gridView = (GridView)sender;

            // Get the selected index and the command name

            int    _selectedIndex = int.Parse(e.CommandArgument.ToString());
            string _commandName   = e.CommandName;

            _gridView.SelectedIndex = _selectedIndex;

            var pvtTournamentGUID = new Guid(_gridView.SelectedDataKey[0].ToString());
            var teamGUID          = new Guid(_gridView.SelectedDataKey[1].ToString());

            switch (_commandName)
            {
            case ("Click"):
                //Gå till tävlingen
                WebControlManager.RedirectWithQueryString("MyTournamentStanding.aspx", new string[] { "pvtTournamentGUID" }, new string[] { pvtTournamentGUID.ToString() });
                break;

            case ("Accept"):
                //ändra utmaningen till accepterad
                AcceptChallenge(pvtTournamentGUID, teamGUID);
                break;

            case ("Deny"):
                //ta bort utmaningen och skicka meddelande till den som utmanade
                DenyChallenge(pvtTournamentGUID, teamGUID);
                break;
            }
        }
예제 #4
0
        /// <summary>
        /// Writes the data in the given webform to the given entity object
        /// </summary>
        /// <param name="form"></param>
        /// <param name="entity"></param>
        public static void FormToEntity(System.Web.UI.Control form, object entity)
        {
            PropertyInfo[] properties = entity.GetType().GetProperties();

            //loop the properties of the entity, try to find a matching webcontrol for each one
            foreach (var property in properties)
            {
                var control = WebControlManager.GetControl(property.Name, form);

                if (control != null)
                {
                    var value = WebControlManager.GetValue(control);

                    //convert to correct type...
                    if (property.CanWrite)
                    {
                        var convertedValue = ConvertValue(value, property.PropertyType);

                        //only set value if conversion was successful
                        if (convertedValue.GetType().Equals(property.PropertyType))
                        {
                            property.SetValue(entity, ConvertValue(value, property.PropertyType), null);
                        }
                    }
                }
            }
        }
예제 #5
0
 protected override void OnPreLoad(EventArgs e)
 {
     if (AuthenticationIsRequired && String.IsNullOrEmpty(SessionProps.UserName))
     {
         WebControlManager.RedirectWithQueryString("SignIn.aspx", new string[] { "SignInredirecturl" }, new string[] { Request.Url.ToString() });
     }
 }
예제 #6
0
        //public static string TwitterAccessToken { get; set; }
        //public static string TwitterAccessTokenSecret { get; set; }

        private static void InitiateTwitterAuthentication(SessionProperties sessionProperties)
        {
            if (String.IsNullOrEmpty(Parameters.Instance.TwitterAccessToken) ||
                String.IsNullOrEmpty(Parameters.Instance.TwitterAccessTokenSecret))
            {
                return;
            }

            try
            {
                // Step 3 - Exchange the Request Token for an Access Token
                Global.TwitterService = new TwitterService(Global.TwitterConsumerKey, Global.TwitterConsumerSecret);


                // Step 4 - User authenticates using the Access Token
                Global.TwitterService.AuthenticateWith(Parameters.Instance.TwitterAccessToken, Parameters.Instance.TwitterAccessTokenSecret);
                TwitterUser user = Global.TwitterService.VerifyCredentials(new VerifyCredentialsOptions());

                if (user == null)
                {
                    TwitterService = null;
                }
            }
            catch (Exception exception)
            {
                WebControlManager.SendAndLogErrorMessage(exception, Parameters.Instance.MailSender, Parameters.Instance.SupportMail);
                Global.TwitterService = null;
            }
        }
예제 #7
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            var messageGUID = this.GetRedirectParameter("messageGUID", false);

            if (messageGUID != null)
            {
                using (var db = Global.GetConnection())
                {
                    var message = db.Ext_Message.Single(m => m.GUID == new Guid(messageGUID.ToString()));

                    //safety

                    foreach (var rec in message.Ext_MessageRecipient)
                    {
                        if (rec.RecipientUserGUID == SessionProps.UserGuid)
                        {
                            db.Ext_MessageRecipient.DeleteOnSubmit(rec);

                            db.SubmitChanges();

                            break;
                        }
                    }
                }

                WebControlManager.RedirectWithQueryString("UserMessages.aspx", new[] { "GUID" }, new[] { SessionProps.UserGuid.ToString() });
            }
        }
예제 #8
0
        protected void UserTeams_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            var gridView = (GridView)sender;

            switch (e.CommandName)
            {
            case ("SingleClick"):
                //set selection from command argument
                gridView.SelectedIndex = int.Parse(e.CommandArgument.ToString());
                WebControlManager.RedirectWithQueryString("UserTeamView.aspx", new string[] { "TeamGUID" }, new string[] { gridView.SelectedValue.ToString() });
                break;
            }
        }
예제 #9
0
        protected void AddTeam_Click(object sender, EventArgs e)
        {
            if (sender is Button)
            {
                var senderButton = (sender as Button);
                if (senderButton.ID.StartsWith("addTeam"))
                {
                    var tourGUID = new Guid(senderButton.ID.Replace("addTeam", ""));

                    WebControlManager.RedirectWithQueryString("UserTeamEdit.aspx", new string[] { "tourGUID" }, new string[] { tourGUID.ToString() });
                }
            }
        }
예제 #10
0
        protected void Application_Error(object sender, EventArgs e)
        {
            var exception = Server.GetLastError().InnerException ?? Server.GetLastError();

            //mail error message
#if !DEBUG
            WebControlManager.SendAndLogErrorMessage(exception, Parameters.Instance.MailSender, Parameters.Instance.SupportMail);
#endif

            var exceptionMsg = Server.HtmlEncode(exception.Message);
            //exceptionMsg += "<p>" + Server.HtmlEncode(exception.StackTrace).Replace("\n", "<br>").Replace(" at ", "<br> at ") + "</p>";

            Response.Redirect("/Error.aspx?errorMsg=" + Server.UrlEncode(exceptionMsg));
        }
예제 #11
0
        protected void drpTournament_SelectedIndexChanged(object sender, EventArgs e)
        {
            var tours = new CommonDataSources(Global.ConnectionString, Global.SessionProperties).AllTournaments();

            foreach (var tournament in tours)
            {
                if (tournament.GUID == new Guid(drpTournament.SelectedValue))
                {
                    Global.SessionProperties.SelectedTournament = tournament;
                    break;
                }
            }

            WebControlManager.RefreshPage();
        }
예제 #12
0
        protected void grdTournaments_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            GridView _gridView = (GridView)sender;

            // Get the selected index and the command name

            int    _selectedIndex = int.Parse(e.CommandArgument.ToString());
            string _commandName   = e.CommandName;

            switch (_commandName)
            {
            case ("Click"):
                _gridView.SelectedIndex = _selectedIndex;
                WebControlManager.RedirectWithQueryString("AdminTournamentEdit.aspx", new string[] { "GUID" }, new string[] { _gridView.SelectedValue.ToString() });
                break;
            }
        }
예제 #13
0
        protected void Session_Start(object sender, EventArgs e)
        {
            var clientInfo  = WebControlManager.GetClientInfo();
            var sessionInfo = new SessionProperties(true, clientInfo);

            //get the default tournament
            using (var db = Global.GetConnection())
            {
                var tours = from t in db.Inti_Tournament
                            select t;

                foreach (var tour in tours.OrderByDescending(tStart => tStart.StartRegistration).ToList())
                {
                    sessionInfo.SelectedTournament = tour;
                    sessionInfo.DefaultTournament  = tour;
                    break;
                }
            }

            if (Request.Cookies != null)
            {
                if (Request.Cookies.Get("SignMeIn") != null)
                {
                    //automatic sign in
                    sessionInfo.UserGuid = new Guid(Request.Cookies["SignMeIn"].Value);

                    //set user guid
                    var user = new UserManagement(Global.ConnectionString, sessionInfo).GetUserByGuid(sessionInfo.UserGuid);

                    sessionInfo.UserName = user.UserName;

                    //set footer text
                    sessionInfo.FooterText = String.Format("Inloggad som {0} {1}", user.FirstName, user.LastName);

                    //set permissions
                    sessionInfo.Permissions = new UserManagement(Global.ConnectionString, sessionInfo).GetUserPermissions(sessionInfo.UserName);
                }
            }



            //set as not signed in
            HttpContext.Current.Session.RemoveAll();
            HttpContext.Current.Session.Add("sessionProps", sessionInfo);
        }
예제 #14
0
        /// <summary>
        /// Writes the data in the given entity object to the given form
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="form"></param>
        public static void EntityToForm(object entity, System.Web.UI.Control form)
        {
            PropertyInfo[] properties = entity.GetType().GetProperties();

            //loop the properties of the entity, try to find a matching webcontrol for each one
            foreach (var property in properties)
            {
                var control = WebControlManager.GetControl(property.Name, form);

                if (control != null)
                {
                    var value = property.GetValue(entity, null);
                    if (value != null)
                    {
                        WebControlManager.SetValue(control, value.ToString());
                    }
                }
            }
        }
예제 #15
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var athleteManagement = new AthleteManagement(Global.ConnectionString, SessionProps);

            var  playerGUIDvar = this.GetRedirectParameter("athleteGUID", false);
            Guid playerGUID    = Guid.Empty;
            Guid newPlayerGUID = Guid.Empty;
            var  newPlayer     = playerGUIDvar == null;

            if (playerGUIDvar != null)
            {
                playerGUID = new Guid(playerGUIDvar.ToString());
            }

            try
            {
                Action <string, Guid> TweetAthlete = (tweet, athleteClubGuid) =>
                {
                    var url = "http://interntipset.com/Player/" + athleteClubGuid.ToString();
                    Global.SendTweet(tweet, url, SessionProps);
                };

                newPlayerGUID = athleteManagement.SaveAthlete(FirstName.Text, LastName.Text, playerGUID, new Guid(drpTournament.SelectedValue),
                                                              (drpClubs.SelectedItem.Text == "---" ? Guid.Empty : new Guid(drpClubs.SelectedValue)),
                                                              (drpPosition.SelectedItem.Text == "---" ? Guid.Empty : new Guid(drpPosition.SelectedValue)),
                                                              int.Parse(Price.Text), IsActive.Checked, drpClubs.SelectedItem.Text, TweetAthlete);
            }
            catch (DuplicateNameException duplicateNameException)
            {
                PlayerEditMessage.Text =
                    "Det finns redan en spelare med detta namnet. Gå tillbaka till söksidan och editera den spelaren om det är samma person. Gör annars namnet unikt.";
            }
            catch (Exception exception)
            {
                PlayerEditMessage.Text = exception.Message;
            }

            if (newPlayerGUID != playerGUID)
            {
                WebControlManager.RedirectWithQueryString("AdminPlayerEdit.aspx", new string[] { "athleteGUID" }, new string[] { newPlayerGUID.ToString() });
            }
        }
예제 #16
0
        protected void grdPlayers_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            GridView _gridView = (GridView)sender;

            // Get the selected index and the command name

            int    _selectedIndex = int.Parse(e.CommandArgument.ToString());
            string _commandName   = e.CommandName;

            switch (_commandName)
            {
            case ("Click"):
                _gridView.SelectedIndex = _selectedIndex;
                var teamGUID = this.GetRedirectParameter("teamGUID", false);
                if (teamGUID != null)
                {
                    WebControlManager.RedirectWithQueryString(this.GetRedirectParameter("redirecturl", false).ToString(), new string[] { "athleteGUID", "teamGUID" }, new string[] { _gridView.SelectedValue.ToString(), teamGUID.ToString() });
                }
                break;
            }
        }
예제 #17
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            var stream = uplImage.FileContent;

            lblMessage.Text    = "";
            lblMessage.ToolTip = "";

            //check file size
            if (stream.Length > (1024 * 512))
            {
                lblMessage.Text = "Max storlek för bilder att ladda upp är 512 MB";
                return;
            }

            try
            {
                var serverSideImage = new System.Drawing.Bitmap(stream);

                var rescaledImage = RescaleImage(serverSideImage, MaximumWidth, MaximumHeight);

                var fileName = NewImageName + uplImage.FileName.Substring(uplImage.FileName.LastIndexOf("."));

                rescaledImage.Save(Server.MapPath("~/img/user/") + fileName);

                LoadPreviewImage(fileName);

                uplImage.Visible  = false;
                btnUpload.Visible = false;

                btnUndo.Visible        = true;
                btnChangeImage.Visible = true;
            }
            catch (Exception exception)
            {
                lblMessage.Text    = "Kan inte läsa bilden, testa med ett annat format.";
                lblMessage.ToolTip = exception.Message;
                WebControlManager.SendAndLogErrorMessage(exception, Parameters.Instance.MailSender, Parameters.Instance.SupportMail);
            }
        }
예제 #18
0
        protected void brnSave_Click(object sender, EventArgs e)
        {
            //save the club
            var clubGuid = this.GetRedirectParameter("clubGUID", false);
            var tourGuid = this.GetRedirectParameter("tourGUID", false);

            using (var db = Global.GetConnection())
            {
                Inti_Club club;
                if (clubGuid == null)
                {
                    club = new Inti_Club();

                    club.TournamentGUID = new Guid(tourGuid.ToString());
                }
                else
                {
                    club = db.Inti_Club.Single(c => c.GUID == new Guid(clubGuid.ToString()));
                }


                club.Name        = ClubName.Text;
                club.Description = ClubDescription.Text;
                club.ShortName   = ClubShortName.Text;

                if (clubGuid == null)
                {
                    db.Inti_Club.InsertOnSubmit(club);
                }

                db.SubmitChanges();

                if (clubGuid == null)
                {
                    WebControlManager.RedirectWithQueryString("AdminEditClub.aspx", new string[] { "clubGuid" }, new string[] { club.GUID.ToString() });
                }
            }
        }
예제 #19
0
        protected void btnReply_Click(object sender, EventArgs e)
        {
            var messageGUID = this.GetRedirectParameter("messageGUID", false);

            if (messageGUID != null)
            {
                using (var db = Global.GetConnection())
                {
                    var message = db.Ext_Message.Single(m => m.GUID == new Guid(messageGUID.ToString()));

                    //safety

                    foreach (var rec in message.Ext_MessageRecipient)
                    {
                        if (rec.RecipientUserGUID == SessionProps.UserGuid)
                        {
                            WebControlManager.RedirectWithQueryString("MessageCreate.aspx", new string[] { "msgSubject", "messageGUID" }, new string[] { String.Format("Sv: {0}", message.Header), message.GUID.ToString() });

                            break;
                        }
                    }
                }
            }
        }
        protected void grdUserTeams_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            GridView _gridView = (GridView)sender;

            // Get the selected index and the command name

            int    _selectedIndex = int.Parse(e.CommandArgument.ToString());
            string _commandName   = e.CommandName;

            switch (_commandName)
            {
            case ("Click"):
                _gridView.SelectedIndex = _selectedIndex;
                //WebControlManager.RedirectWithQueryString("UserTeam/UserTeamEdit_js.aspx", new string[] { "teamGUID" }, new string[] { _gridView.SelectedValue.ToString() });
                WebControlManager.RedirectWithQueryString("UserTeamEdit.aspx", new string[] { "teamGUID" }, new string[] { _gridView.SelectedValue.ToString() });
                break;

            case ("Activate"):
                _gridView.SelectedIndex = _selectedIndex;
                new UserTeamManagement(Global.ConnectionString, SessionProps).ActivateTeam(new Guid(_gridView.SelectedValue.ToString()));
                LoadTeams();
                break;

            case ("MarkAsPaid"):
                _gridView.SelectedIndex = _selectedIndex;
                new UserTeamManagement(Global.ConnectionString, SessionProps).MarkTeamAsPaid(new Guid(_gridView.SelectedValue.ToString()));
                LoadTeams();
                break;

            case ("Bonus"):
                _gridView.SelectedIndex = _selectedIndex;
                new UserTeamManagement(Global.ConnectionString, SessionProps).ToggleBonus(new Guid(_gridView.SelectedValue.ToString()));
                LoadTeams();
                break;
            }
        }
예제 #21
0
 protected void btnNewTournament_Click(object sender, EventArgs e)
 {
     WebControlManager.RedirectWithQueryString("MyTournamentEdit.aspx", new string[] { "dummy" }, new string[] { "dummy" });
 }
예제 #22
0
        public static void SendTweet(string tweet, string appendUrl, SessionProperties sessionProperties)
        {
            if (TwitterService == null)
            {
                InitiateTwitterAuthentication(sessionProperties);
            }


            if (TwitterService == null)
            {
                WebControlManager.SendAndLogErrorMessage(new Exception("TwitterService not initialized"), Parameters.Instance.MailSender, Parameters.Instance.SupportMail);
                //clear authentication, guess we need to authenticate again?
                Parameters.Instance.TwitterAccessToken       = null;
                Parameters.Instance.TwitterAccessTokenSecret = null;
                return;
            }

            try
            {
                //format the string, replace
                if (tweet.Contains("&"))
                {
                    tweet = HttpUtility.HtmlDecode(tweet);
                }

                string shortUrl = String.Empty;
                //parse url to shorturl
                if (!String.IsNullOrEmpty(appendUrl))
                {
                    IBitlyService s = new BitlyService("o_3cpfcndji4", "R_8e203358cb5ca0f68d809419b056b192");

                    string shortened = s.Shorten(appendUrl);
                    if (shortened != null)
                    {
                        shortUrl = " " + shortened;
                    }
                }
                var maxLength = 140 - shortUrl.Length;
                if (tweet.Length > maxLength)
                {
                    tweet = tweet.Substring(0, maxLength);
                }

                tweet += shortUrl;

                TwitterService.SendTweet(new SendTweetOptions()
                {
                    Status = tweet
                });

                // Likely this is an error; we don't have to go fishing for it
                TwitterError    error    = TwitterService.Response.Error;
                TwitterResponse response = TwitterService.Response;
                if (error != null || response.StatusCode != HttpStatusCode.OK)
                {
                    // You now know you have a real error from Twitter, and can handle it
                    string message;
                    if (error != null)
                    {
                        message = String.Format("Twitter error: {0} ({1})", error.Message, error.Code);
                    }
                    else
                    {
                        message = String.Format("Twitter response status not ok: {0} ({1})\n{2}",
                                                response.StatusDescription, response.StatusCode, response.Response);
                    }
                    WebControlManager.SendAndLogErrorMessage(new Exception(message), Parameters.Instance.MailSender, Parameters.Instance.SupportMail);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
예제 #23
0
 protected void btnAddNewTournament_Click(object sender, EventArgs e)
 {
     WebControlManager.ClearRedirectCache();
     Response.Redirect("AdminTournamentEdit.aspx");
 }
예제 #24
0
 protected void lnkNewsInstructions_Click(object sender, EventArgs e)
 {
     WebControlManager.RedirectWithQueryString("MediaPlayer.aspx", new string[] { "mediaToShow" }, new string[] { "NewsUpdate" });
 }
예제 #25
0
 protected void btnImport_Click(object sender, EventArgs e)
 {
     WebControlManager.ClearRedirectCache();
     Response.Redirect("AdminPlayerImport.aspx");
 }
예제 #26
0
 protected void btnAddNewClub_Click(object sender, EventArgs e)
 {
     WebControlManager.RedirectWithQueryString("AdminEditClub.aspx", new string[] { "tourGUID" }, new string[] { TourId.ToString() });
 }
예제 #27
0
 protected void btnCancel_Click(object sender, EventArgs e)
 {
     WebControlManager.RedirectWithQueryString("AdminTournamentEdit.aspx", new string[] { "GUID" }, new string[] { this.GetRedirectParameter("tourGUID", false).ToString() });
 }
예제 #28
0
 protected void btnSendMessage_Click(object sender, EventArgs e)
 {
     WebControlManager.RedirectWithQueryString("MessageCreate.aspx", new string[] { "msgSubject" }, new string[] { "" });
 }
예제 #29
0
 protected void lnkMessages_OnClick(object sender, EventArgs e)
 {
     WebControlManager.RedirectWithQueryString("UserMessages.aspx", new[] { "GUID" }, new[] { SessionProps.UserGuid.ToString() });
 }
예제 #30
0
 protected void btnBatchEditMatches_Click(object sender, EventArgs e)
 {
     WebControlManager.RedirectWithQueryString("AdminBatchEditMatches.aspx", new string[] { "GUID" }, new string[] { TourId.ToString() });
 }