private bool CopyFromForm() { using (var ctx = new Entities()) { try { if (btnFormButtons.EntityID.HasValue) { var id = btnFormButtons.EntityID; var dataSource = ctx.SITEs.FirstOrDefault(u => u.ID == id); PopulateEntity(ref dataSource); Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName, string.Format("Site Edited. ID: {0}", dataSource.ID), LoggedInUser.ID); } ctx.SaveChanges(); return(true); } catch (Exception ex) { ExceptionLog.WriteException("Save Site", ex); ShowMessage(MessageType.Error, "There was an error saving this record"); } } return(false); }
private bool CopyFromForm() { using (var ctx = new Entities()) { try { var user = ctx.SYSTEMUSERs.FirstOrDefault( u => u.DELETED == 0 && u.EMAIL == txtUsername.Text); if (user != null) { // create audit Audit.Log(ctx, AuditType.ForgottenPassword, this.Page.GetType().FullName, user.ID); // TODO: send password // done return(true); } else { ShowMessage(MessageType.Error, "Email address not found - please check and try again"); } } catch (Exception ex) { ExceptionLog.WriteException("User Login", ex); ShowExceptionMessage(); } return(false); } }
private bool DeleteEntity() { using (var ctx = new Entities()) { try { var id = btnFormButtons.EntityID; var dataSource = ctx.REPORTs.FirstOrDefault(u => u.ID == id); dataSource.DELETED = 1; EntityExtensions.ExecuteProcedure(new EntityConnection(ctx.Connection.ConnectionString), "Entities.ClearReportFields", new KeyValuePair <string, object>("REPORT_ID", dataSource.ID)); EntityExtensions.ExecuteProcedure(new EntityConnection(ctx.Connection.ConnectionString), "Entities.ClearReportSites", new KeyValuePair <string, object>("REPORT_ID", dataSource.ID)); Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName, string.Format("Report Marked as Deleted. ID: {0}", dataSource.ID), LoggedInUser.ID); ctx.SaveChanges(); return(true); } catch (Exception ex) { ExceptionLog.WriteException("Delete Report", ex); ShowMessage(MessageType.Error, "There was an error deleting this record"); } } return(false); }
private bool DeleteEntity() { using (var ctx = new Entities()) { try { var id = btnFormButtons.EntityID; var dataSource = ctx.UNITs.FirstOrDefault(u => u.ID == id); Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName, string.Format("Project Marked as Deleted. Name: {0}", dataSource.NAME), LoggedInUser.ID); ctx.DeleteObject(dataSource); ctx.SaveChanges(); return(true); } catch (Exception ex) { ExceptionLog.WriteException("Delete Unit", ex); ShowMessage(MessageType.Error, "There was an error deleting this record"); } } return(false); }
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 { var dataSource = new SITE { NAME = txtSitename.Text, DESCRIPTION = txtDescription.Text, CREATEDON = DateTime.Now, MODIFIEDON = DateTime.Now, DELETED = 0 }; ctx.AddToSITEs(dataSource); ctx.SaveChanges(); return(true); } catch (Exception ex) { ExceptionLog.WriteException("Save Site", ex); } } return(false); }
private bool CopyFromForm() { using (var ctx = new Entities()) { try { var dataSource = new FIELDGROUP(); if (btnFormButtons.EntityID.HasValue) { var id = btnFormButtons.EntityID; dataSource = ctx.FIELDGROUPs.FirstOrDefault(u => u.ID == id); PopulateEntity(ref dataSource); Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName, string.Format("Group Edited. ID: {0}", dataSource.ID), LoggedInUser.ID); } else { dataSource = new FIELDGROUP { CREATEDON = DateTime.Now }; PopulateEntity(ref dataSource); ctx.AddToFIELDGROUPs(dataSource); Audit.Log(ctx, AuditType.Add, this.Page.GetType().FullName, string.Format("Group Added: {0}", dataSource.NAME), LoggedInUser.ID); } ctx.SaveChanges(); // delete fields EntityExtensions.ExecuteProcedure(new EntityConnection(ctx.Connection.ConnectionString), "Entities.ClearGroupFields", new KeyValuePair <string, object>("GROUP_ID", dataSource.ID)); // save fields foreach (var item in jsGroupFields.SelectedItems) { var groupField = new FIELDGROUPFIELD { FIELDGROUPID = dataSource.ID, FIELDID = (short)int.Parse(item.Value) }; ctx.AddToFIELDGROUPFIELDs(groupField); } ctx.SaveChanges(); return(true); } catch (Exception ex) { ExceptionLog.WriteException("Save Group", ex); ShowMessage(MessageType.Error, "There was an error saving this record"); } } return(false); }
private bool CopyFromForm() { using (var ctx = new Entities()) { try { var userCheck = ctx.SYSTEMUSERs.FirstOrDefault( u => u.EMAIL == txtEmailAddress.Text && u.ID != btnFormButtons.EntityID); if (userCheck != null) { ShowMessage(MessageType.Error, "This email address is already registered"); return(false); } if (btnFormButtons.EntityID.HasValue) { var id = btnFormButtons.EntityID; var dataSource = ctx.SYSTEMUSERs.FirstOrDefault(u => u.ID == id); PopulateEntity(ref dataSource); Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName, string.Format("User Edited. ID: {0}", dataSource.ID), LoggedInUser.ID); } else { var dataSource = new SYSTEMUSER { CREATEDON = DateTime.Now, DELETED = 0, LASTLOGGEDON = DateTime.Now }; PopulateEntity(ref dataSource); ctx.AddToSYSTEMUSERs(dataSource); Audit.Log(ctx, AuditType.Add, this.Page.GetType().FullName, string.Format("User Added. Email: {0}", dataSource.EMAIL), LoggedInUser.ID); } ctx.SaveChanges(); return(true); } catch (Exception ex) { ExceptionLog.WriteException("Save User", ex); ShowMessage(MessageType.Error, "There was an error saving this record"); } } return(false); }
public ActionResult Product() { try { ProductsRepo Pro = new ProductsRepo(); ViewBag.AceCatList = Pro.getAceProductsCategorylist(); ViewBag.DxCatList = Pro.getDxProductsCategorylist(); } catch (Exception ex) { ExceptionLog.WriteException(ex, "POSController", "AllProducts"); } return(View()); }
public ActionResult AllProducts() { try { ProductsRepo Productrepo = new ProductsRepo(); List <TblProduct> Productslist = Productrepo.getProductslist(); ViewBag.Productslist = Productslist; } catch (Exception ex) { ExceptionLog.WriteException(ex, "POSController", "AllProducts"); } return(View()); }
private bool CopyFromForm() { using (var ctx = new Entities()) { try { if (btnFormButtons.EntityID.HasValue) { var id = btnFormButtons.EntityID; var dataSource = ctx.PROJECTs.FirstOrDefault(u => u.ID == id); PopulateEntity(ref dataSource); Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName, string.Format("Project Edited. ID: {0}", dataSource.ID), LoggedInUser.ID); } else { var dataSource = new PROJECT { CREATEDON = DateTime.Now, DELETED = 0 }; PopulateEntity(ref dataSource); ctx.AddToPROJECTs(dataSource); Audit.Log(ctx, AuditType.Add, this.Page.GetType().FullName, string.Format("Project Added. Name: {0}", dataSource.NAME), LoggedInUser.ID); } ctx.SaveChanges(); return(true); } catch (Exception ex) { ExceptionLog.WriteException("Save Project", ex); ShowMessage(MessageType.Error, "There was an error saving this record"); } } return(false); }
private bool CopyFromForm() { using (var ctx = new Entities()) { var site = ctx.SITEs.FirstOrDefault(s => s.DELETED == 0 && s.NAME == txtSitename.Text); if (site != null) { lblSiteExists.Visible = true; return(false); } lblSiteExists.Visible = false; try { var dataSource = new SITE { NAME = txtSitename.Text, DESCRIPTION = txtDescription.Text, CREATEDON = DateTime.Now, MODIFIEDON = DateTime.Now, DELETED = 0 }; ctx.AddToSITEs(dataSource); ctx.SaveChanges(); return(true); } catch (Exception ex) { ExceptionLog.WriteException("Save Site", ex); } } return(false); }
/// <summary> /// Attempt the login /// </summary> /// <returns></returns> private bool Login() { using (var ctx = new Entities()) { try { var user = ctx.SYSTEMUSERs.FirstOrDefault( u => u.DELETED == 0 && u.EMAIL == txtUsername.Text & u.PASSWORD == txtPassword.Text); if (user != null) { // update user.LASTLOGGEDON = DateTime.Now; // audit Audit.Log(ctx, AuditType.Login, this.Page.GetType().FullName, user.ID); ctx.SaveChanges(); // save to session LoggedInUser = user; // done return(true); } } catch (Exception ex) { ExceptionLog.WriteException("User Login", ex); ShowExceptionMessage(); } return(false); } }
private bool CopyFromForm() { var isValid = true; if (DateTime.ParseExact(txtDateFrom.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture) > DateTime.ParseExact(txtDateTo.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture)) { ShowMessage(MessageType.Warning, "Your Date From date should be before your Date To date"); isValid = false; } var selectedFields = jsReportFields_value.Value.Split(','); if (selectedFields.Length == 0) { ShowMessage(MessageType.Warning, "You have not chosen any fields - please select at least 1 field."); isValid = false; } if (jsReportSites.SelectedItems.Count == 0) { ShowMessage(MessageType.Warning, "You have not chosen any sites - please select at least 1 site."); isValid = false; } if (selectedFields.Length > 256) { ShowMessage(MessageType.Warning, "You have chosen too many fields, please select less than 256."); isValid = false; } if (!isValid) { return(false); } using (var ctx = new Entities()) { try { var dataSource = new REPORT(); if (btnFormButtons.EntityID.HasValue) { var id = btnFormButtons.EntityID; dataSource = ctx.REPORTs.FirstOrDefault(u => u.ID == id); PopulateEntity(ref dataSource); Audit.Log(ctx, AuditType.Edit, this.Page.GetType().FullName, string.Format("Report Edited. ID: {0}", dataSource.ID), LoggedInUser.ID); // remove any cached data var datastore = new DataStore(ConfigurationSettings.AppSettings["datastore_path"]); datastore.Remove(id.Value); } else { dataSource = new REPORT { CREATEDON = DateTime.Now, DELETED = 0 }; PopulateEntity(ref dataSource); ctx.AddToREPORTs(dataSource); Audit.Log(ctx, AuditType.Add, this.Page.GetType().FullName, string.Format("Report Added. Name: {0}", dataSource.NAME), LoggedInUser.ID); } ctx.SaveChanges(); var fieldsChanged = (jsReportFields_changed.Value != string.Empty); if (fieldsChanged) { EntityExtensions.ExecuteProcedure(new EntityConnection(ctx.Connection.ConnectionString), "Entities.ClearReportFields", new KeyValuePair <string, object>("REPORT_ID", dataSource.ID)); var order = 0; foreach (var item in selectedFields) { var reportField = new REPORTFIELD { REPORTID = dataSource.ID, FIELDID = (short)int.Parse(item), FIELDORDER = (short)order }; ctx.AddToREPORTFIELDs(reportField); order++; } } if (jsReportSites.ValueChanged) { EntityExtensions.ExecuteProcedure(new EntityConnection(ctx.Connection.ConnectionString), "Entities.ClearReportSites", new KeyValuePair <string, object>("REPORT_ID", dataSource.ID)); foreach (var item in jsReportSites.SelectedItems) { var reportSite = new REPORTSITE { REPORTID = dataSource.ID, SITEID = (short)int.Parse(item.Value) }; ctx.AddToREPORTSITEs(reportSite); } } if (fieldsChanged || jsReportSites.ValueChanged) { ctx.SaveChanges(); } return(true); } catch (Exception ex) { ExceptionLog.WriteException("Save Report", ex); ShowMessage(MessageType.Error, "There was an error saving this record"); } } return(false); }