public IActionResult UpdateSetting(int id, [FromBody] TradingBookSetting setting) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _service.Update(id, setting); return(Ok()); }
public IActionResult Post([FromBody] TradingBookSetting theSetting) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TradingBookEntity created = _service.Create(_accountId, theSetting); return(Ok(new { id = created.Id })); }
public void Update(int tradingBookId, TradingBookSetting setting) { TradingBookEntity tradingBook = _context.TradingBooks .Where(tb => tb.Id == tradingBookId) .FirstOrDefault(); if (tradingBook == null) { throw new TradingBookNotFoundException($"trading book with id {tradingBookId} was not found!"); } tradingBook.Setting = setting; _context.SaveChanges(); }
public void ShouldCreateNew() { AccountEntity account = GenerateAccount(); using (var context = new AmfMoneyContext(_options)) { context.Accounts.Add(account); context.SaveChanges(); } using (var tradingBookService = new TradingBookService(new AmfMoneyContext(_options))) { TradingBookSetting setting = GenerateSetting(); TradingBookEntity actual = tradingBookService.Create(account.Id, setting); Assert.True(actual.Id > 0); Assert.Equal(setting, actual.Setting); Assert.NotEqual(default, actual.CreatedAt);
public TradingBookEntity Create(int accountId, TradingBookSetting setting) { AccountEntity account = _context.Accounts.Find(accountId); if (account == null) { throw new AccountNotFoundException($"Account with id: {accountId} does not exists"); } TradingBookEntity toBeAdded = new TradingBookEntity() { Setting = setting, CreatedAt = DateTime.UtcNow, AccountEntityId = account.Id }; _context.TradingBooks.Add(toBeAdded); _context.SaveChanges(); return(toBeAdded); }