Hi @maliming,
I was updating entites (that implemented IMustHaveTenant) prior to sending the notification and I found that I needed to call CurrentUnitOfWork.SaveChangesAsync() before sending the notification.
Thanks,
Wg
Hi @maliming,
Version 8.5.0.
Here is the full class; I create a new list of Abp.UserIdentifier(tenant, userId) and there are values for the parameters being passed to PublishAsync.
Thanks,
Wg
public class UserNotificationAppService : WizgodIncAppServiceBase, IUserNotificationAppService
{
private readonly INotificationPublisher _notificationPublisher;
private readonly IUserAppService _userAppService;
private readonly ITimeSheetApproversAppService _timeSheetApproversAppService;
public UserNotificationAppService(INotificationPublisher notificationPublisher,
IUserAppService userAppService,
ITimeSheetApproversAppService timeSheetApproversAppService)
{
_notificationPublisher = notificationPublisher;
_userAppService = userAppService;
_timeSheetApproversAppService = timeSheetApproversAppService;
}
[AbpAllowAnonymous]
public virtual async Task SendNotificationToApprovers(long fromUserId, string url, string message, string notificationName, int severity)
{
var user = await _userAppService.GetUser(new EntityDto<long> {Id = fromUserId});
if (!user.TimeSheetApproversId.HasValue) return;
var timeSheetApprovers =
await _timeSheetApproversAppService.GetTimeSheetApprovers(
new EntityDto {Id = user.TimeSheetApproversId.Value});
var approverIds = new List<long?> { timeSheetApprovers.ApproverId };
if (timeSheetApprovers.FirstBackupApproverId.HasValue) approverIds.Add(timeSheetApprovers.FirstBackupApproverId.Value);
if (timeSheetApprovers.SecondBackupApproverId.HasValue) approverIds.Add(timeSheetApprovers.SecondBackupApproverId.Value);
var userIds = approverIds.Select(q => new Abp.UserIdentifier(2, q.Value)).ToArray();
message = message.Replace("[Name]", user.Name)
.Replace("[Surname]", user.Surname)
.Replace("[EmployeeID]", user.EmployeeId);
var data = new MessageNotificationData(message) {["url"] = url};
await _notificationPublisher.PublishAsync(notificationName, data, null,(NotificationSeverity)severity, userIds);
}
[AbpAllowAnonymous]
public virtual async Task SendNotificationToUser(long fromUserId, string url, string message, string notificationName, int notificationServerity, long userId)
{
await SendNotificationToUsers(fromUserId, url, message, notificationName, notificationServerity, new[] { userId });
}
[AbpAllowAnonymous]
public virtual async Task SendNotificationToUsers(long fromUserId, string url, string message, string notificationName, int severity, long[] userIds)
{
var user = await UserManager.GetUserByIdAsync(fromUserId);
var userIdentifiers = userIds.Select(q => new Abp.UserIdentifier(2, q)).ToArray();
message = message.Replace("[Name]", user.Name)
.Replace("[Surname]", user.Surname)
.Replace("[EmployeeID]", user.EmployeeId);
var data = new MessageNotificationData(message) {["url"] = url};
await _notificationPublisher.PublishAsync(notificationName, data, severity: (NotificationSeverity)severity, userIds: userIdentifiers);
}
}
@ismcagdas, I've figured it out; it was an oversight on my part.
When I was migrating the users, I was setting the new NormalizedUserName column with UPPER(Name + ' ' + Surname) instead of UPPER(UserName).
Thanks,
Wg
Hi @ismcagdas,
Has that method changed for 8.5.0?
It's saying that _passwordHasher is not accessable because it's private.
Thanks,
Wg
Hi @ismcagdas,
Will do. I'll let you know in about 10 days; tied up till then.
Thanks,
Wg
Hi @ismcagdas,
I added that code and overrode the method in LogInManager.
At:
var user = await UserManager.FindByNameOrEmailAsync(tenantId, userNameOrEmailAddress);
When it's null,it trys to create the object and the "Email is already taken" exception is thrown at:
await UserManager.CreateAsync(user);
Hi @ismcagdas,
Abp and Abp.* packages are v5.4.0 with Abp.AspNetZeroCore and Abp.AspNetZeroCore.Web being v2.0.0.
I found that I was able to log in with the email address and after that, I was able to log in normally with the username.
Is there something I can update so this isn't necessary?
Thanks very much @ismcagdas!
Hi @maliming,
I am using Castle.Core.Logging and injecting ILogger for the _ logger instance, is this correct?
Thanks,
Wg