Пример #1
0
        public async Task <ActionResult> BuyCurrency(string code, CurrencyPurchaseDTO purchaseDTO)
        {
            code = code.ToUpper().Trim();

            if (!_curreciesService.IsCurrencyAbaible(code))
            {
                return(NotFound($@"The currency ""{code}"" is not available at this moment."));
            }

            ResponseHelper <CurrencyPurchase> response = await _curreciesService.BuyCurrencyAsync(_mapper.Map <CurrencyPurchase>(purchaseDTO));

            if (!response.Success)
            {
                foreach (var error in response.Errors)
                {
                    ModelState.AddModelError("Messages", error);
                }

                return(BadRequest(ModelState));
            }

            CurrencyPurchaseDTO dto = _mapper.Map <CurrencyPurchaseDTO>(response.Entity);

            return(CreatedAtAction(nameof(GetPurchase), new { id = dto.Id }, dto));
        }