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
{
///
/// 版 本 6.1
/// Copyright (c) 2013-2016 上海力软信息技术有限公司
/// 创建人:佘赐雄
/// 日 期:2015.11.02 14:27
/// 描 述:部门管理
///
public class DepartmentService : RepositoryFactory, IDepartmentService
{
private IAuthorizeService iauthorizeservice = new AuthorizeService();
#region 获取数据
///
/// 部门列表
///
///
public IEnumerable GetList()
{
return this.BaseRepository().IQueryable().OrderByDescending(t => t.CreateDate).ToList();
}
///
/// 部门实体
///
/// 主键值
///
public DepartmentEntity 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);
if (!string.IsNullOrEmpty(keyValue))
{
expression = expression.And(t => t.DepartmentId != 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);
if (!string.IsNullOrEmpty(keyValue))
{
expression = expression.And(t => t.DepartmentId != keyValue);
}
return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
}
#endregion
#region 提交数据
///
/// 删除部门
///
/// 主键
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);
}
///
/// 保存部门表单(新增、修改)
///
/// 主键值
/// 机构实体
///
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
}
}