You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
5.4 KiB
C#

using Admin.Core.Model;
using Admin.Core.Common.Resource;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Admin.Core.Common;
using Admin.Core.IService.ISys;
using Admin.Core.Model.Sys;
namespace Admin.Core.Api
{
/// <summary>
/// SysNoticeController
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize(Permissions.Name)]
public class SysNoticeController : BaseApiUserController
{
/// <summary>
/// _sysNoticeService
/// </summary>
private readonly ISysNoticeService _sysNoticeService;
/// <summary>
/// 构造方法
/// </summary>
/// <param name="SysNoticeService"></param>
/// <param name="sysUserService"></param>
public SysNoticeController(ISysNoticeService SysNoticeService, ISysUserService sysUserService) : base(sysUserService)
{
_sysUserService = sysUserService;
_sysNoticeService = SysNoticeService;
}
/// <summary>
/// 分页查询
/// </summary>
/// <param name="pageQuery"></param>
/// <returns></returns>
[HttpPost]
[Action("通知公告", ActionType.QUERY)]
public async Task<MessageModel<PageModel<SysNotice>>> GetByPage([FromBody] PageQuery<SysNotice> pageQuery)
{
Expression<Func<SysNotice, bool>> whereExpression = x => true;
if (pageQuery.Query.NoticeTitle.IsNotEmptyOrNull())
{
whereExpression = whereExpression.And(x => x.NoticeTitle.Contains(pageQuery.Query.NoticeTitle));
}
if (pageQuery.Query.NoticeType.IsNotEmptyOrNull())
{
whereExpression = whereExpression.And(x => x.NoticeType == pageQuery.Query.NoticeType);
}
if (pageQuery.Query.CreateBy.IsNotEmptyOrNull())
{
whereExpression = whereExpression.And(x => x.CreateBy.Contains(pageQuery.Query.CreateBy));
}
if (pageQuery.Query.Status.IsNotEmptyOrNull())
{
whereExpression = whereExpression.And(x => x.Status == pageQuery.Query.Status);
}
var data = await _sysNoticeService.QueryPageAsync(whereExpression, pageQuery.Page, pageQuery.PageSize, "UpdateTime desc");
return Success(data);
}
/// <summary>
/// 根据ID查询
/// </summary>
/// <param name="id">主键</param>
/// <returns></returns>
[HttpGet]
[Action("通知公告", ActionType.QUERY)]
public async Task<MessageModel<SysNotice>> GetByID(int id)
{
return new MessageModel<SysNotice>()
{
msg = Resource_SysBase.OprateSuccess,
success = true,
data = await _sysNoticeService.QueryByIdAsync(id)
};
}
/// <summary>
/// 新增一条数据
/// </summary>
/// <param name="request">SysNotice</param>
/// <returns></returns>
[HttpPost]
[Action("通知公告", ActionType.ADD)]
public async Task<MessageModel<int>> Add([FromBody] SysNotice request)
{
var data = new MessageModel<int>();
request.CreateBy = CurrentUser.LoginName;
request.UpdateBy = CurrentUser.LoginName;
request.CreateTime = DateTime.Now;
request.UpdateTime = DateTime.Now;
data.data = await _sysNoticeService.AddAsync(request);
if (data.success)
{
data.success = true;
data.msg = Resource_SysBase.OprateSuccess;
}
else
{
data.success = false;
data.msg = Resource_SysBase.OprateFail;
}
return data;
}
/// <summary>
/// 更新一条数据
/// </summary>
/// <param name="request">SysNotice</param>
/// <returns></returns>
[HttpPost]
[Action("通知公告", ActionType.UPDATE)]
public async Task<MessageModel<bool>> Update([FromBody] SysNotice request)
{
var data = new MessageModel<bool>();
request.UpdateBy = CurrentUser.LoginName;
request.UpdateTime = DateTime.Now;
data.success = await _sysNoticeService.UpdateAsync(request);
if (data.success)
{
data.msg = Resource_SysBase.OprateSuccess;
}
else
{
data.msg = Resource_SysBase.OprateFail;
}
return data;
}
/// <summary>
/// 删除一条数据
/// </summary>
/// <param name="ids">主键</param>
/// <returns></returns>
[HttpPost]
[Action("通知公告", ActionType.DEL)]
public async Task<MessageModel<bool>> Del(List<int> ids)
{
var data = new MessageModel<bool>();
data.success = await _sysNoticeService.DeleteByIdAsync(ids);
if (data.success)
{
data.msg = Resource_SysBase.OprateSuccess;
}
else
{
data.msg = Resource_SysBase.OprateFail;
}
return data;
}
}
}