Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AddRoleHandler.cs 726B

1234567891011121314151617181920212223
  1. using Diligent.WebAPI.Data.Entities;
  2. using Diligent.WebAPI.Host.Mediator.Authentication.Commands;
  3. using MediatR;
  4. using Microsoft.AspNetCore.Identity;
  5. namespace Diligent.WebAPI.Host.Mediator.Authentication.Handlers
  6. {
  7. public class AddRoleHandler : IRequestHandler<AddRoleCommand, Unit>
  8. {
  9. private readonly RoleManager<Roles> _roleManager;
  10. public AddRoleHandler(RoleManager<Roles> roleManager)
  11. {
  12. _roleManager = roleManager;
  13. }
  14. public async Task<Unit> Handle(AddRoleCommand request, CancellationToken cancellationToken)
  15. {
  16. await _roleManager.CreateAsync(new Roles() { Name = request.NameOfRole });
  17. return new Unit();
  18. }
  19. }
  20. }