using Edu.Model.ViewModel.Web;
using Edu.Repository.Web;
using System;
using System.Collections.Generic;
using System.Text;
using VT.FW.DB;

namespace Edu.Module.Web
{
    /// <summary>
    /// 网站导航处理类
    /// </summary>
    public class WebNavModule
    {
        /// <summary>
        /// 网站导航仓储层对象
        /// </summary>
        private readonly RB_Web_NavRepository web_NavRepository = new RB_Web_NavRepository();

        /// <summary>
        /// 获取网站导航分页列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页显示调试</param>
        /// <param name="rowsCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Web_Nav_ViewModel> GetWebNavPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Web_Nav_ViewModel query)
        {
            return web_NavRepository.GetWebNavPageRepository(pageIndex, pageSize, out rowsCount, query);
        }

        /// <summary>
        /// 获取网站导航列表
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Web_Nav_ViewModel> GetWebNavListModule(RB_Web_Nav_ViewModel query)
        {
            return web_NavRepository.GetWebNavListRepository(query);
        }

        /// <summary>
        /// 新增修改导航
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetWebNavModule(RB_Web_Nav_ViewModel model)
        {
            bool flag;
            if (model.Id > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Web_Nav_ViewModel.NavTitle),model.NavTitle },
                    {nameof(RB_Web_Nav_ViewModel.SubTitle),model.SubTitle },
                    {nameof(RB_Web_Nav_ViewModel.BgImg),model.BgImg },
                    {nameof(RB_Web_Nav_ViewModel.LinkUrl),model.LinkUrl },
                    {nameof(RB_Web_Nav_ViewModel.NavType),model.NavType },
                };
                flag = web_NavRepository.Update(fileds, new WhereHelper(nameof(RB_Web_Nav_ViewModel.Id), model.Id));
            }
            else
            {
                var newId = web_NavRepository.Insert(model);
                model.Id = newId;
                flag = newId > 0;
            }
            return flag;
        }

        /// <summary>
        /// 根据编号获取网站导航详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public RB_Web_Nav_ViewModel GetWebNavModule(object Id)
        {
            return web_NavRepository.GetEntity<RB_Web_Nav_ViewModel>(Id);
        }

        /// <summary>
        /// 修改网站导航状态
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="Status">0-正常,1-删除</param>
        /// <returns></returns>
        public bool RemoveWebNavStatusModule(int Id, int Status)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
            {
                {nameof(RB_Web_Nav_ViewModel.Status),Status },
            };
            var flag = web_NavRepository.Update(fileds, new WhereHelper(nameof(RB_Web_Nav_ViewModel.Id), Id));
            return flag;
        }
    }
}
