public ActionResult ExportCSV(string emailList)
{
string FilePath = Server.MapPath("/App_Data/");
string FileName = "EmailList.csv";
System.IO.File.WriteAllText(FilePath + FileName, emailList);
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/csv";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
response.TransmitFile(FilePath + FileName);
response.Flush();
System.IO.File.Delete(FilePath + FileName); // Deletes the file on server
response.End();
List <string> listOfEmails = emailList.Split(',').ToList();
foreach (var emailName in listOfEmails)
{
//Takes each email in list and searches for it on the JPStudents table and finds the associated ApplicationUserID.
//Then calls the UpdateLatestContact method on each ApplicationUserID.
var userId = db.JPStudents.Where(x => x.JPEmail == emailName).First().ApplicationUserId.ToString();
UpdateLatestContact(userId);
}
return(RedirectToAction("Index"));
}