Exemplo n.º 1
0
 public static GiftCardProjectionId From(GiftCardId id)
 {
     return(new GiftCardProjectionId()
     {
         Value = id.Value
     });
 }
Exemplo n.º 2
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.º 3
0
        public async Task <IActionResult> CancelGiftCard([FromRoute] Guid id)
        {
            var aggregateId = GiftCardId.With(id);

            var command = new CancelCommand(aggregateId);

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

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

            return(BadRequest(executionResult.ToString()));
        }
Exemplo n.º 4
0
        public Hydrator(IActorRef aggregateManager, GiftCardId id)
        {
            _aggregateManager = aggregateManager;
            _rng = new Random();
            var time = TimeSpan.FromSeconds(_rng.NextDouble() * 60);

            _credits     = _rng.Next(50, 500);
            _redemptions = _rng.Next(2, 6);
            _id          = id;
            _aggregateManager.Tell(new IssueCommand(_id, _credits));

            Context.GetLogger().Info($"[{_id}] started with [{_credits}]credits, sending Use in [{time.Seconds}s]");
            Context.System.Scheduler.ScheduleTellOnce(time, Self, new Use(), Self);
            Receive <Use>(Handle);
        }