using AutoMapper;
|
using DTO;
|
using DTO.Models;
|
using IServices;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using zhengcaioa.IService;
|
using zhengcaioa.Models;
|
|
namespace Services
|
{
|
public class GroupTopicService : IGroupTopicService
|
{
|
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public GroupTopicService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
|
|
public ResultEntity save(GroupTopicDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
var GroupTopic = _mapper.Map<GroupTopic>(dto);
|
if (String.IsNullOrEmpty(GroupTopic.Id))
|
{
|
GroupTopic.Id = Guid.NewGuid().ToString();
|
_context.GroupTopics.Add(GroupTopic);
|
}
|
else
|
{
|
var updateGroupTopic = _context.GroupTopics.Find(GroupTopic.Id);
|
updateGroupTopic.Topicname = GroupTopic.Topicname;
|
updateGroupTopic.Sort = GroupTopic.Sort;
|
|
|
updateGroupTopic.RecStatus = GroupTopic.RecStatus;
|
// updateGroupTopic.Creater = GroupTopic.Creater;
|
//updateGroupTopic.Createtime = GroupTopic.Createtime;
|
updateGroupTopic.Modifier = GroupTopic.Modifier;
|
updateGroupTopic.Modifytime = GroupTopic.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = GroupTopic.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public GroupTopicDTO Get(string id)
|
{
|
GroupTopic entity = _context.GroupTopics.Find(id);
|
if (entity.RecStatus != "A")
|
{
|
entity = new GroupTopic();
|
}
|
|
var GroupTopicDTO = _mapper.Map<GroupTopicDTO>(entity);
|
return GroupTopicDTO;
|
}
|
|
public ResultDataEntity<GroupTopicDTO> SearchByPaging(GroupTopicDTOSearch searchEntity)
|
{
|
ResultDataEntity<GroupTopicDTO> data = new ResultDataEntity<GroupTopicDTO>();
|
List<GroupTopicDTO> list = new List<GroupTopicDTO>();
|
//筛选
|
var query = _context.GroupTopics
|
.Where(b => b.RecStatus == "A")
|
.ToList();
|
|
if (!string.IsNullOrEmpty(searchEntity.Topicname))
|
{
|
query = query.Where(m => m.Topicname.Contains(searchEntity.Topicname)).ToList();
|
}
|
|
|
|
|
query = query.OrderBy(x => x.Sort).ToList();
|
//if (searchEntity.totalrows == 0)
|
searchEntity.totalrows = query.Count();
|
var rolelist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
|
list = _mapper.Map<List<GroupTopicDTO>>(rolelist);
|
data.LoadData(searchEntity, list);
|
return data;
|
}
|
|
public ResultEntity ModifyStatus(string id, string userid)
|
{
|
|
ResultEntity result = new ResultEntity();
|
result.Result = true;
|
|
var model = _context.GroupTopics.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<GroupTopicDTO> GetList()
|
{
|
|
|
var listRole = _context.GroupTopics.Where(r => r.RecStatus == "A").ToList();
|
|
var list = _mapper.Map<List<GroupTopicDTO>>(listRole);
|
return list;
|
}
|
|
public List<GroupTopicDTO> GetListsalary(string userid, DateTime datemin, DateTime datemax)
|
{
|
|
|
var listRole = _context.GroupTopics.Where(r => r.RecStatus == "A" && r.Creater == userid && r.Createtime >= datemin && r.Createtime < datemax ).ToList();
|
|
var list = _mapper.Map<List<GroupTopicDTO>>(listRole);
|
return list;
|
}
|
}
|
}
|