public Task <CommandResult <UserForUserDto> > Handle(GetCurrentUserQuery query) { var user = access.CurrentUser(); if (user == null) { return(CommandResult <UserForUserDto> .Fail(UserManagementError.UserNotLoggedIn()).AsTaskTyped()); } var userDto = UserMap.ToUserForUserDto(user, tenantRepo.GetAll().ToDictionary(t => t.TenantId.ToString(), t => t.TenantName)); if (userDto == null) { return(CommandResult <UserForUserDto> .Fail(UserManagementError.UserNotFound()).AsTaskTyped()); } return(CommandResult <UserForUserDto> .Success(userDto).AsTaskTyped()); }
public Task <CommandResult> Handle(AddTenantToUserCommand command) { var user = access.CurrentUser(); if (user == null) { return(CommandResult.Fail(UserManagementError.UserNotLoggedIn()).AsTask()); } var tenant = tenantRepo.Get(command.TenantId); if (tenant == null) { return(CommandResult.Fail(ValidationError.New().AddError(nameof(command.TenantId), "Invalid Organization Id")).AsTask()); } if (command.ValidateOnly) { return(CommandResult.Success().AsTask()); } if (user.Tenants.Any(t => t.TenantId == command.TenantId)) { return(CommandResult.Success().AsTask()); } user.Tenants.Add(new Entities.UserTenant() { TenantId = command.TenantId, Permissions = new Dictionary <string, HashSet <string> >() }); userRepo.Update(user); return(CommandResult.Success().AsTask()); }