public SingleTransactionCommand( IStorageStore storageStore, IEventStore eventStore, ITransactionValidationService transactionValidationService, SingleTransactionType type, SingleTransactionData data) { this.storageStore = storageStore; this.eventStore = eventStore; this.transactionValidationService = transactionValidationService; this.transaction = CreateTransaction(type, data); this.transactionEvent = CreateEvent(type, data); }
public async Task <IActionResult> DecreaseItemAsync(SingleTransactionData transaction) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var command = commandFactory.GetSingleTransactionCommand(SingleTransactionType.Decrease, transaction); try { await command.ExecuteAsync(); } catch (NotAuthorizedException) { return(Forbid()); } catch (ValidationException) { return(BadRequest()); } return(Ok()); }
private Event CreateEvent(SingleTransactionType type, SingleTransactionData data) { return(new SingleTransactionEvent(Guid.NewGuid().ToBase64String(), type, data.StorageId, data.ItemName, data.ItemCount.Value)); }
private SingleTransaction CreateTransaction(SingleTransactionType type, SingleTransactionData data) { var item = new Item(data.ItemName, data.ItemCount.Value); return(new SingleTransaction(data.StorageId, type, item)); }
public ICommand GetSingleTransactionCommand(SingleTransactionType type, SingleTransactionData data) { return(new SingleTransactionCommand(storageStore, eventStore, transactionValidationService, type, data)); }