using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using AutoMapper;
|
using DTO;
|
using IServices;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.EntityFrameworkCore;
|
using zhengcaioa.Models;
|
|
|
|
namespace Services
|
{
|
public class AdmTongxunluService: IAdmTongxunluService
|
{
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public AdmTongxunluService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
public ResultEntity save(AdmTongxunluDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
|
|
var entity = _mapper.Map<AdmTongxunlu>(dto);
|
|
|
if (String.IsNullOrEmpty(entity.Id))
|
{
|
entity.Id = Guid.NewGuid().ToString();
|
dto.Id = entity.Id;
|
_context.AdmTongxunlus.Add(entity);
|
}
|
else
|
{
|
var updateproject = _context.AdmTongxunlus.Find(entity.Id);
|
|
updateproject.TypeId = entity.TypeId;
|
updateproject.DanweiName = entity.DanweiName;
|
|
|
updateproject.Lianxidianhua = entity.Lianxidianhua;
|
updateproject.Lianxiren = entity.Lianxiren;
|
updateproject.Beuzhu = entity.Beuzhu;
|
|
updateproject.RecStatus = entity.RecStatus;
|
updateproject.Modifier = entity.Modifier;
|
updateproject.Modifytime = entity.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = entity.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public AdmTongxunluDTO Get(string id)
|
{
|
|
var entity = _context.AdmTongxunlus.Find(id);
|
|
if (entity.RecStatus != "A")
|
{
|
entity = new AdmTongxunlu();
|
}
|
|
var result = _mapper.Map<AdmTongxunluDTO>(entity);
|
|
|
return result;
|
}
|
|
public ResultDataEntity<AdmTongxunluDTO> SearchByPaging(AdmTongxunluDTOSearch searchEntity)
|
{
|
|
|
|
ResultDataEntity<AdmTongxunluDTO> data = new ResultDataEntity<AdmTongxunluDTO>();
|
List<AdmTongxunluDTO> list = new List<AdmTongxunluDTO>();
|
|
|
|
var listCode = (from a in _context.SysCodeDtls
|
join b in _context.SysCodes
|
on a.CodeId equals b.Id
|
where a.RecStatus == "A"
|
&& b.RecStatus == "A"
|
select new CodeDataEntity()
|
{
|
CodeId = b.Id,
|
CodeTable = b.CodeTable,
|
CodeField = b.CodeField,
|
CodeSn = a.CodeSn,
|
Comments = a.Comments,
|
Contents = a.Contents,
|
RecStatus = a.RecStatus,
|
Sort = a.Sort
|
}
|
);
|
|
///AdmTongxunlus
|
var query = (from a in _context.AdmTongxunlus
|
|
|
join e in listCode.Where(x => x.CodeTable == "adm_tongxunlu" && x.CodeField == "type_id")
|
on a.TypeId equals e.CodeSn
|
into esssss
|
from eee in esssss.DefaultIfEmpty()
|
|
|
|
|
|
|
where a.RecStatus == "A"
|
|
&& (string.IsNullOrWhiteSpace(searchEntity.TypeId) || a.TypeId == searchEntity.TypeId.Trim())
|
&& (string.IsNullOrWhiteSpace(searchEntity.DanweiName) || a.DanweiName.Contains(searchEntity.DanweiName.Trim()))
|
&& (string.IsNullOrWhiteSpace(searchEntity.Creater) || a.Creater == searchEntity.Creater.Trim())
|
|
|
|
|
|
|
select new AdmTongxunluDTO
|
{
|
Id = a.Id,
|
TypeId = a.TypeId,
|
TypeName = eee.Comments,
|
DanweiName = a.DanweiName,
|
Lianxiren = a.Lianxiren,
|
Lianxidianhua = a.Lianxidianhua,
|
// DocContent = a.DocContent,
|
Beuzhu = a.Beuzhu,
|
|
|
|
|
|
|
|
Creater = a.Creater,
|
Createtime = a.Createtime,
|
|
RecStatus = a.RecStatus,
|
Modifier = a.Modifier,
|
Modifytime = a.Modifytime,
|
|
}
|
).OrderByDescending(x => x.Modifytime).ToList();
|
|
|
|
//if (searchEntity.totalrows == 0)
|
searchEntity.totalrows = query.Count();
|
var lianlist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
|
data.LoadData(searchEntity, lianlist);
|
return data;
|
}
|
|
|
|
|
|
|
/// <summary>
|
/// 修改主表状态
|
/// </summary>
|
/// <param name="id">主id</param>
|
/// <param name="userid">用户</param>
|
/// <returns></returns>
|
public ResultEntity ModifyStatus(string id, string userid)
|
{
|
ResultEntity result = new ResultEntity();
|
result.Result = true;
|
|
var model = _context.AdmTongxunlus.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<AdmTongxunluDTO> GetList()
|
{
|
|
|
var listRole = _context.AdmTongxunlus.Where(r => r.RecStatus == "A").ToList();
|
|
|
var list = _mapper.Map<List<AdmTongxunluDTO>>(listRole);
|
return list;
|
}
|
}
|
}
|