public EmployeeDeleteResponse Handle(EmployeeDeleteCommand command) { var employee = _employeeContext.Employees.FirstOrDefault(e => e.Id == command.Id); if (employee == null) { return(ResponseFactory.Failure <EmployeeDeleteResponse>(EmployeeError.EmployeeDoesntExist)); } _employeeContext.Employees.Remove(employee); return(ResponseFactory.Success <EmployeeDeleteResponse>()); }
public EmployeeCreateResponse Handle(EmployeeCreateCommand command) { // TODO validation if (!ValidateEmailDoesntExist(command.Email)) { return(ResponseFactory.Failure <EmployeeCreateResponse>(EmployeeError.EmailAlreadyExists)); } var employee = new Employee // TODO mapper { FirstName = command.FirstName, LastName = command.LastName, Email = command.Email }; _employeeContext.Employees.Add(employee); return(ResponseFactory.Success <EmployeeCreateResponse>()); }
public EmployeeUpdateResponse Handle(EmployeeUpdateCommand command) { // TODO validation var employee = _employeeContext.Employees.FirstOrDefault(e => e.Id == command.Id); if (employee == null) { return(ResponseFactory.Failure <EmployeeUpdateResponse>(EmployeeError.EmployeeDoesntExist)); } if (!ValidateEmailDoesntExist(command.Email)) { return(ResponseFactory.Failure <EmployeeUpdateResponse>(EmployeeError.EmailAlreadyExists)); } employee.FirstName = command.FirstName; employee.LastName = command.LastName; employee.Email = command.Email; return(ResponseFactory.Success <EmployeeUpdateResponse>()); }