private bool CopyFromForm() { using (var ctx = new Entities()) { try { var dataSource = new FIELD { NAME = txtSitename.Text, CREATEDON = DateTime.Now, MODIFIEDON = DateTime.Now }; ctx.AddToFIELDs(dataSource); ctx.SaveChanges(); return(true); } catch (Exception ex) { ExceptionLog.WriteException("Save Site", ex); } } return(false); }
private bool CopyFromForm() { using (var ctx = new Entities()) { try { if (btnFormButtons.EntityID.HasValue) { var id = btnFormButtons.EntityID; var dataSource = ctx.FIELDs.FirstOrDefault(u => u.ID == id); PopulateEntity(ref dataSource); Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName, string.Format("Field Edited. ID: {0}", dataSource.ID), LoggedInUser.ID); } else { var dataSource = new FIELD { CREATEDON = DateTime.Now }; PopulateEntity(ref dataSource); ctx.AddToFIELDs(dataSource); Audit.Log(ctx, AuditType.Add, this.Page.GetType().FullName, string.Format("Field Added. Name: {0}", txtName.Text), LoggedInUser.ID); } ctx.SaveChanges(); return(true); } catch (Exception ex) { ExceptionLog.WriteException("Save Field", ex); ShowMessage(MessageType.Error, "There was an error saving this record"); } } return(false); }