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

namespace System.Repositories
{
    public class Cus_VipInfoRepository : BaseRepository<T_Cus_VipInfo>, ICus_VipInfoRepository
    {
        public async Task<PageData<V_Cus_VipInfo>> GetListViewByPage(List<IConditionalModel> conModels, MyPageModel pagemodel, string orderby)
        {
            var list = await Db.SqlQueryable<V_Cus_VipInfo>("select * from T_Cus_VipInfo ").With(SqlWith.NoLock).Where(conModels).OrderBy(orderby).ToPageListAsync(pagemodel.PageIndex, pagemodel.PageSize, pagemodel.PageCount);
            var newlist = new List<V_Cus_VipInfo>();
            foreach (var item in list)
            {
                var newmodel = item;
                if (item.F_Birthday != null)
                    newmodel.Birthday = item.F_Birthday.Value.ToString("yyyy-MM-dd");

                newmodel.F_Contact = 0;

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

        public async Task<V_Cus_VipInfo> GetSingleV(Expression<Func<V_Cus_VipInfo, bool>> whereExpression)
        {
            var model= await Db.SqlQueryable<V_Cus_VipInfo>("select * from T_Cus_VipInfo ").With(SqlWith.NoLock).Where(whereExpression).SingleAsync();
            if(model.F_Birthday!=null)
                model.Birthday=model.F_Birthday.Value.ToString("yyyy-MM-dd");
            return model;
            //return CurrentDb.GetSingle(whereExpression);
        }
    }
    
}
