public void UpdateEnterprise(EnterpriseModel enterprise) { using (AppTourEntities data = new AppTourEntities()) { ENTERPRISE current = data.ENTERPRISE.Where(x => enterprise.Id == x.ID).SingleOrDefault(); if (current != null) { try { current.NAME = enterprise.Name; current.DESCRIPTION = enterprise.Description; current.CREATION_DATE = enterprise.CreationDate; current.UPDATE_DATE = DateTime.Now; data.SaveChanges(); } catch (Exception e) { if (e.InnerException != null) { throw new Exception(e.InnerException.Message); } throw; } } } }
public Guid InsertEnterprise(EnterpriseModel enterprise) { Guid id = Guid.NewGuid(); if (enterprise == null) { throw new NullReferenceException(); } using (AppTourEntities data = new AppTourEntities()) { ENTERPRISE _new = new ENTERPRISE { ID = id, NAME = enterprise.Name, DESCRIPTION = enterprise.Description, CREATION_DATE = DateTime.Now, UPDATE_DATE = DateTime.Now }; data.ENTERPRISE.AddObject(_new); data.SaveChanges(); } return(id); }
public void DeleteEnterprise(EnterpriseModel enterprise) { if (enterprise == null) { throw new ArgumentNullException(); } using (AppTourEntities data = new AppTourEntities()) { ENTERPRISE current = data.ENTERPRISE.Where(p => p.ID == enterprise.Id).SingleOrDefault(); if (current != null) { try { data.DeleteObject(current); data.SaveChanges(); } catch (UpdateException ex) { if (ex.InnerException != null) { throw new UpdateException(ex.InnerException.Message); } throw; } catch (Exception e) { if (e.InnerException != null) { throw new Exception(e.InnerException.Message); } throw; } } } }