public Task<Book> UpdateAsync(Book item) { Book bookToUpdate = _books.Find(b => b.BookId == item.BookId); int ix = _books.IndexOf(bookToUpdate); _books[ix] = item; return Task.FromResult(_books[ix]); }
private void LoadBook(object sender, BookInfoEvent bookInfo) { if (bookInfo.BookId == 0) { Book = new Book(); } else { Book = _booksService.GetBook(bookInfo.BookId); } }
public async Task<Book> AddOrUpdateBookAsync(Book book) { Book updated = null; if (book.BookId == 0) { updated = await _booksRepository.AddAsync(book); _books.Add(updated); } else { updated = await _booksRepository.UpdateAsync(book); Book old = _books.Where(b => b.BookId == updated.BookId).Single(); int ix = _books.IndexOf(old); _books.RemoveAt(ix); _books.Insert(ix, updated); } return updated; }
private async void OnSaveBook() { Book = await _booksService.AddOrUpdateBookAsync(Book); }
public Task<Book> AddAsync(Book item) { item.BookId = _books.Select(b => b.BookId).Max() + 1; _books.Add(item); return Task.FromResult(item); }