BMC/BCS.BMC/src/BCS.BMC.Application/BMCAppServiceBase.cs
2022-10-10 20:44:01 +05:30

48 lines
1.3 KiB
C#

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Abp.Application.Services;
using Abp.IdentityFramework;
using Abp.Runtime.Session;
using BCS.BMC.Authorization.Users;
using BCS.BMC.MultiTenancy;
namespace BCS.BMC
{
/// <summary>
/// Derive your application services from this class.
/// </summary>
public abstract class BMCAppServiceBase : ApplicationService
{
public TenantManager TenantManager { get; set; }
public UserManager UserManager { get; set; }
protected BMCAppServiceBase()
{
LocalizationSourceName = BMCConsts.LocalizationSourceName;
}
protected virtual async Task<User> GetCurrentUserAsync()
{
var user = await UserManager.FindByIdAsync(AbpSession.GetUserId().ToString());
if (user == null)
{
throw new Exception("There is no current user!");
}
return user;
}
protected virtual Task<Tenant> GetCurrentTenantAsync()
{
return TenantManager.GetByIdAsync(AbpSession.GetTenantId());
}
protected virtual void CheckErrors(IdentityResult identityResult)
{
identityResult.CheckErrors(LocalizationManager);
}
}
}