using AutoMapper;
|
using DTO;
|
using IServices;
|
using Microsoft.EntityFrameworkCore;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using zhengcaioa.Models;
|
|
namespace Services
|
{
|
public class PltRoleDeptService: IPltRoleDeptService
|
{
|
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public PltRoleDeptService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
public ResultEntity save(PltRoleDeptDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
var PltRoleDept = _mapper.Map<PltRoleDept>(dto);
|
if (String.IsNullOrEmpty(PltRoleDept.Id))
|
{
|
PltRoleDept.Id = Guid.NewGuid().ToString();
|
|
|
_context.PltRoleDepts.Add(PltRoleDept);
|
}
|
else
|
{
|
var updatepltRole = _context.PltRoleDepts.Find(PltRoleDept.Id);
|
updatepltRole.RoleId = PltRoleDept.RoleId;
|
updatepltRole.DeptId = PltRoleDept.DeptId;
|
|
|
|
|
|
updatepltRole.RecStatus = PltRoleDept.RecStatus;
|
// updatepltRole.Creater = pltRole.Creater;
|
//updatepltRole.Createtime = pltRole.Createtime;
|
updatepltRole.Modifier = PltRoleDept.Modifier;
|
updatepltRole.Modifytime = PltRoleDept.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = PltRoleDept.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public PltRoleDeptDTO Get(string id)
|
{
|
var entity = _context.PltRoleDepts.Find(id);
|
|
if (entity.RecStatus != "A")
|
{
|
entity = new PltRoleDept();
|
}
|
var PltRoleDeptDTO = _mapper.Map<PltRoleDeptDTO>(entity);
|
return PltRoleDeptDTO;
|
}
|
|
public ResultDataEntity<PltRoleDeptDTO> SearchByPaging(PltRoleDeptDTOSearch searchEntity)
|
{
|
ResultDataEntity<PltRoleDeptDTO> data = new ResultDataEntity<PltRoleDeptDTO>();
|
|
|
var query = (from a in _context.PltRoleDepts//.Where(x => x.RecStatus == "A")
|
join b in _context.HrDepts.Where(x=> x.RecStatus=="A" && x.QiyongStatus == "A")
|
on a.DeptId equals b.Id
|
join f in _context.PltRoles
|
on a.RoleId equals f.Id
|
where a.RecStatus == "A"
|
&& (string.IsNullOrWhiteSpace(searchEntity.DeptName) || b.DeptName.Contains(searchEntity.DeptName.Trim()))
|
&& (string.IsNullOrWhiteSpace(searchEntity.RoleName) || f.RoleName.Contains(searchEntity.RoleName.Trim()))
|
&& (string.IsNullOrWhiteSpace(searchEntity.RoleId) || a.RoleId == searchEntity.RoleId.Trim())
|
select new PltRoleDeptDTO
|
{
|
Id = a.Id,
|
RoleName = f.RoleName,
|
DeptName = b.DeptName,
|
RoleId = a.RoleId,
|
|
DeptId = a.DeptId,
|
|
RecStatus = a.RecStatus,
|
Creater = a.Creater,
|
Createtime = a.Createtime,
|
Modifier = a.Modifier,
|
Modifytime = a.Modifytime,
|
}).OrderByDescending(x => x.Modifytime).ToList();
|
|
|
|
|
|
|
|
|
//if (searchEntity.totalrows == 0)
|
searchEntity.totalrows = query.Count();
|
var rolelist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
|
|
data.LoadData(searchEntity, rolelist);
|
return data;
|
}
|
|
public ResultEntity ModifyStatus(string id, string userid)
|
{
|
|
ResultEntity result = new ResultEntity();
|
result.Result = true;
|
|
var model = _context.PltRoleDepts.Find(id);
|
if (model != null)
|
{
|
model.RecStatus = "D";
|
model.Modifier = userid;
|
model.Modifytime = DateTime.Now;
|
_context.SaveChanges();
|
}
|
|
return result;
|
}
|
|
|
|
/// <summary>
|
/// 获取所有有效科目
|
/// </summary>
|
/// <returns></returns>
|
public List<PltRoleDeptDTO> GetList()
|
{
|
|
|
var listPosition = _context.PltRoleDepts.Where(r => r.RecStatus == "A").ToList();
|
|
var list = _mapper.Map<List<PltRoleDeptDTO>>(listPosition);
|
return list;
|
}
|
}
|
}
|