コード例 #1
0
ファイル: Program.cs プロジェクト: limin9988/Entropy
 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
ファイル: Program.cs プロジェクト: limin9988/Entropy
        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);
        }