Browse Source

Listed user and roles in console application.

pull/81/head
Halil İbrahim Kalkan 10 years ago
parent
commit
6d0b501ce4
  1. 10
      src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs
  2. 26
      src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs
  3. 2
      src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUser.cs
  4. 2
      src/Volo.Abp/Volo/Abp/Uow/IUnitOfWork.cs

10
src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs

@ -17,11 +17,11 @@ namespace AbpDesk.ConsoleDemo
.ServiceProvider .ServiceProvider
.GetRequiredService<TicketLister>() .GetRequiredService<TicketLister>()
.List(); .List();
//application application
// .ServiceProvider .ServiceProvider
// .GetRequiredService<UserLister>() .GetRequiredService<UserLister>()
// .List(); .List();
Console.ReadLine(); Console.ReadLine();

26
src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs

@ -1,6 +1,9 @@
using System; using System;
using System.Linq; using System.Linq;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using Volo.Abp.Threading;
using Volo.Abp.Uow;
using Volo.DependencyInjection; using Volo.DependencyInjection;
namespace AbpDesk.ConsoleDemo namespace AbpDesk.ConsoleDemo
@ -8,17 +11,34 @@ namespace AbpDesk.ConsoleDemo
public class UserLister : ITransientDependency public class UserLister : ITransientDependency
{ {
private readonly IdentityUserManager _userManager; private readonly IdentityUserManager _userManager;
private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly IQueryableRepository<IdentityUser> _userRepository;
public UserLister(IdentityUserManager userManager) public UserLister(
IdentityUserManager userManager,
IQueryableRepository<IdentityUser> userRepository,
IUnitOfWorkManager unitOfWorkManager)
{ {
_userManager = userManager; _userManager = userManager;
_userRepository = userRepository;
_unitOfWorkManager = unitOfWorkManager;
} }
public void List() public void List()
{ {
foreach (var user in _userManager.Users.ToList()) using (var uow = _unitOfWorkManager.Begin())
{ {
Console.WriteLine(user); foreach (var user in _userRepository.ToList())
{
Console.WriteLine("# " + user);
foreach (var roleName in AsyncHelper.RunSync(() => _userManager.GetRolesAsync(user)))
{
Console.WriteLine(" - " + roleName);
}
}
AsyncHelper.RunSync(() => uow.CompleteAsync());
} }
} }
} }

2
src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUser.cs

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
@ -14,6 +13,7 @@ namespace Volo.Abp.Identity
//TODO: Should set Id to a GUID (where? on repository?) //TODO: Should set Id to a GUID (where? on repository?)
//TODO: Properties should not be public! //TODO: Properties should not be public!
//TODO: Add Name/Surname/FullName? //TODO: Add Name/Surname/FullName?
//TODO: Set max lenght for Id (set a default max lenght by default, like 64)
public class IdentityUser : AggregateRoot, IHasConcurrencyStamp public class IdentityUser : AggregateRoot, IHasConcurrencyStamp
{ {

2
src/Volo.Abp/Volo/Abp/Uow/IUnitOfWork.cs

@ -7,6 +7,8 @@ using Volo.DependencyInjection;
namespace Volo.Abp.Uow namespace Volo.Abp.Uow
{ {
//TODO: Sync versions of methods!
public interface IUnitOfWork : IDisposable, IServiceProviderAccessor, ITransientDependency public interface IUnitOfWork : IDisposable, IServiceProviderAccessor, ITransientDependency
{ {
[CanBeNull] [CanBeNull]

Loading…
Cancel
Save