public async Task AddNotificationSettingByUserId(int notificationCodeId, UserProfile userProfile, int roleid) { List <UserProfile> users = new List <UserProfile>(); users.Add(userProfile); List <int> userIds = new List <int>(); userIds.Add(userProfile.Id); var userNotificationSettings = await _iNotificationQuerie.GetNotificationSettingsByCodeId(notificationCodeId); var usersHaveSetting = userNotificationSettings.Select(d => d.UserProfileId).ToList(); var usersHavntSetting = userIds.Where(d => !usersHaveSetting.Contains(d)).ToList(); var Code = await _iNotificationQuerie.GetDefaultSettingByCodeId(notificationCodeId); foreach (var usr in users.Where(d => usersHavntSetting.Contains(d.Id)).ToList()) { usr.AddNotificationSetting( new UserNotificationSetting(Code.OperationCode, usr.Id, Code.NotificationOperationCodeId, Code.DefaultSMS, Code.DefaultEmail, roleid)); } _genericrepository.UpdateRange <UserProfile>(users); await _genericrepository.SaveAsync(); }