private void btnOK_Click(object sender, EventArgs e) { try { if (this.ValidateChildren()) { TBL_MP_Master_City model = null; if (CityID == 0) { model = new TBL_MP_Master_City() { CityName = txtCityName.Text, FK_BranchID = Program.CURR_USER.BranchID, FK_CompanyID = Program.CURR_USER.CompanyID, STDCode = txtSTDCode.Text }; model.fk_CountryId = ((SelectListItem)cboCountries.SelectedItem).ID; model.fk_StateId = ((SelectListItem)cboStates.SelectedItem).ID; model.IsActive = chkIsActive.Checked; _UNIT.AppDBContext.TBL_MP_Master_City.Add(model); _UNIT.AppDBContext.SaveChanges(); this.CityID = model.pk_CityId; this.DialogResult = DialogResult.OK; } else { model = _UNIT.AppDBContext.TBL_MP_Master_City.Where(x => x.pk_CityId == CityID).FirstOrDefault(); model.CityName = txtCityName.Text; model.fk_CountryId = ((SelectListItem)cboCountries.SelectedItem).ID; model.fk_StateId = ((SelectListItem)cboStates.SelectedItem).ID; model.STDCode = txtSTDCode.Text; model.IsActive = chkIsActive.Checked; _UNIT.AppDBContext.SaveChanges(); this.DialogResult = DialogResult.OK; } } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "frmAddEditCity::btnOK_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ScatterData() { TBL_MP_Master_City model = (new ServiceMASTERS()).GetCityDBRecordByCityID(this.CityID); if (model != null) { PopulateCountryDropDown(); if (model.fk_CountryId != 0) { cboCountries.SelectedItem = ((List <SelectListItem>)cboCountries.DataSource).Where(x => x.ID == model.fk_CountryId).FirstOrDefault(); this.CountryID = model.fk_CountryId; } PopulateStatesDropDowns(); if (model.fk_StateId != 0) { cboStates.SelectedItem = ((List <SelectListItem>)cboStates.DataSource).Where(x => x.ID == model.fk_StateId).FirstOrDefault(); this.StateID = model.fk_StateId; } txtCityName.Text = model.CityName; txtSTDCode.Text = model.STDCode; chkIsActive.Checked = model.IsActive; } }