public async Task <ExchangeDetailsModel> CreateAsync(ExchangeCreateModel exchange)
        {
            if (await _repository.HasExchangeWithShortcut(exchange.Shortcut))
            {
                throw new ArgumentException();
            }

            var exchangeEntity = _mapper.Map <Exchange>(exchange);
            var createdEntity  = await _repository.CreateAsync(exchangeEntity);

            return(_mapper.Map <ExchangeDetailsModel>(createdEntity));
        }
Example #2
0
        public async Task <ActionResult <ExchangeDetailsModel> > CreateExchangeAsync([FromBody] ExchangeCreateModel exchange)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var createdExchange = await _service.CreateAsync(exchange);

                return(new ObjectResult(createdExchange)
                {
                    StatusCode = 201
                });
            }
            catch (ArgumentException)
            {
                return(BadRequest());
            }
        }