public async Task UpdateAsync(Contractor contractorToSave)
        {
            Stopwatch timespan = Stopwatch.StartNew();

            try
            {
                db.Entry(contractorToSave).State = EntityState.Modified;
                await db.SaveChangesAsync();

                timespan.Stop();
                log.TraceApi("SQL Database", "ContractorRepository.UpdateAsync", timespan.Elapsed, "contractorToSave={0}", contractorToSave);
            }
            catch (Exception e)
            {
                log.Error(e, "Error in ContractorRepository.UpdateAsync(contractorToSave={0})", contractorToSave);
                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 <Contractor> FindContractorsByIDAsync(int contractorID)
        {
            Contractor contractor = null;
            Stopwatch  timespan   = Stopwatch.StartNew();

            try
            {
                contractor = await db.Contractors.FindAsync(contractorID);

                timespan.Stop();
                log.TraceApi("SQL Database", "ContractorRepository.FindContractorsByIDAsync", timespan.Elapsed, "contractorID={0}", contractorID);
            }
            catch (Exception e)
            {
                log.Error(e, "Error in ContractorRepository.FindContractorsByIDAsync(contractorID={0})", contractorID);
                throw;
            }

            return(contractor);
        }
        //https://msdn.microsoft.com/en-us/data/dn307226
        public async Task CreateAsync(Contractor contractorToAdd)
        {
            Stopwatch timespan = Stopwatch.StartNew();

            //Se suspende momentaneamente la estrategia de Azure (reintentos), porque la misma no
            //soporta manejo de transacciones por parte del usuario
            SiccoAppConfiguration.SuspendExecutionStrategy = true;

            DbContextTransaction tran = db.Database.BeginTransaction();

            try
            {
                db.Contractors.Add(contractorToAdd);
                //await db.SaveChangesAsync();

                var contract = CreateContract(contractorToAdd);
                db.Contracts.Add(contract);

                await db.SaveChangesAsync();

                tran.Commit();

                await GenerateContractorRequirements(contractorToAdd.ContractorID, contract.ContractID);

                timespan.Stop();
                log.TraceApi("SQL Database", "ContractorRepository.CreateAsync", timespan.Elapsed, "customerToAdd={0}", contractorToAdd);
            }
            catch (Exception e)
            {
                tran.Rollback();
                log.Error(e, "Error in ContractorRepository.CreateAsync(contractorToAdd={0})", contractorToAdd);
                throw;
            }

            SiccoAppConfiguration.SuspendExecutionStrategy = false;
        }