Crystal Rouse
asked on
Convert a string to a list
I have the following code that returns one record. I need to convert this to a list and return single or more than one.
This sends the email:
public string GetApproverEmail()
{
try
{
var user = (from x in DB.tbl_User
where x.Approver == true
select x).Single();
var email = (from x in DB.tbl_GlobalUser
where x.ID == user.UserID
select x.Email).Single();
return (email);
}
catch
{
return null;
}
}
This sends the email:
public static void Approve(tbl_ChangeRequest cr)
{
User user = new User();
Email mail = new Email("Approval");
string Email = user.GetApproverEmail();
string body = ("This is an automated email.<br />" + "" +
"text here"" +
" is ready for approval. <br />" + "<br />" +
);
mail.SetBody(body, true);
mail.AddTo(Email);
mail.AddCC("");
mail.Send();
}
ASKER
A single email to multiple recipients.
Okay, I think this should get you pretty close, although you might have to shake it out a little there to perfect it.
»bp
public List<string> GetApproverEmail()
{
try
{
var user = (from x in DB.tbl_User
where x.Approver == true
select x).Single();
List<string> email = (from x in DB.tbl_GlobalUser
where x.ID == user.UserID
select x.Email).ToList();
return (email);
}
catch
{
return null;
}
}
public static void Approve(tbl_ChangeRequest cr)
{
User user = new User();
Email mail = new Email("Approval");
List<string> email = user.GetApproverEmail();
string body = ("This is an automated email.<br />" + "" +
"text here"" +
" is ready for approval. <br />" + "<br />" +
);
mail.SetBody(body, true);
foreach (string e in email) {
mail.AddTo(e);
}
mail.AddCC("");
mail.Send();
}
»bp
ASKER
Thank you so much! For the user:
var user = (from x in DB.tbl_User
where x.Approver == true
select x).Single();
I actually need to return a list since there will be more than one Approver. So, I think I need to return the List of emails for all users.
I probably need to add a semi-colon after each one as well. Can you help me update this? This is part I have problems with is figuring
out lists and how to loop thru them.
var user = (from x in DB.tbl_User
where x.Approver == true
select x).Single();
I actually need to return a list since there will be more than one Approver. So, I think I need to return the List of emails for all users.
I probably need to add a semi-colon after each one as well. Can you help me update this? This is part I have problems with is figuring
out lists and how to loop thru them.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You! Now I forgot about joining tables. I really appreciate it!
Welcome, glad that was helpful.
»bp
»bp
»bp