public async Task <ActionResult> AddCurrency(Currency currency)
        {
            if (_dbContext.Currencies.Select(c => c.Code).Contains(currency.Code))
            {
                return(new ObjectResult($"Given currency already contains {currency}"));
            }

            await _dbContext.Currencies.AddAsync(currency);

            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
Пример #2
0
        /// <summary>
        /// Writes the request to the database as intended.
        /// </summary>
        private async Task SaveContextOperation(HttpContext httpContext)
        {
            try
            {
                var requestItem = await GetRequestItem(httpContext.Request);

                var responseItem = await GetResponseItem(httpContext.Response);

                await _exchangeRateApiContext.RequestResponseItems.AddAsync(new RequestResponseItem()
                {
                    Request = requestItem, Response = responseItem
                });

                await _exchangeRateApiContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error with saving request-response");
                throw;
            }
        }