using AutoMapper;
using Model.ModelDto.SysDto;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using WMS.Entity.SysEntity;
using WMS.IBLL.ISysServer;
using WMS.IDAL.ISysInterface;
namespace WMS.BLL.SysServer
{
///
/// 部门服务实践
///
public class DepartmentServer : IDepartmentServer
{
///
/// 依赖注入
///
private readonly IDepartmentRepository _department;
readonly IMapper _mapper;
///
/// 构造函数
///
/// 部门仓储接口
/// automapper
public DepartmentServer(IDepartmentRepository department, IMapper mapper)
{
_department = department;//部门
_mapper = mapper;//automapper
}
///
/// 获取部门信息列表
///
/// 部门名称
/// 部门号
///
public List GetDepartmentList(string DepartmentName, string DepartmentNo)
{
List departmentlist = _department.GetDepartmentList(DepartmentName, DepartmentNo);
return departmentlist;
}
///
/// 根据id获取部门信息
///
/// 部门id
///
public SysDepartment GetDepartmentById(int id)
{
SysDepartment department = _department.GetDepartmentById(id);
return department;
}
///
/// 根据部门号获取部门信息
///
///
public int GetDepartmentByNo(string DepartmentNo)
{
List department = _department.GetDepartmentByNo(DepartmentNo);
return department.Count;
}
///
/// 新增部门信息
///
/// 部门dto
///
/// 捕获异常
public async Task AddDepartment(DepartmentDto departmentdto)
{
//捕获异常
try
{
//模型映射
SysDepartment department = _mapper.Map(departmentdto);
//判断部门号是否唯一
int count = GetDepartmentByNo(department.DepartmentNo);
int i = 0;
if (count > 0)
{
i = 3;
}
else if (count == 0)
{
i = await _department.AddDepartment(department);
}
return i;
}
catch (Exception ex)
{
//抛出异常
throw new Exception("新增部门异常", ex);
}
}
///
/// 删除部门信息
///
/// 部门实体模型
///
/// 捕获异常
public async Task DelDepartment(SysDepartment department)
{
//捕获异常
try
{
//删除
int i = await _department.DelDepartment(department);
return i;
}
catch (Exception ex)
{
//抛出异常
throw new Exception("删除部门异常", ex);
}
}
///
/// 编辑部门信息
///
/// 部门dto
///
/// 捕获异常
public async Task ExitDepartment(DepartmentDto departmentdto)
{
//捕获异常
try
{
//模型映射
SysDepartment department = _mapper.Map(departmentdto);
//编辑
int i = await _department.ExitDepartment(department);
return i;
}
catch (Exception ex)
{
//抛出异常
throw new Exception("编辑部门异常", ex);
}
}
}
}