public async Task <IActionResult> GetCvTemplate(string id) { try { CVTemplate cv = new CVTemplate(); var cvTemplates = _cvRepository.FilterBy( filter => filter.Name != "").ToList(); foreach (var item in cvTemplates) { if (item.Id.ToString() == id) { cv = item; } } using (var net = new System.Net.WebClient()) { return(new FileContentResult(cv.FileByte, "application/docx") { FileDownloadName = DateTime.Now.ToString() + ".docx" }); } } catch { return(BadRequest()); } }
public async Task <IActionResult> GetCvDocx(CvDocxDTO cvDocxDto) { try { CVTemplate cv = new CVTemplate(); var cvTemplates = _cvRepository.FilterBy( filter => filter.Name != "").ToList(); foreach (var item in cvTemplates) { if (item.Id.ToString() == cvDocxDto.TempId) { cv = item; } } var user = await userManager.FindByIdAsync(cvDocxDto.UserId); DocxCreator docxCreate = new DocxCreator(); if (cv.FileByte != null) { byte[] bytearray = null; using MemoryStream memoryStream = new MemoryStream(0); { memoryStream.Write(cv.FileByte, 0, cv.FileByte.Length); await docxCreate.CreateDocx(memoryStream, user); bytearray = memoryStream.ToArray(); memoryStream.Close(); } using (var net = new System.Net.WebClient()) { return(new FileContentResult(bytearray, "application/docx") { FileDownloadName = DateTime.Now.ToString() + ".docx" }); } } else { return(StatusCode(409, "Cv kunde inte skapas, mall saknas")); } } catch { return(BadRequest()); } }
public async Task <IActionResult> PostCvTemplate(CvUpload cvUpload) { try { CVTemplate cvTemplate = new CVTemplate(); cvTemplate.Name = cvUpload.Name; var splitString = cvUpload.Base64String.Split(","); cvTemplate.FileByte = Convert.FromBase64String(splitString[1]); cvTemplate.Active = true; await _cvRepository.InsertOneAsync(cvTemplate); return(Ok()); } catch { return(BadRequest()); } }