public IEnumerable <BookData> GetAllBooks() { using (IRepositoryTransactionContext ctx = ObjectContainer.Instance.GetService <IRepositoryTransactionContext>()) { IRepository <Book> bookRepository = ctx.GetRepository <Book>(); List <BookData> bds = new List <BookData>(); var books = bookRepository.GetAll(); foreach (var book in books) { BookData bd = new BookData(); bd.FromEntity(book); bds.Add(bd); } return(bds); } }
public BookData GetBookDetail(Guid id) { try { using (IRepositoryTransactionContext ctx = ObjectContainer.Instance.GetService <IRepositoryTransactionContext>()) { IRepository <Book> bookRepository = ctx.GetRepository <Book>(); Book bk = bookRepository.GetByKey(id); BookData bd = new BookData(); bd.FromEntity(bk); return(bd); } } catch { throw; } }