using Lottomat.Data.Repository; using Lottomat.Util; using Lottomat.Util.WebControl; using Lottomat.Util.Extension; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Common; using Lottomat.Application.Code; using Lottomat.Data; using Lottomat.Application.Entity.BaseManage; using Lottomat.Application.IService.BaseManage; using Lottomat.Application.Service.AuthorizeManage; using Lottomat.Application.IService.AuthorizeManage; using Newtonsoft.Json.Linq; namespace Lottomat.Application.Service.BaseManage { /// /// 版 本 /// Copyright (c) 2016-2017 /// 创建人:赵轶 /// 日 期:2015.11.4 14:31 /// 描 述:角色管理 /// public class RoleService : RepositoryFactory, IRoleService { private IAuthorizeService iauthorizeservice = new AuthorizeService(); #region 获取数据 /// /// 角色列表 /// /// public IEnumerable GetList() { var expression = LinqExtensions.True(); expression = expression.And(t => t.Category == 1).And(t => t.EnabledMark == (int)EnabledMarkEnum.Enabled).And(t => t.DeleteMark == (int)DeleteMarkEnum.NotDelete); return this.BaseRepository().IQueryable(expression).OrderByDescending(t => t.CreateDate).ToList(); } /// /// 角色列表 /// /// 分页 /// 查询参数 /// public IEnumerable GetPageList(Pagination pagination, string queryJson) { var expression = LinqExtensions.True(); JObject queryParam = queryJson.ToJObject(); if (queryParam != null) { //查询条件 if (!queryParam["condition"].IsEmpty() && !queryParam["keyword"].IsEmpty()) { string condition = queryParam["condition"].ToString(); string keyword = queryParam["keyword"].ToString(); switch (condition) { case "EnCode": //角色编号 expression = expression.And(t => t.EnCode.Contains(keyword)); break; case "FullName": //角色名称 expression = expression.And(t => t.FullName.Contains(keyword)); break; default: break; } } } expression = expression.And(t => t.Category == 1); return this.BaseRepository().FindList(expression, pagination); } /// /// 角色列表all /// /// public IEnumerable GetAllList() { var strSql = new StringBuilder(); strSql.Append(@"SELECT r.RoleId , o.FullName AS OrganizeId , r.Category , r.EnCode , r.FullName , r.SortCode , r.EnabledMark , r.Description , r.CreateDate FROM Base_Role r LEFT JOIN Base_Organize o ON o.OrganizeId = r.OrganizeId WHERE o.FullName is not null and r.Category = 1 and r.EnabledMark =1 ORDER BY o.FullName, r.SortCode"); return this.BaseRepository().FindList(strSql.ToString()); } /// /// 角色实体 /// /// 主键值 /// public RoleEntity GetEntity(string keyValue) { return this.BaseRepository().FindEntity(keyValue); } #endregion #region 验证数据 /// /// 角色编号不能重复 /// /// 编号 /// 主键 /// public bool ExistEnCode(string enCode, string keyValue) { var expression = LinqExtensions.True(); expression = expression.And(t => t.EnCode == enCode).And(t => t.Category == 1); if (!string.IsNullOrEmpty(keyValue)) { expression = expression.And(t => t.RoleId != keyValue); } return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false; } /// /// 角色名称不能重复 /// /// 名称 /// 主键 /// public bool ExistFullName(string fullName, string keyValue) { var expression = LinqExtensions.True(); expression = expression.And(t => t.FullName == fullName).And(t => t.Category == 1); if (!string.IsNullOrEmpty(keyValue)) { expression = expression.And(t => t.RoleId != keyValue); } return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false; } #endregion #region 提交数据 /// /// 删除角色 /// /// 主键 public void RemoveForm(string keyValue) { this.BaseRepository().Delete(keyValue); } /// /// 保存角色表单(新增、修改) /// /// 主键值 /// 角色实体 /// public void SaveForm(string keyValue, RoleEntity roleEntity) { if (!string.IsNullOrEmpty(keyValue)) { roleEntity.Modify(keyValue); this.BaseRepository().Update(roleEntity); } else { roleEntity.Create(); roleEntity.Category = 1; this.BaseRepository().Insert(roleEntity); } } #endregion } }