public async Task <IActionResult> LockoutUsers([Required] LockUsersDTO model) { try { foreach (var id in model.UserIds) { var userInDb = await dbContext.Users.FindAsync(id); if (userInDb == null) { return(BadRequest()); } userInDb.LockoutEnd = new DateTimeOffset(model.LockUntil.HasValue ? model.LockUntil.Value : DateTime.Now.AddYears(100)); } dbContext.AddAuditCustomField("Title", "Locked users"); await dbContext.SaveChangesAsync(); return(NoContent()); } catch (Exception) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
public async Task Handle(ContactsDeletedIntegrationEvent @event) { using (LogContext.PushProperty("CorrelationId", @event.CorrelationId)) { _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); // get ids of affected users var usernames = new List <string>(); // remove contact ids from users await dbContext.Users.Where(u => u.ContactId.HasValue && @event.ContactIds.Contains(u.ContactId.Value)) .ForEachAsync(u => { u.ContactId = null; usernames.Add(u.UserName); }); dbContext.AddAuditCustomField("CorrelationId", @event.CorrelationId); dbContext.AddAuditCustomField("AuditUsername", @event.User); await dbContext.SaveChangesAsync(); // send notification to users affected eventBus.Publish(new NotificationIntegrationEvent("You can no longer receive or send forms", NotificationIntegrationEvent.NotificationType.Warning) .ToUsers(usernames) .WithCorrelationId(@event.CorrelationId) .ByUser(@event.User)); } }