using Microsoft.AspNetCore.Mvc;
|
using System.Net;
|
using System.Net.Http.Headers;
|
using Microsoft.Extensions.Hosting.Internal;
|
using Microsoft.AspNetCore.Http.Extensions;
|
using IStation.Untity;
|
using Furion.DynamicApiController;
|
using System.ComponentModel.DataAnnotations;
|
using Mapster;
|
|
|
namespace IStation.Application
|
{
|
/// <summary>
|
/// UserRole
|
/// </summary>
|
[Route("User/UserRole")]
|
[ApiDescriptionSettings("User", Name = "用户角色分配", Order = 700)]
|
public class UserRole_Controller : IDynamicApiController
|
{
|
private Service.UserRoleMapping _service = new Service.UserRoleMapping();
|
|
#region Query
|
|
/// <summary>
|
/// 获取所有
|
/// </summary>
|
[Route("GetAll@V1.0")]
|
[HttpGet]
|
public List<UserRoleDto> GetAll()
|
{
|
var list = _service.GetAll();
|
var dtoList = list?.Select(x => x.Adapt<Model.UserRoleMapping, UserRoleDto>()).ToList();
|
return dtoList;
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
/// <param name="ID">标识 (必须大于0)</param>
|
/// <returns></returns>
|
[Route("GetByID@V1.0")]
|
[HttpGet]
|
public UserRoleDto GetByID
|
(
|
[Required,Range(1,long.MaxValue,ErrorMessage ="ID 必须大于0")]
|
long ID
|
)
|
{
|
var model = _service.GetByID(ID);
|
return model?.Adapt<Model.UserRoleMapping, UserRoleDto>();
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
[Route("GetByIds@V1.0")]
|
[HttpGet]
|
public List<UserRoleDto> GetByIds([FromQuery] IdsInput model)
|
{
|
var ids = LongListHelper.ToList(model.Ids);
|
var list = _service.GetByIds(ids);
|
var dtoList = list?.Select(x => x.Adapt<Model.UserRoleMapping, UserRoleDto>()).ToList();
|
return dtoList;
|
}
|
|
/// <summary>
|
/// 根据Role获取
|
/// </summary>
|
[Route("GetByRoleID@V1.0")]
|
[HttpGet]
|
public List<UserRoleDto> GetByRoleID
|
(
|
[Required,Range(1,long.MaxValue,ErrorMessage ="RoleID 必须大于0")]
|
long RoleID
|
)
|
{
|
var list = _service.GetByRoleID(RoleID);
|
var dtoList = list?.Select(x => x.Adapt<Model.UserRoleMapping, UserRoleDto>()).ToList();
|
return dtoList;
|
}
|
|
/// <summary>
|
/// 通过 UserID 获取
|
/// </summary>
|
[Route("GetByUserID@V1.0")]
|
[HttpGet]
|
public List<UserRoleDto> GetByUserID
|
(
|
[Required,Range(1,long.MaxValue,ErrorMessage ="UserID 必须大于0")]
|
long UserID
|
)
|
{
|
var list = _service.GetByUserID(UserID);
|
var dtoList = list?.Select(x => x.Adapt<Model.UserRoleMapping, UserRoleDto>()).ToList();
|
return dtoList;
|
}
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
[Route("Insert@V1.0")]
|
[HttpPost]
|
public long Insert(AddUserRoleInput input)
|
{
|
if (input == null)
|
return default;
|
var model = input.Adapt<AddUserRoleInput, Model.UserRoleMapping>();
|
var id = _service.Insert(model);
|
return id;
|
}
|
|
/// <summary>
|
/// 插入多条
|
/// </summary>
|
[Route("Inserts@V1.0")]
|
[HttpPost]
|
public bool Inserts(List<AddUserRoleInput> inputList)
|
{
|
if (inputList == null || inputList.Count < 1)
|
return false;
|
var list = inputList.Select(x => x.Adapt<AddUserRoleInput, Model.UserRoleMapping>()).ToList();
|
var bol = _service.Inserts(list);
|
return bol;
|
}
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
[Route("Update@V1.0")]
|
[HttpPut]
|
public bool Update(UpdateUserRoleInput input)
|
{
|
if (input == null)
|
return false;
|
var model = _service.GetByID(input.ID);
|
if (model == null)
|
return false;
|
var rhs = new Model.UserRoleMapping(model);
|
input.Adapt(rhs);
|
var bol = _service.Update(rhs);
|
return bol;
|
}
|
|
/// <summary>
|
/// 更新多条
|
/// </summary>
|
[Route("Updates@V1.0")]
|
[HttpPut]
|
public bool Updates(List<UpdateUserRoleInput> inputList)
|
{
|
if (inputList == null || inputList.Count() < 1)
|
{
|
return false;
|
}
|
var modelList = _service.GetByIds(inputList.Select(x => x.ID).ToList());
|
if (modelList == null || modelList.Count < 1)
|
return false;
|
var rhsList = new List<Model.UserRoleMapping>();
|
modelList.ForEach(x =>
|
{
|
var input = inputList.Find(t => t.ID == x.ID);
|
if (input != null)
|
{
|
var rhs = new Model.UserRoleMapping(x);
|
input.Adapt(rhs);
|
rhsList.Add(rhs);
|
}
|
});
|
if (rhsList.Count < 1)
|
return false;
|
var bol = _service.Updates(rhsList);
|
return bol;
|
}
|
|
#endregion
|
|
#region Set
|
|
/// <summary>
|
/// 设置
|
/// </summary>
|
[Route("Set@V1.0")]
|
[HttpPost]
|
public bool Set([Required] List<Model.UserRoleSelected> inputList)
|
{
|
if (inputList == null || inputList.Count < 1)
|
return false;
|
var bol = _service.Set(inputList);
|
return bol;
|
}
|
|
#endregion
|
}
|
}
|