private void PopulateEntity(ref SITECONTACT entity) { entity.SITEID = short.Parse(hdnSiteId.Value); entity.NAME = txtName.Text; entity.PHONE = txtPhone.Text; entity.EMAIL = txtEmailAddress.Text; }
private bool CopyFromForm() { using (var ctx = new Entities()) { try { if (btnFormButtons.EntityID.HasValue) { var id = btnFormButtons.EntityID; var dataSource = ctx.SITECONTACTs.FirstOrDefault(u => u.ID == id); PopulateEntity(ref dataSource); Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName, string.Format("Site Contact Edited. ID: {0}", dataSource.ID), LoggedInUser.ID); } else { var dataSource = new SITECONTACT(); PopulateEntity(ref dataSource); ctx.AddToSITECONTACTs(dataSource); Audit.Log(ctx, AuditType.Add, this.Page.GetType().FullName, string.Format("Site Contact Added. Name: {0}", dataSource.NAME), LoggedInUser.ID); } ctx.SaveChanges(); return(true); } catch (Exception ex) { ExceptionLog.WriteException("Save Site Contact", ex); ShowMessage(MessageType.Error, "There was an error saving this record"); } } return(false); }