public static async void send(IConfigurationRoot config) { var list = getEmailAdds(config); var badList = checkForBad(list); string nameList = badList.Count() > 0 ? makeNameList(badList) : null; var client = new GraphClient().getClient(config); string sendTo = config.GetSection("sendToEmail").Value; var message = new Message { Subject = "SYSTEM GENERATED: Invalid Email Address", Body = new ItemBody { ContentType = BodyType.Text, Content = "Please check the Email Addresses for the following patients in Crystal: \r\n" + nameList }, ToRecipients = new List <Recipient>() { new Recipient { EmailAddress = new EmailAddress { Address = sendTo } } } }; var saveToSentItems = false; var target = config.GetSection("targetUserId").GetChildren().Select(x => x.Value).ToList(); if (nameList != null) { try { await client.Users[target[^ 1]].SendMail(message, saveToSentItems)
///<summary> ///This method will loop over a list of Corliss Users and for each User get all their contacts, set updated contact ids, delete any old contacts, and add the new or edited contact. ///</summary> ///<param name="list">The newly processed list of MS Contact objects</param> ///<param name="config">The configuration object</param> static async void postChangelist(List <Contact> list, IConfigurationRoot config) { var target = config.GetSection("targetUserId").GetChildren().Select(x => x.Value).ToList(); var client = new GraphClient().getClient(config); foreach (var t in target) //for each Corliss User { //this section sets up a list of ms Ids and fileAs from the User MS Contacts to compare against List <Contact> allOldContacts = new List <Contact>(); var oldContacts = await client.Users[t].Contacts .Request().Select("id,fileAs").GetAsync(); allOldContacts.AddRange(oldContacts.CurrentPage); //Graph returns pages of results, this is how we handle the pages while (oldContacts.NextPageRequest != null) { oldContacts = await oldContacts.NextPageRequest.GetAsync(); allOldContacts.AddRange(oldContacts.CurrentPage); } //Add existing MS Contact ID to any edited contacts //TODO: this should return a new List, not change the existing List if (allOldContacts.Count > 0) { foreach (var c in list) { var n = allOldContacts.Where(o => o.FileAs == c.FileAs).FirstOrDefault(); if (n != null) { c.Id = n.Id; } } } //this section will loop through the list check for null ID, delete ms Contact @ ID if !null, then add Contact int count = 0; foreach (var x in list) { if (x.Id != null) { //delete from MS Contacts by ID and Save the updated Contact in MS Contacts bool y = await deleteOldContact(t, client, x.Id) ? await addUpdatedContact(t, client, x) : false; if (y) { count++; } } else { //add new contacts to MS Contacts bool y = await addUpdatedContact(t, client, x) ? true : false; if (y) { count++; } } } string st = (count.ToString() + " contacts synced for User " + t); Logger.log("runLogger", st); } }