protected void btnSaveEdit_Click(object sender, EventArgs e) { try { #region Save Facilities_Record record; if (lblDateAdded.Text == string.Empty) record = new Facilities_Record(); else record = CurrentRecord(); string originalFacilityName = record.Facility_Name, currentUser = HttpContext.Current.User.Identity.Name.ToString(); record.Facility_Name = txtFacilityName.Text; record.Entity_Name = ddlEntity.SelectedItem.Text; record.BusinessUnit_Name = ddlBusinessUnit.SelectedItem.Text; record.PortalPage_Name = ddlPortalPage.SelectedItem.Text; record.Original_Facility = originalFacilityName; record.Visible = ddlVisible.SelectedValue.ToString(); record.CostCenter = txtCostCenter.Text; record.RollupCostCenter = txtRollupCostCenter.Text; if (hfNewFacility.Value == "New Facility") record.Review_Ind = "Y"; else record.Review_Ind = ddlValidatedValue.SelectedValue.ToString(); #region Checks if Facility Name exists or not Facilities BOFacilties = (Facilities)GetBOFacilities(); var facilityCountQuery = (from c in BOFacilties where c.Facility_Name == record.Facility_Name.Trim().ToUpper() select c.Facility_Name); int facilityCount = facilityCountQuery.Count(); //if ((originalFacilityName == string.Empty) && facilityCount != 0) //{ // ScriptManager.RegisterStartupScript(Page, typeof(Page), "SymbolError", "alert('Facility with that name already exists.')", true); // return; //} #endregion if (record.AddedBy_Name.Length == 0) { EmployeeInfo ei = new EmployeeInfo(); record.AddedBy_Name = currentUser; record.DataOwner_Name = ei.FirstLastName(currentUser); } if (ddlStatus.SelectedItem.Text == "DISABLED") record.Decommissioned_By = currentUser; else if (ddlStatus.SelectedItem.Text == "ENABLED") record.Decommissioned_By = string.Empty; record.Save(); int newRecord = record.ReturnedDMPK; #endregion #region Email Message //if its staging if (AppConfiguration.Current.ConfigurationName == "Production") { if (lblDateAdded.Text == string.Empty) { SmtpClient smtp = new SmtpClient(AppConfiguration.Current.SMTPServer); MailMessage msg = new MailMessage(); msg.From = new MailAddress("*****@*****.**"); msg.To.Add("*****@*****.**"); msg.Subject = "GHG Emissions Validation Portal - New Facility Created"; msg.IsBodyHtml = true; string facilityLink = "http://dev-ghgemissions.ihess.com/Admin/FacilityManagement?Facility=" + HttpUtility.UrlEncode(record.Facility_Name); StringBuilder html = new StringBuilder(); html.AppendFormat("<p>The following facilty has been created in the GHG Emissions Validation Portal.</p>"); html.AppendFormat("<p><b>Facility Name: " + record.Facility_Name + "</b></p>"); html.AppendFormat("<p>Please click <a href='" + facilityLink + "'>here</a> to review and approve the Facility.</p>"); html.AppendFormat("<p>This is a system generated mail, please do not reply to this email. If you have questions please contact <a href='mailto:[email protected]'>[email protected]</a></p>"); html.AppendFormat("<p>Thank you,<br />System Administrator</p>"); msg.Body = html.ToString(); smtp.Send(msg); } } #endregion EditMode(false); DatabindSelection(newRecord); NewItemVisible(false); hfNewFacility.Value = ""; hfChangeDetector.Value = ""; } catch (Exception ex) { PopAddFacilityUser.Hide(); PopAddPrimaryOwner.Hide(); PopErrorMsg.Hide(); PopImportFacilityUsers.Hide(); PopVerifyChanges.Hide(); PopVerifyDisable.Hide(); PopDuplicateFacility.Show(); //handles duplicate key error } }