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

94 lines
2.7 KiB

using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Volo.Abp.Identity;
using Win_in.Sfs.Auth.Application.Contracts;
using Win_in.Sfs.Auth.Domain;
namespace Win_in.Sfs.Auth.Application;
[Authorize]
[Route($"{AuthConsts.RootPath}department")]
public class DepartmentAppService
: SfsBaseDataWithCodeAppServiceBase<Department, DepartmentDTO, SfsAuthRequestInputBase, DepartmentCreateInput>
, IDepartmentAppService
{
private readonly IdentityUserManager _identityUserManager;
private new readonly IDepartmentRepository _repository;
private readonly IConfiguration _configuration;
public DepartmentAppService(
IDepartmentRepository repository, IdentityUserManager identityUserManager, IConfiguration configuration) : base(repository)
{
_repository = repository;
base.CreatePolicyName = DepartmentPermissions.Create;
base.UpdatePolicyName = DepartmentPermissions.Update;
base.DeletePolicyName = DepartmentPermissions.Delete;
_identityUserManager = identityUserManager;
_configuration = configuration;
}
[AllowAnonymous]
[HttpGet("by-username")]
public virtual async Task<DepartmentDTO> GetByUsernameAsync(string username)
{
var user = await _identityUserManager.FindByNameAsync(username).ConfigureAwait(false);
if (user == null)
{
return null;
}
var departmentCode = user.GetDepartmentCode();
if (string.IsNullOrEmpty(departmentCode))
{
return null;
}
var deptDto = await GetByCodeAsync(departmentCode).ConfigureAwait(false);
if (username.ToLower() == "wms")
{
var depCode=_configuration["WmsDepCode"];
deptDto.Code = depCode;
}
return deptDto;
}
[AllowAnonymous]
[HttpGet("by-userid")]
public virtual async Task<DepartmentDTO> GetByUserIdAsync(string userId)
{
var user = await _identityUserManager.FindByIdAsync(userId).ConfigureAwait(false);
if (user == null)
{
return null;
}
var departmentCode = user.GetDepartmentCode();
if (string.IsNullOrEmpty(departmentCode))
{
return null;
}
var deptDto = await GetByCodeAsync(departmentCode).ConfigureAwait(false);
return deptDto;
}
[AllowAnonymous]
[HttpPost("update")]
public virtual async Task UpdateAsync(DepartmentCreateInput input)
{
var entity = ObjectMapper.Map<DepartmentCreateInput, Department>(input);
await _repository.UpdateAsync(entity).ConfigureAwait(false);
}
}