Ejemplo n.º 1
0
        public async System.Threading.Tasks.Task DeleteEmployee(DeleteEmployeeInput input)
        {
            try
            {
                foreach (var id in input.EmployeeIds)
                {
                    var employee = _employeeRepository
                                   .GetAll()
                                   .Include(e => e.Tasks)
                                   .FirstOrDefault(e => e.Id == id);//

                    if (employee == null)
                    {
                        throw new UserFriendlyException("Employee not found.");
                    }

                    employee.Tasks.ForEach(t => t.AssignedEmployeeId = null);

                    await _employeeRepository.DeleteAsync(employee);
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
Ejemplo n.º 2
0
        public async System.Threading.Tasks.Task DeleteEmployee(DeleteEmployeeInput input)
        {
            try
            {
                var employee = await _employeeRepository.FirstOrDefaultAsync(x => x.Id == input.Id);

                await _employeeRepository.DeleteAsync(employee);
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
Ejemplo n.º 3
0
        public async System.Threading.Tasks.Task DeleteEmployee(DeleteEmployeeInput input)
        {
            try
            {
                var employees = await _employeeRepository
                                .GetAll()
                                .Include(x => x.EmployeeTasks)
                                .Where(e => input.EmployeeIds.Contains(e.Id))
                                .ToListAsync();



                //await _employeeRepository.DeleteAsync(e => input.EmployeeIds.Contains(e.))

                //employees.RemoveRange(0, employees.Count());
                foreach (var employee in employees)
                {
                    await _employeeRepository.DeleteAsync(employee);
                }



                //foreach (var id in input.EmployeeIds)
                //{
                //    var employee = _employeeRepository
                //        .GetAll()
                //        .Include(e => e.Tasks)
                //        .FirstOrDefault(e => e.Id == id);//

                //    if (employee == null)
                //    {
                //        throw new UserFriendlyException("Employee not found.");
                //    }

                //    employee.Tasks.ForEach(t => t.AssignedEmployeeId = null);

                //    await _employeeRepository.DeleteAsync(employee);
                //}
            }
            catch (Exception e)
            {
                throw (e);
            }
        }