Ejemplo n.º 1
0
 public CryptoCurrency MapAddCryptoCurrencyCommandToCryptoCurrency(AddCryptoCurrencyCommand command)
 {
     return(new CryptoCurrency()
     {
         Code = command.Code
     });
 }
        public async Task <ValidateableResponse <CryptoCurrencyRawResponse> > Handle(AddCryptoCurrencyCommand request, CancellationToken cancellationToken)
        {
            var newCryptoCurrency = _mapper.MapAddCryptoCurrencyCommandToCryptoCurrency(request);
            var result            = await _cryptoCurrencyRepository.AddNewCryptoCurrencyAsync(newCryptoCurrency, cancellationToken);

            return(new ValidateableResponse <CryptoCurrencyRawResponse>(_mapper.MapCryptoCurrencyToCryptoCurrencyRawResponse(result)));
        }
Ejemplo n.º 3
0
        public void MapAddCryptoCurrencyCommandToCryptoCurrency_ShouldreturnCorrectData(string code)
        {
            //arrange
            var request = new CryptoCurrencyAddRequest()
            {
                Code = code
            };
            var command = new AddCryptoCurrencyCommand(request);

            //act
            var result = _mapper.MapAddCryptoCurrencyCommandToCryptoCurrency(command);

            //assert
            result.Code.Should().Be(code);
            result.Id.Should().Be(default);
        public async Task <IActionResult> Create(CryptoCurrencyAddRequest request)
        {
            try
            {
                var command = new AddCryptoCurrencyCommand(request);
                var res     = await _mediator.Send(command);

                if (res.HasError)
                {
                    ViewBag.Errors = res.Errors;
                    return(View());
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }