Skip to content

Commit

Permalink
Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-D-Smith committed May 18, 2022
1 parent d749a5c commit 80bb6a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
17 changes: 13 additions & 4 deletions Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ public ActionResult Create(ExplanatoryNote note)
transaction.Commit();
}
}
return base.View("Index", this.getNotes());
}

[HttpGet]
return base.RedirectToAction("Index", this.getNotes());
}

[HttpGet]
public ActionResult Edit(int id = 0)
{
return this.PartialView("~/Views/Home/NoteFields.cshtml", this.getNote(id));
Expand All @@ -78,6 +79,7 @@ public ActionResult Update(int? id, ExplanatoryNote n)
note.FromPosition = n.FromPosition;
note.ToName = n.ToName;
note.ToPosition = n.ToPosition;

using (ITransaction transaction = session.BeginTransaction())
{
session.Save(note);
Expand Down Expand Up @@ -114,6 +116,7 @@ private MemoryStream getTemplate(string path)
Stream templateDocumentReadStream = System.IO.File.OpenRead(path);
BinaryReader templateDocumentBinaryReader = new BinaryReader(templateDocumentReadStream);
byte[] templateDocumentByteArray = templateDocumentBinaryReader.ReadBytes(Convert.ToInt32(templateDocumentReadStream.Length));

MemoryStream templateDocumentStream = new MemoryStream();
templateDocumentStream.Write(templateDocumentByteArray, 0, templateDocumentByteArray.Length);
return templateDocumentStream;
Expand All @@ -132,11 +135,14 @@ public FileResult GetDoc(int id = 0)
string xsltBody = this.getXSLT("document.xslt");
string xml = this.getNote(id).ToXml();
MemoryStream templateDocumentStream = this.getTemplate(Path.Combine(base.Server.MapPath("/Content/"), "template.docx"));

XmlDocument xmlBody = new XmlDocument();
xmlBody.LoadXml(xml);
HomeController.GenerateWordDocument(xmlBody.OuterXml, xsltBody, ref templateDocumentStream);

GenerateWordDocument(xmlBody.OuterXml, xsltBody, ref templateDocumentStream);
byte[] fileContent = templateDocumentStream.ToArray();
templateDocumentStream.Close();

base.Response.Buffer = true;
base.Response.AddHeader("Content-Disposition", "filename=result.docx");
return this.File(fileContent, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "result.docx");
Expand All @@ -146,11 +152,14 @@ private static void GenerateWordDocument(string xmlBody, string xsltBody, ref Me
{
StringWriter sw = new StringWriter();
XmlWriter xw = XmlWriter.Create(sw);

XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(new XmlTextReader(new StringReader(xsltBody)));
transform.Transform(XmlReader.Create(new StringReader(xmlBody)), xw);

XmlDocument wordBody = new XmlDocument();
wordBody.LoadXml(sw.ToString());

using (WordprocessingDocument output = WordprocessingDocument.Open(templateDocumentStream, true))
{
Body updatedBodyContent = new Body(wordBody.DocumentElement.InnerXml);
Expand Down
3 changes: 1 addition & 2 deletions Migrations/AddCreatedField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace AdvanceTest.Migrations
{
[Migration(202205170001)]
[Migration(202205170002)]
public class AddCreatedField : Migration
{
public override void Up()
Expand All @@ -14,7 +14,6 @@ public override void Up()
this.Create.Column("CreatedDate").OnTable("ExplanatoryNote").AsDate();
}
}

public override void Down()
{

Expand Down
2 changes: 1 addition & 1 deletion Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<form class="form-horizontal" asp-controller="Home" asp-action="Create" method="post" enctype="multipart/form-data">
@Html.Partial("/Views/Home/NoteFields.cshtml", new ExplanatoryNote())
<div class="fx-row pr80" style="justify-content:end">
<button type="submit" class="btn base-btn glyphicon glyphicon-edit pr80 b40" style="text-align: end;" formaction="/Home/Create">
<button type="submit" class="btn base-btn glyphicon glyphicon-edit pr80 b40" style="text-align: end;" formmethod="post" formaction="/Home/Create">
<span>Создать</span>
</button>
</div>
Expand Down

0 comments on commit 80bb6a1

Please sign in to comment.