using AutoMapper;
using Tiobon.Core.IServices;
using Tiobon.Core.Model;
using Tiobon.Core.Model.Models;
using Tiobon.Core.Model.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Tiobon.Core.Controllers
{
///
/// 用户角色关系
///
[Produces("application/json")]
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize(Permissions.Name)]
public class UserRoleController : Controller
{
private readonly ISysUserInfoServices _sysUserInfoServices;
private readonly IUserRoleServices _userRoleServices;
private readonly IRoleServices _roleServices;
private readonly IMapper _mapper;
///
/// 构造函数
///
///
///
///
///
public UserRoleController(ISysUserInfoServices sysUserInfoServices, IUserRoleServices userRoleServices, IMapper mapper, IRoleServices roleServices)
{
_sysUserInfoServices = sysUserInfoServices;
_userRoleServices = userRoleServices;
_roleServices = roleServices;
_mapper = mapper;
}
///
/// 新建用户
///
///
///
///
[HttpGet]
public async Task> AddUser(string loginName, string loginPwd)
{
var userInfo = await _sysUserInfoServices.SaveUserInfo(loginName, loginPwd);
return new MessageModel()
{
success = true,
msg = "添加成功",
response = _mapper.Map(userInfo)
};
}
///
/// 新建Role
///
///
///
[HttpGet]
public async Task> AddRole(string roleName)
{
return new MessageModel()
{
success = true,
msg = "添加成功",
response = await _roleServices.SaveRole(roleName)
};
}
///
/// 新建用户角色关系
///
///
///
///
[HttpGet]
public async Task> AddUserRole(long uid, long rid)
{
return new MessageModel()
{
success = true,
msg = "添加成功",
response = await _userRoleServices.SaveUserRole(uid, rid)
};
}
}
}