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());
        }
示例#2
0
        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());
        }