123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using LeaRun.Application.Entity.BaseManage;
- using LeaRun.Application.IService.BaseManage;
- using LeaRun.Data;
- using LeaRun.Data.Repository;
- using LeaRun.Util.Extension;
- using System;
- using System.Collections.Generic;
- using System.Data.Common;
- using System.Linq;
- using System.Text;
- using LeaRun.Application.IService.AuthorizeManage;
- using LeaRun.Application.Service.AuthorizeManage;
- namespace LeaRun.Application.Service.BaseManage
- {
- /// <summary>
- /// 版 本 6.1
- /// Copyright (c) 2013-2016 上海力软信息技术有限公司
- /// 创建人:佘赐雄
- /// 日 期:2015.11.02 14:27
- /// 描 述:部门管理
- /// </summary>
- public class DepartmentService : RepositoryFactory<DepartmentEntity>, IDepartmentService
- {
- private IAuthorizeService<DepartmentEntity> iauthorizeservice = new AuthorizeService<DepartmentEntity>();
- #region 获取数据
- /// <summary>
- /// 部门列表
- /// </summary>
- /// <returns></returns>
- public IEnumerable<DepartmentEntity> GetList()
- {
- return this.BaseRepository().IQueryable().OrderByDescending(t => t.CreateDate).ToList();
- }
- /// <summary>
- /// 部门实体
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns></returns>
- public DepartmentEntity GetEntity(string keyValue)
- {
- return this.BaseRepository().FindEntity(keyValue);
- }
- #endregion
- #region 验证数据
- /// <summary>
- /// 部门编号不能重复
- /// </summary>
- /// <param name="enCode">编号</param>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public bool ExistEnCode(string enCode, string keyValue)
- {
- var expression = LinqExtensions.True<DepartmentEntity>();
- expression = expression.And(t => t.EnCode == enCode);
- if (!string.IsNullOrEmpty(keyValue))
- {
- expression = expression.And(t => t.DepartmentId != keyValue);
- }
- return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
- }
- /// <summary>
- /// 部门名称不能重复
- /// </summary>
- /// <param name="fullName">名称</param>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public bool ExistFullName(string fullName, string keyValue)
- {
- var expression = LinqExtensions.True<DepartmentEntity>();
- expression = expression.And(t => t.FullName == fullName);
- if (!string.IsNullOrEmpty(keyValue))
- {
- expression = expression.And(t => t.DepartmentId != keyValue);
- }
- return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
- }
- #endregion
- #region 提交数据
- /// <summary>
- /// 删除部门
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void RemoveForm(string keyValue)
- {
- int count = this.BaseRepository().IQueryable(t => t.ParentId == keyValue).Count();
- if (count > 0)
- {
- throw new Exception("当前所选数据有子节点数据!");
- }
- this.BaseRepository().Delete(keyValue);
- }
- /// <summary>
- /// 保存部门表单(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="departmentEntity">机构实体</param>
- /// <returns></returns>
- public void SaveForm(string keyValue, DepartmentEntity departmentEntity)
- {
- if (!string.IsNullOrEmpty(keyValue))
- {
- departmentEntity.Modify(keyValue);
- this.BaseRepository().Update(departmentEntity);
- }
- else
- {
- departmentEntity.Create();
- this.BaseRepository().Insert(departmentEntity);
- }
- }
- #endregion
- }
- }
|