public void ClearDb() { using (var context = new CryptoCognizantContext(options)) { // clear the db context.Coin.RemoveRange(context.Coin); context.SaveChanges(); }; }
public void SetupDb() { using (var context = new CryptoCognizantContext(options)) { // populate the db context.Coin.Add(coins[0]); context.Coin.Add(coins[1]); context.SaveChanges(); } }
public CoinDTO Patch(int id, [FromBody] JsonPatchDocument <CoinDTO> coinPatch) { //get original coin object from the database Coin originCoin = coinRepository.GetCoinByID(id); //use automapper to map that to DTO object CoinDTO coinDTO = _mapper.Map <CoinDTO>(originCoin); //apply the patch to that DTO coinPatch.ApplyTo(coinDTO); //use automapper to map the DTO back ontop of the database object _mapper.Map(coinDTO, originCoin); //update coin in the database _context.Update(originCoin); _context.SaveChanges(); return(coinDTO); }
public void Save() { context.SaveChanges(); }