Created
February 20, 2017 20:31
-
-
Save vgirard/be7da18ab5cf793b985ccdfcdb48da23 to your computer and use it in GitHub Desktop.
méthode d'appel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ActionResult GetCoursePlan(Course course, Language lang) | |
{ | |
// get values ready for insert in the docx file | |
var bookmarks = new Dictionary<string, string>(); | |
var bookmarksHeaderFooter = new Dictionary<string, string>(); | |
var htmlChunks = new Dictionary<string, string>(); | |
var model = string.Empty; | |
var file = string.Empty; | |
// html chuncks in the document area | |
//Remplace la section <w:altChunk r:id="PlandeCours"/> dans le document | |
var suggestions = course | |
.Suggestions | |
.Where(x => x.Course != null && x.Course.IsActive) | |
.Where(x => x.Course != null && x.Course.Category != null && x.Course.Category.IsActive) | |
.ToList(); | |
if (lang == Language.English) | |
{ | |
//Obtenir les suggestions de cours en anglais | |
var liste = string.Empty; | |
foreach (var courseSuggestion in suggestions) | |
{ | |
liste += "<li>" + HttpUtility.HtmlEncode(courseSuggestion.Course.EnglishName) + "</li>"; | |
} | |
if (!string.IsNullOrEmpty(liste)) | |
{ | |
liste = "<h1 style='margin:0;padding:0;'>We also suggest these courses:</h1><ul>" + liste + "</ul>"; | |
} | |
htmlChunks.Add("PlandeCours", course.PlanEnglish + liste); | |
model = Server.MapPath("~\\Plans\\PlanAnglais2012.docx"); | |
file = course.EnglishName | |
.Replace("|", "") | |
.SanitizeForUrl() | |
.Replace("/", "-") + ".docx"; | |
} | |
else | |
{ | |
//Obtenir les suggestions de cours en français | |
var liste = string.Empty; | |
foreach (var courseSuggestion in suggestions) | |
{ | |
liste += "<li>" + HttpUtility.HtmlEncode(courseSuggestion.Course.Name) + "</li>"; | |
} | |
if (!string.IsNullOrEmpty(liste)) | |
{ | |
liste = "<h1 style='margin:0;padding:0;'>Nous vous suggérons également ces formations:</h1><ul>" + liste + "</ul>"; | |
} | |
htmlChunks.Add("PlandeCours", course.Plan + liste); | |
model = Server.MapPath("~\\Plans\\PlanFrancais2012.docx"); | |
file = course.Name | |
.Replace("|", "") | |
.SanitizeForUrl() | |
.Replace("/", "-") + ".docx"; | |
} | |
var fileName = WordML.CreateWordDocument(model, file, bookmarks, bookmarksHeaderFooter, htmlChunks); | |
return File(fileName, "application/docx", System.IO.Path.GetFileName(fileName)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment