3using Microsoft.EntityFrameworkCore;
54 where c.CurrencyName == name
55 select c).FirstAsync();
57 catch (InvalidOperationException e)
74 throw new InvalidOperationException($
"Unique name violation.");
77 await
_db.SaveChangesAsync();
93 throw new InvalidOperationException($
"Unique name violation.");
96 await
_db.SaveChangesAsync();
109 if (currency ==
null)
throw new NullReferenceException($
"Currency with id {id} doesn't exist.");
DbSet< Currency > Currencies
CurrencyService class inserts and updates Currency in the Database
async Task< Currency > UpdateCurrency(Currency currency)
Updates changes on a Currency in the database
CurrencyService(DataContext db)
async Task DeleteCurrency(int id)
Deletes a currency with id in the database
async Task< List< Currency > > GetAllCurrencies()
Read all Currencies from database
async Task< Currency > GetCurrencyById(int id)
Read one Currency with id from database
async Task< Currency > GetCurrencyByName(string name)
Read one Currency with name from database
async Task< Currency > AddCurrency(Currency currency)
Adds a Currency to the database