Exemplo n.º 1
0
        public async Task <IActionResult> RedeemGiftCard([FromRoute] Guid id, [FromBody] GiftCardInputModel model)
        {
            var aggregateId = GiftCardId.With(id);

            var command = new RedeemCommand(aggregateId, model.Credits);

            var executionResult = await _aggregateManager.Ask <ExecutionResult>(command);

            if (executionResult.IsSuccess)
            {
                return(Accepted(new { Id = aggregateId.GetGuid() }));
            }

            return(BadRequest(executionResult.ToString()));
        }
Exemplo n.º 2
0
        public bool Execute(RedeemCommand command)
        {
            if (!IsNew && State.Credits >= command.Credits)
            {
                Emit(new RedeemedEvent(command.Credits));
                Sender.Tell(new SuccessExecutionResult(), Self);
            }
            else
            {
                Log.Error($"{command.GetType().PrettyPrint()} has failed ");
                Sender.Tell(new FailedExecutionResult(new List <string> {
                    "aggregate is already created"
                }), Self);
            }

            return(true);
        }