public T Add(T entity) { _dbContext.Set <T>().Add(entity); _dbContext.SaveChanges(); return(entity); }
public void Create(CustomerAuditor customerAuditorToAdd) { Stopwatch timespan = Stopwatch.StartNew(); try { db.CustomerAuditors.Add(customerAuditorToAdd); db.SaveChanges(); //Seteamos el Rol SetRole(customerAuditorToAdd.UserId); timespan.Stop(); log.TraceApi("SQL Database", "CustomerAuditorRespository.Create", timespan.Elapsed, "customerAuditorToAdd={0}", customerAuditorToAdd); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { //Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); log.Error(e, "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { //Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); log.Error(e, "- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } catch (Exception e) { log.Error(e, "Error in CustomerAuditorRespository.CreateAsync(customerAuditorToAdd={0})", customerAuditorToAdd); throw; } }
public async Task DeleteAsync(int businessTypeTemplateID) { BusinessTypeTemplate businessTypeTemplate = null; Stopwatch timespan = Stopwatch.StartNew(); try { DeleteDocumentationBusinessTypesTemplate(businessTypeTemplateID); businessTypeTemplate = await db.BusinessTypeTemplates.FindAsync(businessTypeTemplateID); db.BusinessTypeTemplates.Remove(businessTypeTemplate); db.SaveChanges(); timespan.Stop(); log.TraceApi("SQL Database", "BusinessTypeTemplateRepository.DeleteAsync", timespan.Elapsed, "businessTypeTemplateID={0}", businessTypeTemplateID); } catch (Exception e) { log.Error(e, "Error in BusinessTypeTemplateRepository.DeleteAsync(businessTypeTemplateID={0})", businessTypeTemplateID); throw; } }
private void DeleteDocumentationBusinessTypesTemplate(int documentationTemplateID) { Stopwatch timespan = Stopwatch.StartNew(); try { var docBusinessTypeTemplates = db.DocumentationBusinessTypeTemplates .Where(t => t.DocumentationTemplateID == documentationTemplateID).ToList(); foreach (DocumentationBusinessTypeTemplate item in docBusinessTypeTemplates) { db.DocumentationBusinessTypeTemplates.Remove(item); } db.SaveChanges(); timespan.Stop(); log.TraceApi("SQL Database", "DocumentationTemplateRepository.DeleteDocumentationBusinessTypesTemplate", timespan.Elapsed, "documentationTemplateID={0}", documentationTemplateID); } catch (Exception e) { log.Error(e, "Error in DocumentationTemplateRepository.DeleteDocumentationBusinessTypesTemplate()"); throw; } }
public async Task DeleteAsync(int contractorID) { Contractor contractor = null; Contract contract = null; Stopwatch timespan = Stopwatch.StartNew(); SiccoAppConfiguration.SuspendExecutionStrategy = true; DbContextTransaction tran = db.Database.BeginTransaction(); try { contractor = await db.Contractors.FindAsync(contractorID); contract = await db.Contracts.FindAsync(GetContractID(contractorID)); if (contract != null) { db.Contracts.Remove(contract); } db.Contractors.Remove(contractor); //contract = await db.Contracts.FindAsync(GetContractID(contractorID)); //if (contract != null) // db.Contracts.Remove(contract); db.SaveChanges(); tran.Commit(); timespan.Stop(); log.TraceApi("SQL Database", "ContractorRepository.DeleteAsync", timespan.Elapsed, "contractorID={0}", contractorID); } catch (Exception e) { tran.Rollback(); log.Error(e, "Error in ContractorRepository.DeleteAsync(contractorID={0})", contractorID); throw; } SiccoAppConfiguration.SuspendExecutionStrategy = false; }
public async Task DeleteAsync(int documentationBusinessTypeID) { DocumentationBusinessType docuBusinessType = null; Stopwatch timespan = Stopwatch.StartNew(); try { docuBusinessType = await db.DocumentationBusinessTypes.FindAsync(documentationBusinessTypeID); db.DocumentationBusinessTypes.Remove(docuBusinessType); db.SaveChanges(); timespan.Stop(); log.TraceApi("SQL Database", "DocumentationBusinessTypeRepository.DeleteAsync", timespan.Elapsed, "documentationBusinessTypeID={0}", documentationBusinessTypeID); } catch (Exception e) { log.Error(e, "Error in DocumentationBusinessTypeRepository.DeleteAsync(documentationBusinessTypeID={0})", documentationBusinessTypeID); throw; } }
public async Task DeleteAsync(int contractID) { Contract contract = null; Stopwatch timespan = Stopwatch.StartNew(); try { contract = await db.Contracts.FindAsync(contractID); db.Contracts.Remove(contract); db.SaveChanges(); timespan.Stop(); log.TraceApi("SQL Database", "contractsRepository.DeleteAsync", timespan.Elapsed, "contractID={0}", contractID); } catch (Exception e) { log.Error(e, "Error in contractsRepository.DeleteAsync(contractID={0})", contractID); throw; } }
public async Task DeleteAsync(int requirementID) { Requirement requirement = null; Stopwatch timespan = Stopwatch.StartNew(); try { requirement = await db.Requirements.FindAsync(requirementID); db.Requirements.Remove(requirement); db.SaveChanges(); timespan.Stop(); log.TraceApi("SQL Database", "RequirementRepository.DeleteAsync", timespan.Elapsed, "requirementID={0}", requirementID); } catch (Exception e) { log.Error(e, "Error in RequirementRepository.DeleteAsync(requirementID={0})", requirementID); throw; } }
public async Task DeleteAsync(int vehicleID) { Vehicle vehicle = null; VehicleContract vehicleContract = null; Stopwatch timespan = Stopwatch.StartNew(); SiccoAppConfiguration.SuspendExecutionStrategy = true; DbContextTransaction tran = db.Database.BeginTransaction(); try { vehicle = await db.Vehicles.FindAsync(vehicleID); db.Vehicles.Remove(vehicle); vehicleContract = await db.VehiclesContracts.FindAsync(GetVehicleContractID(vehicleID)); if (vehicleContract != null) { db.VehiclesContracts.Remove(vehicleContract); } db.SaveChanges(); tran.Commit(); timespan.Stop(); log.TraceApi("SQL Database", "VehicleRepository.DeleteAsync", timespan.Elapsed, "vehicleID={0}", vehicleID); } catch (Exception e) { tran.Rollback(); log.Error(e, "Error in VehicleRepository.DeleteAsync(vehicleID={0})", vehicleID); throw; } SiccoAppConfiguration.SuspendExecutionStrategy = false; }