예제 #1
0
 public async Task<Book> CreateBook(Book book)
 {
     if (book == null) throw new PiggyBankDataException("Book object is missing");
     PiggyBankUtility.CheckMandatory(book);
     _dbContext.Books.Add(book);
     await _dbContext.SaveChangesAsync();
     return book;
 }
예제 #2
0
 public async Task<Account> CreateAccount(Book book, Account account)
 {
     if (book == null) throw new PiggyBankDataException("Book object is missing");
     if (account == null) throw new PiggyBankDataException("Account object is missing");
     account.Book = book;
     PiggyBankUtility.CheckMandatory(account);
     _dbContext.Accounts.Add(account);
     await _dbContext.SaveChangesAsync();
     return account;
 }
예제 #3
0
        public async Task<Book> UpdateBook(Book book)
        {
            if (book == null) throw new PiggyBankDataException("Book object is missing");

            Book bookToUpdate = await FindBook(book.Id);
            if (!bookToUpdate.IsValid) throw new PiggyBankDataNotFoundException("Book [" + book.Id + "] cannot be found");
            PiggyBankUtility.CheckMandatory(book);
            PiggyBankUtility.UpdateModel(bookToUpdate, book);
            await _dbContext.SaveChangesAsync();
            return bookToUpdate;
        }
예제 #4
0
        public async Task<Tag> CreateTag(Book book, Tag tag)
        {
            if (book == null) throw new PiggyBankDataException("Book object is missing");
            if (tag == null) throw new PiggyBankDataException("Tag object is missing");

            tag.Book = book;
            PiggyBankUtility.CheckMandatory(tag);
            _dbContext.Tags.Add(tag);
            await _dbContext.SaveChangesAsync();

            return tag;
        }
예제 #5
0
        public async Task<Transaction> CreateTransaction(Book book, Transaction transaction)
        {
            DateTime timeStamp = DateTime.Now;

            if (book == null) throw new PiggyBankDataException("Book object is missing");
            if (transaction == null) throw new PiggyBankDataException("Transaction object is missing");

            transaction.Book = book;
            AccountManager acc = new AccountManager(_dbContext);
            transaction.DebitAccount = await acc.FindAccount(transaction.DebitAccount.Id);
            transaction.CreditAccount = await acc.FindAccount(transaction.CreditAccount.Id);
            ValidateTransaction(transaction);
            transaction.TimeStamp = timeStamp;
            PiggyBankUtility.CheckMandatory(transaction);
            _dbContext.Transactions.Add(transaction);
            await _dbContext.SaveChangesAsync();

            return transaction;
        }
예제 #6
0
 public async Task<IEnumerable<Account>> ListAccounts(Book book)
 {
     return await ListAccounts(b => b.Book.Id == book.Id);
 }