using System;
using System.Collections.Generic;
using System.Text;
using System.Common;
using System.IRepositories;
using System.Model;
using System.Threading.Tasks;
using SqlSugar;

namespace System.Repositories
{
    public class Sys_CallDutyNumberRepository : BaseRepository<T_Sys_CallDutyNumber>, ISys_CallDutyNumberRepository
    {

        public async Task<PageData<V_CallDutyNumber>> GetListViewByPage(List<IConditionalModel> conModels, MyPageModel pagemodel, string orderby)
        {
            var userlist = await Db.SqlQueryable<V_CallDutyNumber>("select * from T_Sys_CallDutyNumber").Where(conModels).OrderBy(orderby).ToPageListAsync(pagemodel.PageIndex, pagemodel.PageSize, pagemodel.PageCount);

            var seatlist = await Db.Queryable<T_Sys_SeatGroup>().With(SqlWith.NoLock).Where(c => c.F_State == (int)EnumDelState.Enabled).ToListAsync();

            var list = new List<V_CallDutyNumber>();
            foreach (var item in userlist)
            {
                var newmodel = item;
                
                var seatmodel = seatlist.Find(a => a.F_ZXZID == item.F_Groupid);
                if (seatmodel != null)
                    newmodel.F_Group = seatmodel.F_ZXZName;

                list.Add(newmodel);
            }
            PageData<V_CallDutyNumber> pd = new PageData<V_CallDutyNumber>();
            pd.Rows = list;
            pd.Totals = pagemodel.PageCount;
            return pd;
        }
    }
}
