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