コード例 #1
0
ファイル: TMSPlayer.aspx.cs プロジェクト: guriiii/TMSSystem
        protected void btnSave_Click(object sender, EventArgs e)
        {
            PlayerVMModel pr = new PlayerVMModel();

            pr.Name     = txtName.Text.Trim();
            pr.TeamID   = Convert.ToInt32(TeamID.Text);
            pr.Position = Position.Text.Trim();
            pr.Gender   = GenderList.Text;
            if (HiddenField1.Value != "")
            {
                pr.ID = Convert.ToInt32(HiddenField1.Value);
            }
            bool result = _service.AddEditPlayerMaster(pr);

            if (result)
            {
                Response.Write("<script>alert('Record saved successfully')</script>");
                Response.Redirect("Player.aspx");
            }
            bindGrid();
        }
コード例 #2
0
ファイル: PlayerService.cs プロジェクト: guriiii/TMSSystem
        public bool AddEditPlayerMaster(PlayerVMModel pr)
        {
            bool isUpdate = false;

            try
            {
                if (pr.ID == 0)
                {
                    Player _player = new Player();
                    _player.Name      = pr.Name;
                    _player.Position  = pr.Position;
                    _player.Gender    = pr.Gender;
                    _player.TeamID    = pr.TeamID;
                    _player.CoachName = pr.CoachName;
                    _db.Players.Add(_player);
                    _db.SaveChanges();
                    isUpdate = true;
                }
                else
                {
                    var _player = _db.Players.Where(x => x.ID == pr.ID).FirstOrDefault();
                    if (_player != null)
                    {
                        _player.Name      = pr.Name;
                        _player.Position  = pr.Position;
                        _player.Gender    = pr.Gender;
                        _player.TeamID    = pr.TeamID;
                        _player.CoachName = pr.CoachName;
                        _db.SaveChanges();
                        isUpdate = true;
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(isUpdate);
        }