protected virtual async Task <List <UserNotificationDto> > SaveUserNotifications(long[] userIds, NotificationScheme notificationScheme) { var userNotificationDtos = new List <UserNotificationDto>(); var notificationDetail = new NotificationDetail(notificationScheme); await _notificationRepository.InsertNotificationDetailAsync(notificationDetail); await _notificationRepository.SaveChangesAsync(); //To get notificationDetail.Id. var notificationDetailDto = notificationDetail.ToNotificationDetailDto(); foreach (var userId in userIds) { var userNotification = new UserNotification() { UserId = userId, NotificationDetailId = notificationDetail.Id }; await _notificationRepository.InsertUserNotificationAsync(userNotification); userNotificationDtos.Add(userNotification.ToUserNotificationDto(notificationDetailDto)); } await _notificationRepository.SaveChangesAsync(); return(userNotificationDtos); }