public void Handle(RemoveEmployeeFromLocationCommand command)
        {
            Location location = _session.Get <Location>(command.Id);

            location.RemoveEmployee(command.EmployeeID);
            _session.Commit();
        }
        public IHttpActionResult AssignEmployee(
            AssignEmployeeToLocationRequest request)
        {
            var employee = _employeeRepo.GetByID(request.EmployeeID);

            if (employee.LocationID != 0)
            {
                var oldLocationAggregateID
                    = _locationRepo.GetByID(employee.LocationID).AggregateID;

                RemoveEmployeeFromLocationCommand removeCommand
                    = new RemoveEmployeeFromLocationCommand(
                          oldLocationAggregateID,
                          request.LocationID, employee.EmployeeID);
                _commandSender.Send(removeCommand);
            }

            var locationAggregateID
                = _locationRepo.GetByID(request.LocationID).AggregateID;
            var assignCommand
                = new AssignEmployeeToLocationCommand(
                      locationAggregateID,
                      request.LocationID,
                      request.EmployeeID);

            _commandSender.Send(assignCommand);

            return(Ok());
        }
        public async Task Handle(RemoveEmployeeFromLocationCommand command)
        {
            Location location = await _session.Get <Location>(command.Id);

            location.RemoveEmployee(command.EmployeeId);
            await _session.Commit();
        }
Exemple #4
0
        public async Task Handle(RemoveEmployeeFromLocationCommand message)
        {
            Location location = await _session.Get <Location>(message.Id);

            location.RemoveEmployee(message.EmployeeID);

            await _session.Commit();
        }
        public async Task <IActionResult> AssignEmployee(AssignEmployeeToLocationRequest request, CancellationToken ct = default)
        {
            var employee = await _queryProcessor.Query(new GetEmployeeById(request.EmployeeId), ct);

            if (Guid.Empty != employee.LocationId)
            {
                var removeCommand = new RemoveEmployeeFromLocationCommand(employee.LocationId, request.LocationId, employee.Id);
                await _commandSender.Send(removeCommand, ct);
            }

            var assignCommand = new AssignEmployeeToLocationCommand(request.LocationId, request.EmployeeId);
            await _commandSender.Send(assignCommand, ct);

            return(Ok());
        }
        public async Task <IActionResult> AssignEmployee(AssignEmployeeToLocationRequest request)
        {
            var employee = await _employeeRepository.GetByID(request.EmployeeID);

            if (employee.LocationID != 0)
            {
                var oldLocationAggregateID = (await _locationRepository.GetByID(employee.LocationID)).AggregateID;

                RemoveEmployeeFromLocationCommand command = new RemoveEmployeeFromLocationCommand(oldLocationAggregateID, request.LocationID, employee.EmployeeID);
                await _commandSender.Send(command);
            }

            var locationAggregateID = (await _locationRepository.GetByID(request.LocationID)).AggregateID;
            var assignCommand       = new AssignEmployeeToLocationCommand(locationAggregateID, request.LocationID, request.EmployeeID);
            await _commandSender.Send(assignCommand);

            return(Ok());
        }