using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using SlnMesnac.Repository.service.ScanLog;

using System;
using System.Collections.Generic;
using System.Text;

namespace SlnMesnac.Repository.service.LogImpl
{
    public class BaseLogServiceImpl : BaseServiceImpl<BaseLog>, IBaseLogService
    {
        public BaseLogServiceImpl(Repository<BaseLog> rep) : base(rep)
        {
        }

        public void CreatTable()
        {
            _rep.Context.CodeFirst.InitTables<BaseLog>();
        }

        public Page<BaseLog> QueryPage(int pageIndex, int pageSize)
        {
            int totalCount = 0;
            var list = _rep.Context.Queryable<BaseLog>().OrderByDescending(x => x.CreateTime)
                .ToPageList(pageIndex, pageSize, ref totalCount);
            Page<BaseLog> page = new Page<BaseLog>();
            page.Data = list;
            page.PageIndex = pageIndex;
            page.PageSize = pageSize;
            page.TotalCount = totalCount;
            page.TotalPage = (int)Math.Ceiling(totalCount / (double)pageSize);
            return page;
        }
    }
}
