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 void Handle(AssignEmployeeToLocationCommand command)
        {
            Location location = _session.Get <Location>(command.Id);

            location.AddEmployee(command.EmployeeID);
            _session.Commit();
        }
        public async Task Handle(AssignEmployeeToLocationCommand command)
        {
            Location location = await _session.Get <Location>(command.Id);

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

            location.AddEmployee(message.EmployeeID);

            await _session.Commit();
        }
Example #5
0
        public async Task <IActionResult> Create(CreateEmployeeRequest request, CancellationToken ct = default)
        {
            var command = await _mapper.Map <CreateEmployeeCommand>(request);

            await _commandSender.Send(command, ct);

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

            return(Ok());
        }
Example #6
0
        public IHttpActionResult Create(CreateEmployeeRequest request)
        {
            var command = _mapper.Map<CreateEmployeeCommand>(request);
            _commandSender.Send(command);

            var locationAggregateID = _locationRepo.GetByID(request.LocationID).AggregateID;

            var assignCommand = new AssignEmployeeToLocationCommand(locationAggregateID, request.LocationID, request.EmployeeID);
            _commandSender.Send(assignCommand);
            return Ok();
        }
        public async Task <IActionResult> Create(CreateEmployeeRequest request)
        {
            var command = _mapper.Map <CreateEmployeeCommand>(request);
            await _commandSender.Send(command);

            if (request.LocationID > 0)
            {
                var locationAggregateID = (await _locationRepository.GetByID(request.LocationID)).AggregateID;

                var assignCommand = new AssignEmployeeToLocationCommand(locationAggregateID, request.LocationID, request.EmployeeID);
                await _commandSender.Send(assignCommand);
            }
            return(Ok());
        }
Example #8
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());
        }