コード例 #1
0
 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);
     }
 }
コード例 #2
0
 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;
     }
 }