﻿using ClasscialChinese.Dal.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using pengzhenhua.common;

namespace ClasscialChinese.Dal.Dao
{
    public class ArticleDao : BaseDao<ClassiscalChineseEntities, Article>
    {
        //public List<Book> Find(BookCondition c, PagingArgument page)
        //{
        //    IQueryable<Book> q = database.Book.OrderBy(t => t.Id);
        //    return getPocoList(q, page, null);
        //}

        //one article with detial infor
        public Article detail(int id)
        {
            return get(id, loadDetail);
        }

        //load detail infor
        public void loadDetail(Article a)
        {
            if (a == null)
                return;
            if (a.BookPart != null)
            {
                if (a.BookPart.Book.Author != null)
                    a.authorName = a.BookPart.Book.Author.Name;
            }
            else
            {
                if (a.Book.Author != null)
                    a.authorName = a.Book.Author.Name;
            }
            a.exts = a.ArticleExt.ToList();
        }
    }
}
