public bool InsertUpdateCoachMaster(CoachProps pr) { bool isUpdate = false; try { if (pr.ID == 0) { Coach _coach = new Coach(); _coach.CoachName = pr.CoachName; _db.Coaches.Add(_coach); _db.SaveChanges(); isUpdate = true; } else { var _coach = _db.Coaches.Where(x => x.ID == pr.ID).FirstOrDefault(); if (_coach != null) { _coach.CoachName = pr.CoachName; _db.SaveChanges(); isUpdate = true; } } } catch (Exception ex) { } return(isUpdate); }
protected void btnSave_Click(object sender, EventArgs e) //THis is save button code { CoachProps pr = new CoachProps(); //this is propeties class instance from propeties pr.CoachName = txtCoachName.Text.Trim(); //here we are putting data in coach name field if (HiddenField1.Value != "") { pr.ID = Convert.ToInt32(HiddenField1.Value); //here hidden field value for editing the record } bool result = _serviceCoach.InsertUpdateCoachMaster(pr); //here we are calling insert update method for saving and updating the data if (result) { Response.Write("<script>alert('Record saved successfully')</script>"); } bindGrid(); }