Exemplo n.º 1
0
        //public async Task CreateContractAsync(EmployeeContract contract)
        //{
        //    Stopwatch timespan = Stopwatch.StartNew();

        //    try
        //    {
        //        db.EmployeesContracts.Add(contract);

        //        await db.SaveChangesAsync();

        //        timespan.Stop();
        //        log.TraceApi("SQL Database", "EmployeeRepository.CreateContractAsync", timespan.Elapsed, "contract={0}", contract);

        //    }
        //    catch (Exception e)
        //    {

        //        log.Error(e, "Error in EmployeeRepository.CreateContractAsync(contract={0})", contract);
        //        throw;
        //    }
        //}

        public async Task CreateContractAsync(EmployeeContract employeeContract)
        {
            Stopwatch timespan = Stopwatch.StartNew();

            SiccoAppConfiguration.SuspendExecutionStrategy = true;

            DbContextTransaction tran = db.Database.BeginTransaction();

            try
            {
                db.EmployeesContracts.Add(employeeContract);

                await db.SaveChangesAsync();

                tran.Commit();

                var contract = db.Contracts.Where(c => c.ContractID == employeeContract.ContractID).SingleOrDefault <Contract>();

                await GenerateContractorEmployeeRequirements(contract.ContractorID, employeeContract.ContractID, employeeContract.EmployeeID);

                timespan.Stop();
                log.TraceApi("SQL Database", "EmployeeRepository.CreateContractAsync", timespan.Elapsed, "employeeContract={0}", employeeContract);
            }
            catch (Exception e)
            {
                tran.Rollback();
                log.Error(e, "Error in EmployeeRepository.CreateContractAsync(employeeContract={0})", employeeContract);
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <EmployeeContract> GetEmployeeContract(int employeeID, int contractID)
        {
            Stopwatch timespan = Stopwatch.StartNew();

            try
            {
                EmployeeContract employeeContract = db.EmployeesContracts.Where(c => c.EmployeeID == employeeID && c.ContractID == contractID).ToList().First();

                timespan.Stop();
                log.TraceApi("SQL Database", "EmployeeRepository.GetEmployeeContract", timespan.Elapsed, "employeeID={0}, contractID={1}", employeeID, contractID);

                return(await Task.Run(() => { return employeeContract; }));
            }
            catch (Exception e)
            {
                log.Error(e, "Error in EmployeeRepository.GetEmployeeContract(employeeID={0}, contractID={1})", employeeID, contractID);
                throw;
            }
        }
Exemplo n.º 3
0
        public async Task DeleteContract(int employeeID, int contractID)
        {
            Stopwatch timespan = Stopwatch.StartNew();

            try
            {
                EmployeeContract employeeContract = db.EmployeesContracts.Where(c => c.EmployeeID == employeeID && c.ContractID == contractID).ToList().First();

                db.EmployeesContracts.Remove(employeeContract);
                await db.SaveChangesAsync();

                timespan.Stop();
                log.TraceApi("SQL Database", "EmployeeRepository.DeleteContract", timespan.Elapsed, "employeeID={0}, contractID={1}", employeeID, contractID);
            }
            catch (Exception e)
            {
                log.Error(e, "Error in EmployeeRepository.DeleteContract(employeeID={0}, contractID={1})", employeeID, contractID);
                throw;
            }
        }
Exemplo n.º 4
0
        public async Task DeleteAsync(int employeeID)
        {
            Employee         employee         = null;
            EmployeeContract employeeContract = null;

            Stopwatch timespan = Stopwatch.StartNew();

            SiccoAppConfiguration.SuspendExecutionStrategy = true;

            DbContextTransaction tran = db.Database.BeginTransaction();

            try
            {
                employee = await db.Employees.FindAsync(employeeID);

                db.Employees.Remove(employee);

                employeeContract = await db.EmployeesContracts.FindAsync(GetEmployeeContractID(employeeID));

                if (employeeContract != null)
                {
                    db.EmployeesContracts.Remove(employeeContract);
                }

                db.SaveChanges();

                tran.Commit();

                timespan.Stop();
                log.TraceApi("SQL Database", "EmployeeRepository.DeleteAsync", timespan.Elapsed, "employeeID={0}", employeeID);
            }
            catch (Exception e)
            {
                tran.Rollback();
                log.Error(e, "Error in EmployeeRepository.DeleteAsync(employeeID={0})", employeeID);
                throw;
            }

            SiccoAppConfiguration.SuspendExecutionStrategy = false;
        }
Exemplo n.º 5
0
        private int?GetEmployeeContractID(int employeeID)
        {
            EmployeeContract employeeContract = db.EmployeesContracts.Where(c => c.EmployeeID == employeeID).ToList().FirstOrDefault();

            return(employeeContract?.EmployeeContractID);
        }