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

namespace Edu.Module.Web
{
    /// <summary>
    /// 网站新闻处理类
    /// </summary>
    public class WebNewsModule
    {
        /// <summary>
        /// 网站新闻管理仓储层对象
        /// </summary>
        private readonly RB_Web_NewsRepository web_NewsRepository = new RB_Web_NewsRepository();

        /// <summary>
        /// 网站新闻类型仓储层对象
        /// </summary>
        private readonly RB_Web_NewsTypeRepository web_NewsTypeRepository = new RB_Web_NewsTypeRepository();

        /// <summary>
        /// 品牌月刊管理仓储层对象
        /// </summary>
        private readonly RB_Web_MonthlyRepository web_MonthlyRepository = new RB_Web_MonthlyRepository();

        /// <summary>
        /// 品牌漫画管理仓储层对象
        /// </summary>
        private readonly RB_Web_CartoonRepository web_CartoonRepository = new RB_Web_CartoonRepository();

        #region 新闻管理
        /// <summary>
        /// 获取网站新闻分页列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页显示调试</param>
        /// <param name="rowsCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Web_News_ViewModel> GetWebNewsPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Web_News_ViewModel query)
        {
            return web_NewsRepository.GetWebNewsPageRepository(pageIndex, pageSize, out rowsCount, query);
        }

        /// <summary>
        /// 获取网站新闻列表
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Web_News_ViewModel> GetWebNewsListModule(RB_Web_News_ViewModel query)
        {
            return web_NewsRepository.GetWebNewsListRepository(query);
        }

        /// <summary>
        /// 新增修改新闻
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetWebNewsModule(RB_Web_News_ViewModel model)
        {
            bool flag;
            if (model.Id > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Web_News_ViewModel.Title),model.Title },
                    {nameof(RB_Web_News_ViewModel.Img),model.Img },
                    {nameof(RB_Web_News_ViewModel.Content),model.Content },
                    {nameof(RB_Web_News_ViewModel.TypeId),model.TypeId },
                };
                flag = web_NewsRepository.Update(fileds, new WhereHelper(nameof(RB_Web_News_ViewModel.Id), model.Id));
            }
            else
            {
                var newId = web_NewsRepository.Insert(model);
                model.Id = newId;
                flag = newId > 0;
            }
            return flag;
        }

        /// <summary>
        /// 根据编号获取网站新闻详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public RB_Web_News_ViewModel GetWebNewsModule(object Id)
        {
            return web_NewsRepository.GetEntity<RB_Web_News_ViewModel>(Id);
        }

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

        #endregion

        #region 新闻类型管理


        /// <summary>
        /// 获取网站新闻类型分页列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页显示调试</param>
        /// <param name="rowsCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Web_NewsType_ViewModel> GetWebNewsTypePageModule(int pageIndex, int pageSize, out long rowsCount, RB_Web_NewsType_ViewModel query)
        {
            return web_NewsTypeRepository.GetWebNewsTypePageRepository(pageIndex, pageSize, out rowsCount, query);
        }

        /// <summary>
        /// 获取网站新闻类型列表
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Web_NewsType_ViewModel> GetWebNewsTypeListModule(RB_Web_NewsType_ViewModel query)
        {
            return web_NewsTypeRepository.GetWebNewsTypeListRepository(query);
        }

        /// <summary>
        /// 新增修改新闻类型
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetWebNewsTypeModule(RB_Web_NewsType_ViewModel model)
        {
            bool flag;
            if (model.Id > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Web_NewsType_ViewModel.TypeName),model.TypeName },
                    {nameof(RB_Web_NewsType_ViewModel.Image),model.Image },
                };
                flag = web_NewsTypeRepository.Update(fileds, new WhereHelper(nameof(RB_Web_NewsType_ViewModel.Id), model.Id));
            }
            else
            {
                var newId = web_NewsTypeRepository.Insert(model);
                model.Id = newId;
                flag = newId > 0;
            }
            return flag;
        }

        /// <summary>
        /// 根据编号获取网站新闻类型详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public RB_Web_NewsType_ViewModel GetWebNewsTypeModule(object Id)
        {
            return web_NewsTypeRepository.GetEntity<RB_Web_NewsType_ViewModel>(Id);
        }

        /// <summary>
        /// 修改网站新闻类型状态
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="Status">0-正常,1-删除</param>
        /// <returns></returns>
        public bool RemoveWebNewsTypeStatusModule(int Id, int Status)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
            {
                {nameof(RB_Web_NewsType_ViewModel.Status),Status },
            };
            var flag = web_NewsTypeRepository.Update(fileds, new WhereHelper(nameof(RB_Web_NewsType_ViewModel.Id), Id));
            return flag;
        }
        #endregion

        #region 品牌动漫管理

        /// <summary>
        /// 获取品牌卡通分页列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页显示调试</param>
        /// <param name="rowsCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Web_Cartoon_ViewModel> GetWebCartoonPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Web_Cartoon_ViewModel query)
        {
            return web_CartoonRepository.GetWebCartoonPageRepository(pageIndex, pageSize, out rowsCount, query);
        }

        /// <summary>
        /// 新增修改品牌动漫
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetWebCartoonModule(RB_Web_Cartoon_ViewModel model)
        {
            bool flag;
            if (model.Id > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Web_Cartoon_ViewModel.Name),model.Name },
                    {nameof(RB_Web_Cartoon_ViewModel.LinkUrl),model.LinkUrl },
                };
                flag = web_CartoonRepository.Update(fileds, new WhereHelper(nameof(RB_Web_NewsType_ViewModel.Id), model.Id));
            }
            else
            {
                var newId = web_CartoonRepository.Insert(model);
                model.Id = newId;
                flag = newId > 0;
            }
            return flag;
        }

        /// <summary>
        /// 根据编号获取品牌卡通详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public RB_Web_Cartoon_ViewModel GetWebCartoonModule(object Id)
        {
            return web_CartoonRepository.GetEntity<RB_Web_Cartoon_ViewModel>(Id);
        }

        /// <summary>
        /// 修改品牌卡通状态
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="Status">0-正常,1-删除</param>
        /// <returns></returns>
        public bool RemoveWebCartoonStatusModule(int Id, int Status)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
            {
                {nameof(RB_Web_Cartoon_ViewModel.Status),Status },
            };
            var flag = web_CartoonRepository.Update(fileds, new WhereHelper(nameof(RB_Web_Cartoon_ViewModel.Id), Id));
            return flag;
        }

        #endregion

        #region 品牌月刊管理
        /// <summary>
        /// 获取品牌月刊分页列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页显示调试</param>
        /// <param name="rowsCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Web_Monthly_ViewModel> GetWebMonthlyPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Web_Monthly_ViewModel query)
        {
            return web_MonthlyRepository.GetWebMonthlyPageRepository(pageIndex, pageSize, out rowsCount, query);
        }

        /// <summary>
        /// 新增修改品牌月刊
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetWebMonthlyModule(RB_Web_Monthly_ViewModel model)
        {
            bool flag;
            if (model.Id > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Web_Monthly_ViewModel.Name),model.Name },
                    {nameof(RB_Web_Monthly_ViewModel.LinkUrl),model.LinkUrl },
                    {nameof(RB_Web_Monthly_ViewModel.CoverImg),model.CoverImg },
                };
                flag = web_MonthlyRepository.Update(fileds, new WhereHelper(nameof(RB_Web_Monthly_ViewModel.Id), model.Id));
            }
            else
            {
                var newId = web_MonthlyRepository.Insert(model);
                model.Id = newId;
                flag = newId > 0;
            }
            return flag;
        }

        /// <summary>
        /// 根据编号获取品牌月刊详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public RB_Web_Monthly_ViewModel GetWebMonthlyModule(object Id)
        {
            return web_MonthlyRepository.GetEntity<RB_Web_Monthly_ViewModel>(Id);
        }

        /// <summary>
        /// 修改品牌月刊状态
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="Status">0-正常,1-删除</param>
        /// <returns></returns>
        public bool RemoveWebMonthlyStatusModule(int Id, int Status)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
            {
                {nameof(RB_Web_Monthly_ViewModel.Status),Status },
            };
            var flag = web_MonthlyRepository.Update(fileds, new WhereHelper(nameof(RB_Web_Monthly_ViewModel.Id), Id));
            return flag;
        }

        #endregion
    }
}
