public void ShouldReturnErrorWhenHadAmountAndCurrenciesIsInvalid() { var command = new CreateCurrencyCommand(); command.Validate(); Assert.AreEqual(false, command.Valid); }
private CreateCurrencyCommand CreateCommand() { var command = new CreateCurrencyCommand { Name = "Wat Dynero", Code = "WAT", }; return(command); }
public void ShouldReturnErrorWhenNotExistisCurrency() { var handle = new CurrencyHandler(new FakeCurrencyRepository()); var command = new CreateCurrencyCommand(); command.Amount = 10; command.CurrencyOrigin = "AAA"; command.CurrencyDestination = "BBB"; handle.Handle(command); Assert.AreEqual(false, handle.Valid); }
public async Task <IActionResult> Create([FromForm] CreateCurrencyCommand command) { if (ModelState.IsValid) { Currency taskReturn = await Mediator.Send(command); return(Ok(new CurrenciesResponse(nameof(Currency), taskReturn, taskReturn.statusCode, _baseLocalizer, _localizer))); } else { return(BadRequest(ModelState)); } }
public async Task <CommandResult <Currency> > Handle(CreateCurrencyCommand request, CancellationToken cancellationToken) { var currency = await currencyRepository.FindOneAsync(p => p.IsoCode.Equals(request.CurrencyIso.ToLower())); if (currency != null) { return(CommandResult <Currency> .Fail(currency, "IsoCode already exists")); } currency = new Currency(request.Name, request.CurrencyIso); await currencyRepository.Add(currency); PublishEvents(currency); return(CommandResult <Currency> .Success(currency)); }
public async Task <IActionResult> Post([FromBody] CreateCurrencyCommand command) { if (command == null) { return(BadRequest()); } ////VAlidation //if (command. == string.Empty || command.LastName == string.Empty) //{ // ModelState.AddModelError("Name/FirstName", "The name or first name shouldn't be empty"); //} if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createdCurrency = await _mediator.Send(command); return(Created("currency", createdCurrency)); }
public IActionResult CreateCurrency(CreateCurrencyCommand command) { try { _commandDispatcher.Dispatch(command); } catch (CodeAlreadyExistsException ex) { return(this.ConflictError(ex)); } var id = command.GetResult(); var query = new GetCurrencyQuery { Id = id, }; _queryRunner.Run(query); var queryResult = query.GetResult(); var url = this.Url.Action("GetCurrency", "GetCurrency", new { id }); return(this.Created(url, queryResult)); }
public async Task <ActionResult> CreateCurrency([FromBody] CreateCurrencyCommand request, CancellationToken cancellationToken) { var response = await Mediator.Send(request, cancellationToken); return(Ok(response)); }
public void CreateDimension <TResult>(TResult obj) where TResult : class { var resultType = typeof(TResult); if (resultType == typeof(Customer)) { var command = new CreateCustomerCommand { Customer = obj as Customer }; _processXml.Process(command.ToXml()); } if (resultType == typeof(Supplier)) { var command = new CreateSupplierCommand { Supplier = obj as Supplier }; _processXml.Process(command.ToXml()); } if (resultType == typeof(BalanceSheet)) { var command = new CreateGeneralLedgerCommand { GeneralLedger = obj as BalanceSheet }; _processXml.Process(command.ToXml()); } if (resultType == typeof(ProfitLoss)) { var command = new CreateGeneralLedgerCommand { GeneralLedger = obj as ProfitLoss }; _processXml.Process(command.ToXml()); } if (resultType == typeof(CostCenter)) { var command = new CreateCostCenterCommand { CostCenter = obj as CostCenter }; _processXml.Process(command.ToXml()); } if (resultType == typeof(Article)) { var command = new CreateArticleCommand { Article = obj as Article }; _processXml.Process(command.ToXml()); } if (resultType == typeof(Data.SalesInvoice.SalesInvoice)) { var command = new CreateSalesInvoiceCommand { SalesInvoice = obj as Data.SalesInvoice.SalesInvoice }; _processXml.Process(command.ToXml()); } if (resultType == typeof(Vat)) { var command = new CreateVatCommand { Vat = obj as Vat }; _processXml.Process(command.ToXml()); } if (resultType == typeof(Currency)) { var command = new CreateCurrencyCommand { Currency = obj as Currency }; _processXml.Process(command.ToXml()); } if (resultType == typeof(DimensionType)) { var command = new UpdateDimensionTypeCommand { DimensionType = obj as DimensionType }; _processXml.Process(command.ToXml()); } }
public async Task <IActionResult> Create([FromBody] CreateCurrencyCommand command) { _result = (CommandResult)await _handler.Handle(command); return(Ok(_result)); }
public async Task <ActionResult <Result <int> > > Post(CreateCurrencyCommand command) { return(Ok(await _mediator.Send(command))); }
public async Task <IActionResult> Create([FromBody] CreateCurrencyCommand command) { return(await Execute(command)); }