| 12345678910111213141516171819202122232425262728293031 |
- using System;
- using System.Security.Principal;
- using BO.AppServer.Data.Entity;
- using Microsoft.AspNetCore.Identity;
- using Microsoft.Extensions.Logging;
- using Quadarax.Foundation.Core.Business;
- namespace BO.AppServer.Business.Services.Base
- {
- public abstract class UserContextService : AbstractService
- {
- protected UserManager<IdentityUser> _manUser;
- protected UserRepo _repoUser;
- protected UserContextService(UserRepo repoUser, UserManager<IdentityUser> userManager, IPrincipal currentPrincipal, ILoggerFactory logger) : base(currentPrincipal, logger)
- {
- _manUser = userManager ?? throw new ArgumentNullException(nameof(userManager));
- _repoUser = repoUser ?? throw new ArgumentNullException(nameof(repoUser));
- }
- protected User GetCurrentUser()
- {
- var userIdt = _manUser.FindByNameAsync(CurrentPrincipal.Identity.Name).Result;
- return _repoUser.GetByIfReference(userIdt.Id);
- }
- protected long GetCurrentUserId()
- {
- var user = GetCurrentUser();
- return user.Id;
- }
- }
- }
|