예제 #1
0
        protected async Task <UserDTO> GetCurrentUser()
        {
            ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;
            var             userId    = principal.Claims.Where(c => c.Type == Core.Constant.Claim.ClaimsUserId).Single().Value;

            ApplicationUser entity = await this.AppUserManager.Users.Include(x => x.Roles).FirstAsync(x => x.Id == userId);

            UserDTO dto = new UserDTO();

            if (entity != null && entity.Roles != null && entity.Roles.Count > 0)
            {
                var role = await this.AppRoleManager.FindByIdAsync(entity.Roles.First().RoleId);

                dto.ConvertFromEntity(entity, role.Name);
            }
            else
            {
                dto.ConvertFromEntity(entity, string.Empty);
            }

            return(dto);
        }