public string Post([FromBody] ClientInfo client) { DataValid dv = new DataValid(); if (!dv.IsValidDatas(client.LastName, client.FirstName, client.MiddleName, client.BirthDate, client.LoanSum)) { return("Проверьте правильность введённых данных"); } DateTime currentDate = DateTime.Now; string pathTemplate = templatesList[client.TemplateNum]; string pathOutputFolder = foldersList[client.FolderNum]; if (!Directory.Exists(pathOutputFolder)) { return("Папка не найдена, обратитесь к администратору или выберите другую"); } string templateName = templatesList[client.TemplateNum].Remove(0, templatesList[client.TemplateNum].LastIndexOf("\\")); templateName = templateName.Remove(templateName.IndexOf(".")); string newFileName = templateName + " " + client.FirstName + " " + client.LastName + " от " + currentDate.ToLongDateString().Replace(".", "") + ".docx"; string pathNewFile = pathOutputFolder + newFileName; Replacer repl = new Replacer(); return(repl.NewDoc(pathTemplate, pathNewFile, client.LastName, client.FirstName, client.MiddleName, client.BirthDate, client.LoanSum, client.Image)); }
public Object Create(ClientInfo client, string submit) { Random rnd = new Random(); if (ModelState.IsValid) { string imageName = Path.GetFileName(client.Image.FileName); try { client.Image.SaveAs(Server.MapPath("~/Resources/Images/" + imageName)); } catch { imageName = imageName.Replace(".", rnd.Next(0, 10).ToString() + "."); client.Image.SaveAs(Server.MapPath("~/Resources/Images/" + imageName)); } DateTime currentDate = DateTime.Now; string pathTemplate = AppDomain.CurrentDomain.BaseDirectory + "Resources\\" + client.TemplateName; string pathOutputFolder = AppDomain.CurrentDomain.BaseDirectory + "Documents\\"; string templateName = client.TemplateName.Remove(client.TemplateName.IndexOf(".")); string newFileName = templateName + " " + client.FirstName + " " + client.LastName + " от " + currentDate.ToLongDateString().Replace(".", "") + ".docx"; string pathNewFile = pathOutputFolder + newFileName; Replacer repl = new Replacer(); string pathDoc = repl.NewDoc(pathTemplate, pathNewFile, client.LastName, client.FirstName, client.MiddleName, client.BirthDate.ToString(), client.LoanSum, imageName); string nameDoc = pathDoc.Substring(pathDoc.LastIndexOf('\\') + 1); Converter conv = new Converter(); string pathPdf = conv.ConvertFile(pathDoc); string namePdf = pathPdf.Substring(pathPdf.LastIndexOf('\\') + 1); switch (submit) { case "Скачать": return(File(pathDoc, "application/docx", nameDoc)); case "Распечатать": return(File(pathPdf.Replace(".pdf", "_.pdf"), "application/pdf", namePdf)); } } return("Проверьте правильность введённых данных"); }