예제 #1
0
 public static GiftCardProjectionId From(GiftCardId id)
 {
     return(new GiftCardProjectionId()
     {
         Value = id.Value
     });
 }
예제 #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()));
        }
예제 #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()));
        }
예제 #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);
        }