protected void Page_Load(object sender, EventArgs e)
        {
            player _player = new player();
            player_points _playerpoints = new player_points();
            IQueryable<prize> _prizes;
            string id = Request.QueryString["playerId"];

            Guid _guid = string.IsNullOrEmpty(id) ? new Guid() : new Guid(id);

            _player = _dal.GetPlayerBYID(new Guid(_dal.UserID.ToString()));

            playerName.InnerText = _player.Name.Substring(0, 9);
            lblshirtNumber.Text = _player.shirtNumber.ToString();

            int playerPointsToadd = _dal.GetTotalPointsToAdd();

            lblpoints.Text = playerPointsToadd.ToString();

            _playerpoints = _dal.GetPlayerPointsBYID(new Guid(_dal.UserID.ToString()));

            _prizes = _dal.getAllprizesByPoints(Convert.ToInt32(_playerpoints.points));

            rptPrize.DataSource = _prizes.ToList();
            rptPrize.DataBind();

            points.InnerText = _playerpoints.points.ToString();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            player _player = new player();

            Guid id = new Guid(Request.QueryString["id"].ToString());
            if (id == Guid.Empty)
            {
                _player.Name = txtFullName.Text;
                _player.address = txtAddress.Text;
                _player.player_id = _dal.GetNextPlayerId(16, 45);
                _player.gender = dlGenders.SelectedValue.ToString();
                _dal.AddToPlayers(_player);
                _dal.SoccerEntities.SaveChanges();
                Response.Redirect("default.aspx");
            }
            else
            {
                Guid _playerId = new Guid(Request.QueryString["id"].ToString());
                _player = _dal.GetPlayerBYID(_playerId);

                if (_player.player_id == "")
                    _player.player_id = _dal.GetNextPlayerId(16, 45);
                _player.gender = dlGenders.SelectedValue.ToString();

                _player.Name = txtFullName.Text;

                _player.address = txtAddress.Text;
                _player.player_id = _dal.GetNextPlayerId(16, 45);
                _player.gender = dlGenders.SelectedValue.ToString();

                _dal.SoccerEntities.SaveChanges();
                Response.Redirect("default.aspx");

            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                player _player = new player();
                Guid id = new Guid(Request.QueryString["id"].ToString());
                if (id == Guid.Empty)
                {

                }
                else
                {
                    _player = _dal.GetPlayerBYID(id);

                    if (!Page.IsPostBack)
                    {
                        if (_player.Name != null)
                            txtFullName.Text = _player.Name;
                        if (_player.address != null)
                            txtAddress.Text = _player.address;

                        dlGenders.SelectedValue = _player.gender;

                    }

                }

                var dlGendersSource = _dal.GetGenders();
                dlGenders.DataSource = dlGendersSource;
                dlGenders.DataValueField = "LookupValue";
                dlGenders.DataTextField = "LookupDescription";
                dlGenders.DataBind();

                string message = "";
                if (Context.User.IsInRole("canEdit"))
                {
                    //enable edit controls on page

                    message += "This user can edit a record";
                }
                else if (Context.User.IsInRole("canDelete"))
                {
                    //enable delete controls on page
                    message += "This user can delete a record.";
                }
                else if (Context.User.IsInRole("canAdd"))
                {
                    //enable delete controls on page
                    message += "This user can add a record.";
                }

            }
            catch(Exception ex)
            {

            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            player _player = new player();

            string id = Request.QueryString["playId"];

            Guid _guid = string.IsNullOrEmpty(id) ? new Guid() : new Guid(id);

            _player = _dal.GetPlayerBYID(_guid);
        }
        public void AddToPlayers(player record)
        {
            try
            {
                SoccerEntities.players.AddObject(record);

            }
            catch (Exception ex)
            {
                throw new EntityContextException("AddToPlayers failed.", ex);
            }
        }
        public player GetPlayerBYID(Guid _playerId)
        {
            try
            {
                if (_playerId == Guid.Empty)
                {
                    player _player = new player();
                    return _player;
                }
                else
                {
                    var q = SoccerEntities.players.Where(p => p.id == _playerId);

                    if (q == null)
                        throw new EntityContextException(string.Format("A player could not be found {0}!", _playerId));
                    else
                        return q.ToList()[0];
                }
            }
            catch (Exception ex)
            {
                throw new EntityContextException("GetPlayerBYID failed.", ex);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {

                string id = Request.QueryString["id"];
                if (id != "00000000-0000-0000-0000-000000000000")
                {
                    _playerId = string.IsNullOrEmpty(id) ? new Guid() : new Guid(id);

                }

                string teamIds = Request.QueryString["teamId"];
                if (teamIds != "00000000-0000-0000-0000-000000000000")
                {
                    _teamId = string.IsNullOrEmpty(id) ? new Guid() : new Guid(id);

                }

                  player _player = new player();

                  RadWindow1.VisibleOnPageLoad = false;

                _player = _dal.GetPlayerBYID(_playerId);

                _player.Name = txtFullName.Text;
                _player.email = txtEmail.Text;
                  _player.address = txtAddress.Text;

                  _player.description = txtDescription.InnerText;
                   _player.gender = dlGenders.SelectedValue.ToString();
                  _player.modifiedDate = DateTime.Now;
                _player.teamId = new Guid(ddlTeam.SelectedValue.ToString());

                if (Convert.ToDateTime(dateOfBirth.Text) == new DateTime(1900, 1, 1))

                _player.dob =Convert.ToDateTime(dateOfBirth.Text);

                if (_player.player_id == null)
                    _player.player_id = _dal.genPlayerID(new Guid("B9B2A89A-2295-4E48-BBA4-9DC28A1855FB"), new Guid("6E424913-A9A4-4A46-9785-C8AFA09C82DB"));

                if (_teamId != Guid.Empty)
                {
                    _player.teamId = _teamId;

                }

                 if (id == "00000000-0000-0000-0000-000000000000")
                {

                   player_points _points = new player_points();

                   _points.points = 200;
                   _points.pointsToRedeem = 20;
                   _points.authCreatedDate = DateTime.Now;
                   _points.authUserName = User.Identity.Name;

                   _player.player_points.Add(_points);

                    _dal.SoccerEntities.AddToplayers(_player);
                }

                 _dal.SoccerEntities.SaveChanges();
            }

            catch (Exception ex)
            {

                throw new EntityContextException("btnSave_Click failed.", ex);

            }

            Response.Redirect("default.aspx?teamId=00000000-0000-0000-0000-000000000000&id=00000000-0000-0000-0000-000000000000");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                MasterPagePropertiesInterface m = Master as MasterPagePropertiesInterface;
                if (m != null) m.themeTitle = "Players Edit";

                player _player = new player();

                   string id = Request.QueryString["id"];

                  Guid _guid= string.IsNullOrEmpty(id) ? new Guid() : new Guid(id);

                    _player = _dal.GetPlayerBYID(_guid);

                    if (!Page.IsPostBack)
                    {
                        if (_player.Name != null)
                            txtFullName.Text = _player.Name;
                        if (_player.address != null)
                            txtAddress.Text = _player.address;

                        if (_player.player_id != null)
                            lblPlayerId.Text = _player.player_id.ToString();

                        if (_player.email != null)
                           txtEmail.Text= _player.email.ToString();

                        if (_player.description != null)
                            txtDescription.InnerText = _player.description;

                        if (_player.dob != null)
                            dateOfBirth.Text = Convert.ToString(_player.dob);
                        if (_player.player_id != null)
                        lblPlayerId.Text = _player.player_id;

                        dlGenders.SelectedValue = _player.gender;

                }

                    if (_player.player_points.Count > 0)
                    {

                        grdPoints.DataSource = _dal.getAllPlayersPointsByPlayerId(_guid);
                        grdPoints.MasterTableView.DataKeyNames = new string[] { "playerId" };
                        grdPoints.DataBind();

                    }

                var dlGendersSource = _dal.GetGenders();
                dlGenders.DataSource = dlGendersSource;
                dlGenders.DataValueField = "LookupValue";
                dlGenders.DataTextField = "LookupDescription";
                dlGenders.DataBind();

                var dlteams = _dal.GetTeams();
                ddlTeam.DataSource = dlteams;
                ddlTeam.DataValueField = "LookupValue";
                ddlTeam.DataTextField = "LookupDescription";
                ddlTeam.DataBind();

                var dldistrcits =_dal.GetDistricts();

                ddldistrcit.DataSource = dldistrcits;
                ddldistrcit.DataValueField = "Prefix";
                ddldistrcit.DataTextField = "Name";
                ddldistrcit.DataBind();

            }
            catch (Exception ex)
            {
                throw new EntityContextException("Page Load Failed in Edit Players  .", ex);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //try
            //{

                string id = Request.QueryString["id"];
                if (id != "00000000-0000-0000-0000-000000000000")
                {
                    _playerId = string.IsNullOrEmpty(id) ? new Guid() : new Guid(id);

                }

                string teamIds = Request.QueryString["teamId"];
                if (teamIds != "00000000-0000-0000-0000-000000000000")
                {
                    _teamId = string.IsNullOrEmpty(teamIds) ? new Guid() : new Guid(teamIds);

                }

                player _player = new player();

                _player = _dal.GetPlayerBYID(_playerId);

                _player.Name = txtFullName.Text;
                _player.email = txtEmail.Text;
                _player.address = txtAddress.Text;

                _player.description = txtDescription.InnerText;
                _player.gender = dlGenders.SelectedValue.ToString();
                _player.modifiedDate = DateTime.Now;
                _player.teamId = new Guid(ddlTeam.SelectedValue.ToString());
                _player.description = txtDescription.InnerText;

                _player.shirtNumber = Convert.ToInt32(txtShirtNumber.Text);

                _player.createdDate = DateTime.Now;

            DateTime? _dob = (String.IsNullOrEmpty(dateOfBirth.Text) ? (DateTime?)null : DateTime.Parse(dateOfBirth.Text));

                    _player.dob =_dob;
                    _player.isDeleted = false;

                if (_player.player_id == null)
                    _player.player_id = _dal.genPlayerID(new Guid("B9B2A89A-2295-4E48-BBA4-9DC28A1855FB"), new Guid("6E424913-A9A4-4A46-9785-C8AFA09C82DB"));

                if (_teamId != Guid.Empty)
                {
                    _player.teamId = _teamId;

                }

                   if (_player.player_id  !="")
                   _dal.SoccerEntities.players.Add(_player);

                   _dal.SoccerEntities.SaveChanges();
            //}

            //catch (Exception ex)
            //{

            //    throw new EntityContextException("btnSave_Click failed.", ex);

            //}

            Response.Redirect("default.aspx?teamId=00000000-0000-0000-0000-000000000000&id=00000000-0000-0000-0000-000000000000");
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the players EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToplayers(player player)
 {
     base.AddObject("players", player);
 }
 /// <summary>
 /// Create a new player object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 public static player Createplayer(global::System.Guid id)
 {
     player player = new player();
     player.id = id;
     return player;
 }