You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AddRoleHandler.cs 762B

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