Exemplo n.º 1
0
        public async Task VisitAsync(SingleTransactionEvent e)
        {
            var result = CreateBase(e);

            result["Type"]            = "SingleTransaction";
            result["TransactionType"] = e.TransactionType.ToString();
            result["ItemCount"]       = e.ItemCount;
            result["ItemName"]        = e.ItemName;
            await SaveResultAsync(result);
        }
Exemplo n.º 2
0
        public async Task VisitAsync(SingleTransactionEvent e)
        {
            var storage = source.FirstOrDefault(entity => entity.Id == e.StorageId);

            if (storage == null)
            {
                return;
            }

            var item        = new Item(e.ItemName, e.ItemCount);
            var transaction = new SingleTransaction(e.StorageId, e.TransactionType, item);

            if (storage.IsTransactionPossible(transaction))
            {
                storage.ApplyTransaction(transaction);
            }

            await Task.CompletedTask;
        }
Exemplo n.º 3
0
        protected override bool TryParse(string json, out Event result)
        {
            result = null;
            var obj = JObject.Parse(json);

            if (obj.Value <string>("Type") != "SingleTransaction")
            {
                return(false);
            }

            var id              = obj.Value <string>("_id");
            var storageId       = obj.Value <string>("StorageId");
            var itemName        = obj.Value <string>("ItemName");
            var itemCount       = obj.Value <int>("ItemCount");
            var transactionType = obj.Value <string>("TransactionType");

            result = new SingleTransactionEvent(id,
                                                Enum.Parse <SingleTransactionType>(transactionType),
                                                storageId,
                                                itemName,
                                                itemCount);
            return(true);
        }