public void DeleteAllRowsOfPolicyTable() { using (var db = new VuelingEntities()) { using (var dbTransaction = db.Database.BeginTransaction()) { try { db.Database.ExecuteSqlCommand(Resource_Infrastructure_Repository.QueryToDeleteAllRowsInPolicyTable); db.SaveChanges(); dbTransaction.Commit(); } catch (Exception e) { dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.CantDeleteMsg, e); } } } }
public bool HasTheDbBeenModified(List <Client> newListClients, VuelingEntities db) { List <Client> currentListClients = db.Client.OrderBy(x => x.Name).ToList(); if (newListClients.Count() == currentListClients.Count()) { newListClients = newListClients.OrderBy(x => x.Name).ToList(); for (int i = 0; i < currentListClients.Count(); i++) { if (!currentListClients[i].Id.Equals(newListClients[i].Id)) { return(true); } } } else { return(true); } return(false); }
public bool HasTheDbBeenModified(List <Policy> newListPolicies) { using (var db = new VuelingEntities()) { try { List <Policy> currentListPolicies = db.Policy.OrderBy(x => x.Id).ToList(); if (newListPolicies.Count() == currentListPolicies.Count()) { newListPolicies = newListPolicies.OrderBy(x => x.Id).ToList(); for (int i = 0; i < currentListPolicies.Count(); i++) { if (!currentListPolicies[i].Id.Equals(newListPolicies[i].Id)) { return(true); } } } else { return(true); } return(false); } #region Exceptions With Log catch (DbUpdateConcurrencyException e) { Log.Error(Resource_Infrastructure_Repository.ConcurrencyError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.ConcurrencyError, e); } catch (DbUpdateException e) { Log.Error(Resource_Infrastructure_Repository.DbUpdateError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.DbUpdateError, e); } catch (DbEntityValidationException e) { Log.Error(Resource_Infrastructure_Repository.DbEntityValidationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.DbEntityValidationError, e); } catch (NotSupportedException e) { Log.Error(Resource_Infrastructure_Repository.NotSuportedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.NotSuportedError, e); } catch (ObjectDisposedException e) { Log.Error(Resource_Infrastructure_Repository.ObjectDisposedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.ObjectDisposedError, e); } catch (InvalidOperationException e) { Log.Error(Resource_Infrastructure_Repository.InvalidOperationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.InvalidOperationError, e); #endregion } } }
public List <PolicyEntity> GetPoliciesByUserName(string username) { List <PolicyEntity> listPolicyEntities; List <Policy> listPolicies; using (var db = new VuelingEntities()) { using (var dbTransaction = db.Database.BeginTransaction()) { try { listPolicies = db.Policy.Where(p => p.ClientId.Equals(username)).ToList(); var config = new MapperConfiguration(cfg => cfg.CreateMap <Policy, PolicyEntity>()); IMapper iMapper = config.CreateMapper(); listPolicyEntities = iMapper.Map <List <Policy>, List <PolicyEntity> >(listPolicies); return(listPolicyEntities); } #region Exceptions With Log catch (DbUpdateConcurrencyException e) { Log.Error(Resource_Infrastructure_Repository.ConcurrencyError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.ConcurrencyError, e); } catch (DbUpdateException e) { Log.Error(Resource_Infrastructure_Repository.DbUpdateError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.DbUpdateError, e); } catch (DbEntityValidationException e) { Log.Error(Resource_Infrastructure_Repository.DbEntityValidationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.DbEntityValidationError, e); } catch (NotSupportedException e) { Log.Error(Resource_Infrastructure_Repository.NotSuportedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.NotSuportedError, e); } catch (ObjectDisposedException e) { Log.Error(Resource_Infrastructure_Repository.ObjectDisposedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.ObjectDisposedError, e); } catch (InvalidOperationException e) { Log.Error(Resource_Infrastructure_Repository.InvalidOperationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.InvalidOperationError, e); #endregion } } } }
public PolicyEntity Add(PolicyEntity model) { using (var db = new VuelingEntities()) { using (var dbTransaction = db.Database.BeginTransaction()) { try { Policy policy = null; var config = new MapperConfiguration(cfg => cfg.CreateMap <PolicyEntity, Policy>() .ReverseMap()); IMapper iMapper = config.CreateMapper(); policy = iMapper.Map <PolicyEntity, Policy>(model); Policy policyAdded = db.Policy.Add(policy); db.SaveChanges(); dbTransaction.Commit(); PolicyEntity policyEntityAdded = iMapper.Map <Policy, PolicyEntity>(policyAdded); return(policyEntityAdded); } #region Exceptions With Log catch (DbUpdateConcurrencyException e) { Log.Error(Resource_Infrastructure_Repository.ConcurrencyError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.ConcurrencyError, e); } catch (DbUpdateException e) { Log.Error(Resource_Infrastructure_Repository.DbUpdateError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.DbUpdateError, e); } catch (DbEntityValidationException e) { Log.Error(Resource_Infrastructure_Repository.DbEntityValidationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.DbEntityValidationError, e); } catch (NotSupportedException e) { Log.Error(Resource_Infrastructure_Repository.NotSuportedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.NotSuportedError, e); } catch (ObjectDisposedException e) { Log.Error(Resource_Infrastructure_Repository.ObjectDisposedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.ObjectDisposedError, e); } catch (InvalidOperationException e) { Log.Error(Resource_Infrastructure_Repository.InvalidOperationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.InvalidOperationError, e); #endregion } } } }
public List <PolicyEntity> AddList(List <PolicyEntity> listPolicyEntities) { using (var db = new VuelingEntities()) { using (var dbTransaction = db.Database.BeginTransaction()) { try { List <Policy> listPolicies = null; var config = new MapperConfiguration(cfg => cfg.CreateMap <PolicyEntity, Policy>().ReverseMap()); IMapper iMapper = config.CreateMapper(); listPolicies = iMapper.Map <List <PolicyEntity>, List <Policy> >(listPolicyEntities); if (HasTheDbBeenModified(listPolicies)) { DeleteAllRowsOfPolicyTable(); foreach (var policy in listPolicies) { db.Policy.Add(policy); } db.SaveChanges(); dbTransaction.Commit(); } List <PolicyEntity> listPolicyEntitiesAdded = iMapper.Map <List <Policy>, List <PolicyEntity> >(listPolicies); return(listPolicyEntitiesAdded); } #region Exceptions With Log catch (DbUpdateConcurrencyException e) { Log.Error(Resource_Infrastructure_Repository.ConcurrencyError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.ConcurrencyError, e); } catch (DbUpdateException e) { Log.Error(Resource_Infrastructure_Repository.DbUpdateError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.DbUpdateError, e); } catch (DbEntityValidationException e) { Log.Error(Resource_Infrastructure_Repository.DbEntityValidationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.DbEntityValidationError, e); } catch (NotSupportedException e) { Log.Error(Resource_Infrastructure_Repository.NotSuportedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.NotSuportedError, e); } catch (ObjectDisposedException e) { Log.Error(Resource_Infrastructure_Repository.ObjectDisposedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.ObjectDisposedError, e); } catch (InvalidOperationException e) { Log.Error(Resource_Infrastructure_Repository.InvalidOperationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.InvalidOperationError, e); #endregion } } } }
public PolizasRepository( VuelingEntities vuelingEntities) { this.db = vuelingEntities; }
public ClientEntity GetUserByPolicyId(string idPolicy) { ClientEntity clientEntity; Client client; using (var db = new VuelingEntities()) { try { client = db.Policy .Select(p => p.Client) .FirstOrDefault(p => p.Id.Equals(idPolicy)); var config = new MapperConfiguration(cfg => cfg.CreateMap <Client, ClientEntity>()); IMapper iMapper = config.CreateMapper(); clientEntity = iMapper.Map <Client, ClientEntity>(client); return(clientEntity); } #region Exceptions With Log catch (DbUpdateConcurrencyException e) { Log.Error(Resource_Infrastructure_Repository.ConcurrencyError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.ConcurrencyError, e); } catch (DbUpdateException e) { Log.Error(Resource_Infrastructure_Repository.DbUpdateError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.DbUpdateError, e); } catch (DbEntityValidationException e) { Log.Error(Resource_Infrastructure_Repository.DbEntityValidationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.DbEntityValidationError, e); } catch (NotSupportedException e) { Log.Error(Resource_Infrastructure_Repository.NotSuportedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.NotSuportedError, e); } catch (ObjectDisposedException e) { Log.Error(Resource_Infrastructure_Repository.ObjectDisposedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.ObjectDisposedError, e); } catch (InvalidOperationException e) { Log.Error(Resource_Infrastructure_Repository.InvalidOperationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.InvalidOperationError, e); #endregion } } }
public List <ClientEntity> GetAll() { List <ClientEntity> ListClientEntities; List <Client> ListClients; using (var db = new VuelingEntities()) { try { ListClients = db.Client.ToList(); var config = new MapperConfiguration(cfg => cfg.CreateMap <Client, ClientEntity>()); IMapper iMapper = config.CreateMapper(); ListClientEntities = iMapper.Map <List <Client>, List <ClientEntity> >(ListClients); return(ListClientEntities); } #region Exceptions With Log catch (DbUpdateConcurrencyException e) { Log.Error(Resource_Infrastructure_Repository.ConcurrencyError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.ConcurrencyError, e); } catch (DbUpdateException e) { Log.Error(Resource_Infrastructure_Repository.DbUpdateError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.DbUpdateError, e); } catch (DbEntityValidationException e) { Log.Error(Resource_Infrastructure_Repository.DbEntityValidationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.DbEntityValidationError, e); } catch (NotSupportedException e) { Log.Error(Resource_Infrastructure_Repository.NotSuportedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.NotSuportedError, e); } catch (ObjectDisposedException e) { Log.Error(Resource_Infrastructure_Repository.ObjectDisposedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.ObjectDisposedError, e); } catch (InvalidOperationException e) { Log.Error(Resource_Infrastructure_Repository.InvalidOperationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); throw new VuelingException(Resource_Infrastructure_Repository.InvalidOperationError, e); #endregion } } }
public void DeleteAllRowsOfPolicyTable(VuelingEntities db) { db.Database.ExecuteSqlCommand(Resource_Infrastructure_Repository.QueryToDeleteAllRowsInPolicyTable); }
public void DeleteAllTablesInOrder(VuelingEntities db) { using (var dbTransaction = db.Database.BeginTransaction()) { try { DeleteAllRowsOfPolicyTable(db); DeleteAllRowsOfClientTable(db); db.SaveChanges(); dbTransaction.Commit(); } #region Exceptions With Log catch (DbUpdateConcurrencyException e) { Log.Error(Resource_Infrastructure_Repository.ConcurrencyError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.ConcurrencyError, e); } catch (DbUpdateException e) { Log.Error(Resource_Infrastructure_Repository.DbUpdateError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.DbUpdateError, e); } catch (DbEntityValidationException e) { Log.Error(Resource_Infrastructure_Repository.DbEntityValidationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.DbEntityValidationError, e); } catch (NotSupportedException e) { Log.Error(Resource_Infrastructure_Repository.NotSuportedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.NotSuportedError, e); } catch (ObjectDisposedException e) { Log.Error(Resource_Infrastructure_Repository.ObjectDisposedError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.ObjectDisposedError, e); } catch (InvalidOperationException e) { Log.Error(Resource_Infrastructure_Repository.InvalidOperationError + e.Message + Resource_Infrastructure_Repository.ErrorLogSeparation + e.Data + Resource_Infrastructure_Repository.ErrorLogSeparation + e.StackTrace); dbTransaction.Rollback(); throw new VuelingException(Resource_Infrastructure_Repository.InvalidOperationError, e); #endregion } } }
public ClienteRepository( VuelingEntities vuelingEntities) { this.db = vuelingEntities; }