Last post Nov 16, 2017 06:06 AM by X.Daisy
Nov 15, 2017 07:14 AM|loraine26|LINK
I am working on web app that sends an email notification to tagged users. I have 2 options to tag the users -
individually and group. What I want to do is, if the tagged user in individual tagging is already belong to group tag, only 1 notification will be sent to tagged user.
This is my code. This code is working when only 1 user is tagged in individual tagging. For example,
User1 is tagged in individual tagging. And in
group tagging, I tagged Group1 which composed of 3 users (which includes the
User1 in this group), only the 2 users under the Group1 has received an email notification.
But the problem is, when I tried to tagged more than 1 users in individual tagging, all the users under the
group tagging is still receiving an email notification.
if (GroupUsersID != null && UsersID != null)
foreach (var Users in GroupUsersID)
foreach (var Users2 in UsersID)
foreach (var grp2 in usersInGroup)
if (grp2.group_id == Users)
foreach (var usersList in users)
if (grp2.user_id == usersList.user_id && Users2 != grp2.user_id)
if (usersList.user_id != Users2)
var adUsersList = db.ad_users.Find(usersList.user_id);
var emp = adUsersList.employee_nr;
if (emp != null)
mail.Body = TestMessage();
mail2.Body = TestMessage2();
foreach (var irCreatoremail in empEmail)
if (mail.To.Count > 0)
if (mail2.To.Count > 0)
catch (InvalidOperationException /*ex*/)
What am I doing wrong here?
Thank you in advance.
Nov 15, 2017 08:38 AM|oned_gk|LINK
My idea is simple, collect all into one then make it distinct
create recieverlist, add all to the recieverlist except already exist
Nov 15, 2017 11:39 PM|loraine26|LINK
Thank you for the response.
But can I ask how to do this? Can you give a sample code for that? Or, how can I apply that in my existing code like the one I have posted.
Thank you so much in advance.
Nov 16, 2017 12:57 AM|oned_gk|LINK
Maybe like this
//foreach users in group, add it to receiver if not exist in receiver//foreach receiver, prepare sending message
Nov 16, 2017 06:06 AM|X.Daisy|LINK
Just like what oned_gk said, you can select all of the users which need to be sent email to and then use 'distinct'.
var list=new List<int>()
1. Select individual UserId which are targeted, add them to list.
2. Select group UserId which are targeted, add them to list.
4. According to the UserId in list, send email to these user.