private Result <Exception, int> ProcessHeadRotate(HeadRotateCommand command, RobotAgreggate robot) { Result <Exception, int> rotateCallback; switch (command.HeadRotate.ToLower()) { case "left": rotateCallback = robot.RotateHeadToTheLeft(); break; case "right": rotateCallback = robot.RotateHeadToTheRight(); break; default: return(new BussinessException(ErrorCodes.BadRequest, "Comando inválido.")); } // Publish Domain Events _mediator.PublishDomainEvents(robot.RaisedEvents()); if (rotateCallback.IsSuccess) { return(PersistRobotState(robot, rotateCallback.Success)); } return(rotateCallback.Failure); }
public async Task <IActionResult> PutHeadRotate(string id, [FromBody] HeadRotateCommand command) { command.RobotId = id; var result = await _mediator.Send(command); return(HandleCommand(result)); }
public Task <Result <Exception, int> > Handle(HeadRotateCommand command, CancellationToken cancellationToken) { var findRobotCallback = _repository.Get(command.RobotId); if (!findRobotCallback.IsSuccess) { return(Task.FromResult(findRobotCallback.Failure.Run <int>())); } return(Task.FromResult(ProcessHeadRotate(command, findRobotCallback.Success))); }