Example #1
0
        private void HandleInternal(RemoveEmployeeFromEmployerCommand command)
        {
            using (var context = new EmploymentDataDbContext())
            {
                var employer = FindWithId(context, command.EmployerId);

                employer.FireAnEmployee(command.EmployeeId);

                context.SaveChanges();
            }
        }
Example #2
0
        private void HandleInternal(HireEmployeeByEmployerCommand command)
        {
            using (var context = new EmploymentDataDbContext())
            {
                var nextKey = context.Employees.Count() + 1; // :)

                var employee = new Employee(nextKey, command.EmployeeSalary, command.EmployeeName);

                var employer = FindWithId(context, command.EmployerId);

                context.Employees.Add(employee);
                employer.Employees.Add(employee);

                context.SaveChanges();
            }
        }
Example #3
0
        public GetAllEmployersDataQueryResponse Handle(GetAllEmployersDataQuery query)
        {
            using (var context = new EmploymentDataDbContext())
            {
                var employers = context.Employers.Include(e => e.Employees).ToList();

                var employersSummaryList = new GetAllEmployersDataQueryResponse();
                employersSummaryList.Data =
                    employers.Select(
                        e =>
                        new EmployerSummaryData()
                {
                    EmployerId   = e.Id,
                    EmployerName = e.Name,
                    TotalSalary  = e.Employees.Sum(ee => ee.Salary)
                }).ToList();

                return(employersSummaryList);
            }
        }
Example #4
0
 private Employer FindWithId(EmploymentDataDbContext context, int id)
 {
     return(context.Employers.Where(e => e.Id == id).Include(e => e.Employees).Single());
 }