using Edu.Model.Entity.System;
using Edu.Model.ViewModel.System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Edu.Repository.System
{
    /// <summary>
    /// 角色菜单权限表仓储层
    /// </summary>
    public class RB_Role_PermissionRepository : BaseRepository<RB_Role_Permission>
    {
        /// <summary>
        /// 获取角色菜单权限列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Role_Permission_ViewModel> GetRolePermissionListRepository(RB_Role_Permission_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT *
FROM RB_Role_Permission
WHERE 1=1 
");
            if (query != null)
            {
                if (query.ID > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Role_Permission_ViewModel.ID), query.ID);
                }
                if (query.Role_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Role_Permission_ViewModel.Role_Id), query.Role_Id);
                }
                if (query.Menu_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Role_Permission_ViewModel.Menu_Id), query.Menu_Id);
                }
            }
            return Get<RB_Role_Permission_ViewModel>(builder.ToString()).ToList();
        }
    }
}