public string GetProjectSiteAddress(int projectID) { string strAddress = string.Empty; try { TBL_MP_PMC_ProjectMaster dbProject = _dbContext.TBL_MP_PMC_ProjectMaster.Where(x => x.PK_ProjectID == projectID).FirstOrDefault(); int SiteAddressID = dbProject.SiteClientAddressID; Tbl_MP_Master_Party_Address dbAddress = _dbContext.Tbl_MP_Master_Party_Address.Where(x => x.PK_AddressID == SiteAddressID).FirstOrDefault(); strAddress = dbAddress.Address; strAddress += string.Format("\n{0} {1}, {2}", dbAddress.TBL_MP_Master_City.CityName, dbAddress.TBL_MP_Master_State.StateName, dbAddress.TBL_MP_Master_Country.CountryName ); } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceProject::GetProjectSiteAddress", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(strAddress); }
private void ScatterData() { try { Tbl_MP_Master_Party_Address model = (new ServiceParties()).GetPartyAddressForAddressID(this.PartyAddressID); if (model != null) { cboParties.SelectedItem = ((List <SelectListItem>)cboParties.DataSource).Where(x => x.ID == model.FK_PartyID).FirstOrDefault(); txtAddress.Text = model.Address; cboCountries.SelectedItem = ((List <SelectListItem>)cboCountries.DataSource).Where(x => x.ID == model.FK_CountryID).FirstOrDefault(); selectedCountryID = model.FK_CountryID; PopulateStatesDropdown(); cboStates.SelectedItem = ((List <SelectListItem>)cboStates.DataSource).Where(x => x.ID == model.FK_StateID).FirstOrDefault(); selectedStateID = model.FK_StateID; PopulateCitiesDropdown(); cboCities.SelectedItem = ((List <SelectListItem>)cboCities.DataSource).Where(x => x.ID == model.FK_CityID).FirstOrDefault(); txtPINCode.Text = model.PIN_Code; chkIsActive.Checked = model.IsActive; } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "frmAddEditAddress::ScatterData", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool UpdatePartyAddress(Tbl_MP_Master_Party_Address model) { bool result = false; try { Tbl_MP_Master_Party_Address dbModel = _dbContext.Tbl_MP_Master_Party_Address.Where(x => x.PK_AddressID == model.PK_AddressID).FirstOrDefault(); if (dbModel != null) { dbModel.FK_PartyID = model.FK_PartyID; dbModel.Address = model.Address; dbModel.FK_CountryID = model.FK_CountryID; dbModel.FK_StateID = model.FK_StateID; dbModel.FK_CityID = model.FK_CityID; dbModel.PIN_Code = model.PIN_Code; dbModel.IsActive = model.IsActive; _dbContext.SaveChanges(); result = true; } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceParties::UpdatePartyAddress", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(result); }
private void btnOK_Click(object sender, EventArgs e) { try { if (!this.ValidateChildren()) { return; } Tbl_MP_Master_Party_Address model = null; if (this.PartyAddressID == 0) { model = new Tbl_MP_Master_Party_Address(); } else { model = (new ServiceParties()).GetPartyAddressForAddressID(this.PartyAddressID); } model.FK_PartyID = ((SelectListItem)cboParties.SelectedItem).ID; model.Address = txtAddress.Text; model.FK_CountryID = ((SelectListItem)cboCountries.SelectedItem).ID; model.FK_StateID = ((SelectListItem)cboStates.SelectedItem).ID; model.FK_CityID = ((SelectListItem)cboCities.SelectedItem).ID; model.PIN_Code = txtPINCode.Text; model.IsActive = chkIsActive.Checked; if (this.PartyAddressID == 0) { (new ServiceParties()).AddNewPartyAddress(model); } else { (new ServiceParties()).UpdatePartyAddress(model); } 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, "frmAddEditAddress::btnOK_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Tbl_MP_Master_Party_Address GetPartyAddressForAddressID(int addID) { Tbl_MP_Master_Party_Address model = null; try { model = _dbContext.Tbl_MP_Master_Party_Address.Where(x => x.PK_AddressID == addID).FirstOrDefault(); } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceParties::GetPartyAddressForAddressID", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(model); }
public int AddNewPartyAddress(Tbl_MP_Master_Party_Address model) { int newID = 0; try { _dbContext.Tbl_MP_Master_Party_Address.Add(model); _dbContext.SaveChanges(); newID = model.PK_AddressID; } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceParties::AddNewPartyAddress", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(newID); }