public async Task Handle(StockInitializedEvent notification, CancellationToken cancellationToken) { StockAction stockAction = notification.StockAction; StockSnapshot stockSnapshot = StockSnapshot.Create(stockAction.ProductId, stockAction.Count, stockAction.Id, stockAction.CreatedOn, _snapshotUniqueChecker, cancellationToken); IStockSnapshotRepository snapshotRepository = _stockDbContext.StockSnapshotRepository; await snapshotRepository.AddAsync(stockSnapshot, cancellationToken); }
/// <summary> /// Stock action /// </summary> /// <param name="adapterPosition">Adapter position.</param> /// <param name="action">Action.</param> void OnStockAction(int adapterPosition, StockAction action) { _stockItem = _driverStock[adapterPosition]; _stockItemId = _stockItem.Id; _adapterPosition = adapterPosition; EditStockItem(_stockItem); }
public async Task <bool> Handle(AddToStockCommand request, CancellationToken cancellationToken) { var stockActionModel = StockAction.Create(request.ProductId, StockActionTypes.AddToStock, request.Count, request.CorrelationId, _stockActionUniqueChecker, cancellationToken); IStockActionRepository stockActionRepository = _stockDbContext.StockActionRepository; await stockActionRepository.AddAsync(stockActionModel, cancellationToken); return(true); }
public async Task <Guid> Handle(InitializeStockCommand request, CancellationToken cancellationToken) { StockAction stockAction = StockAction.Create(request.ProductId, StockActionTypes.InitializeStock, request.AvailableStock, request.CorrelationId, _stockActionUniqueChecker, cancellationToken); IStockActionRepository stockActionRepository = _stockDbContext.StockActionRepository; await stockActionRepository.AddAsync(stockAction, cancellationToken); return(stockAction.Id); }
public async Task Handle(StockIncreasedEvent notification, CancellationToken cancellationToken) { StockAction stockAction = notification.StockAction; IStockSnapshotRepository stockSnapshotRepository = _stockDbContext.StockSnapshotRepository; StockSnapshot stockSnapshot = await stockSnapshotRepository.GetByProductIdAsync(stockAction.ProductId, cancellationToken); stockSnapshot.IncreaseStock(stockAction.Count, stockAction.Id, stockAction.CreatedOn); }
public async Task <bool> Handle(RollbackDecreaseFromStockCommand request, CancellationToken cancellationToken) { IStockActionRepository stockActionRepository = _stockDbContext.StockActionRepository; StockAction stockAction = await stockActionRepository.GetByCorrelationIdAsync(request.CorrelationId, cancellationToken); AddToStockCommand addToStockCommand = new AddToStockCommand(stockAction.ProductId, stockAction.Count, $"{stockAction.CorrelationId}-rollback"); await _domainMessageBroker.SendAsync(addToStockCommand, cancellationToken); return(true); }
public PendingAction(string symbol, int quantity, Guid historyID, StockAction actionType, string accountID, string connectionID) { this.Symbol = symbol; this.Quantity = quantity; this.HistoryID = historyID; this.ActionType = actionType; this.AccountID = accountID; this.ConnectionID = connectionID; this.CyclesToWait = RandomNumber.GetRandomInt(5); }
public async Task <bool> Handle(ResetStockCommand request, CancellationToken cancellationToken) { IStockSnapshotRepository stockSnapshotRepository = _stockDbContext.StockSnapshotRepository; StockSnapshot stockSnapshot = await stockSnapshotRepository.GetByProductIdAsync(request.ProductId, cancellationToken); var stockActionModel = StockAction.Create(request.ProductId, StockActionTypes.RemoveFromStock, stockSnapshot.AvailableStock, request.CorrelationId, _stockActionUniqueChecker, cancellationToken); IStockActionRepository stockActionRepository = _stockDbContext.StockActionRepository; await stockActionRepository.AddAsync(stockActionModel, cancellationToken); return(true); }
public static StockActionCreatedEvent Create(StockAction stockAction) { StockActionCreatedEvent stockActionCreatedEvent = stockAction.StockActionType switch { StockActionTypes.InitializeStock => new StockInitializedEvent(stockAction), StockActionTypes.AddToStock => new StockIncreasedEvent(stockAction), StockActionTypes.RemoveFromStock => new StockDecreasedEvent(stockAction), StockActionTypes.ResetStock => new StockDecreasedEvent(stockAction), _ => throw new ArgumentOutOfRangeException() }; return(stockActionCreatedEvent); } }
public void Create(IPortfolio portfolio, StockAction stockAction) { var stock = dbContext.Stocks.Where(s => s.Symbol == portfolio.StockSymbol).FirstOrDefault(); bool purchased = stockAction == StockAction.Bought ? true : false; ITransactionLog entity = new Model.TransactionLog { Price = stock.LastPrice.Value, StockId = stock.ID, StockSymbol = stock.Symbol, Purchased = purchased, Quantity = portfolio.Quantity, TransactionDate = DateTime.Now }; dbContext.TransactionLogs.Add(Mapper.Map<ITransactionLog, Data.TransactionLog>(entity)); dbContext.SaveChanges(); }
public void Create(IPortfolio portfolio, StockAction stockAction) { var stock = dbContext.Stocks.Where(s => s.Symbol == portfolio.StockSymbol).FirstOrDefault(); bool purchased = stockAction == StockAction.Bought ? true : false; ITransactionLog entity = new Model.TransactionLog { Price = stock.LastPrice.Value, StockId = stock.ID, StockSymbol = stock.Symbol, Purchased = purchased, Quantity = portfolio.Quantity, TransactionDate = DateTime.Now }; dbContext.TransactionLogs.Add(Mapper.Map <ITransactionLog, Data.TransactionLog>(entity)); dbContext.SaveChanges(); }
public StockInitializedEvent(StockAction stockAction) : base(stockAction) { }
private void PublishStockActionRequest(StockAction action, string symbol, int quantity) { var stockActionRequestedEvent = this.eventAggregator.GetEvent<StockActionRequestedEvent>(); stockActionRequestedEvent.Publish(new StockActionRequestedEventArgs(Guid.NewGuid(), action, symbol, quantity)); }
public StockDecreasedEvent(StockAction stockAction) : base(stockAction) { }
public void RequestStockAction(Guid requestID, string connectionID, string accountID, StockAction action, string symbol, int quantity) { this.pendingStockActions.RegisterPendingAction(symbol, quantity, requestID, action, accountID, connectionID); }
private void OnStockActionExecuted(Guid requestID, StockActionStatus status, StockAction action, string symbol, int quantity, decimal? price, decimal? amount) { var stockActionExecutedEvent = this.eventAggregator.GetEvent<StockActionExecutedEvent>(); stockActionExecutedEvent.Publish(new StockActionExecutedEventArgs(requestID, status, action, symbol, quantity, price, amount)); }
public void RegisterPendingAction(string symbol, int quantity, Guid historyID, StockAction actionType, string accountID, string connectionID) { lock (this.pendingActions) { this.pendingActions.Add(new PendingAction(symbol, quantity, historyID, actionType, accountID, connectionID)); } }
public async Task RequestStockAction(Guid requestID, StockAction action, string symbol, int quantity) { await this.Clients.Caller.StockActionExecuted(requestID, StockActionStatus.Submitted, action, symbol, quantity, null, null); string accountID = this.Clients.Caller.AccountID; this.stockBroker.RequestStockAction(requestID, this.Context.ConnectionId, accountID, action, symbol, quantity); }
private void UpdateStockActions(string ticker, decimal stockPrice, StockAction stockAction) { Stocks.Add(new Stock { Name = ticker, Value = stockPrice, PurchasedDate = DateTime.Now, Action = stockAction }); }
public async Task AddAsync(StockAction stockAction, CancellationToken cancellationToken) { await _appDbContext.AddAsync(stockAction, cancellationToken); }
protected StockActionCreatedEvent(StockAction stockAction) { StockAction = stockAction; }