From 04cca012f4aaef7ef9127761376bb97afc8999e1 Mon Sep 17 00:00:00 2001 From: ivanszabo Date: Thu, 27 Mar 2025 11:13:42 +0100 Subject: [PATCH] WORD -> PDF --- .../Controllers/UserController.cs | 22 + .../DocumentGenerator/DokumentumGenerator.cs | 108 ++++ .../DocumentGenerator/SablonGenerator.cs | 499 ++++++++++++++++++ .../Mappings/MapperProfile.cs | 5 + .../Services/CheckListService.cs | 15 +- .../Services/Interfaces/ICheckListService.cs | 1 + .../Services/Interfaces/IUserService.cs | 2 +- src/WorkFlowCheck.BL/Services/UserService.cs | 1 + src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj | 2 + .../DTO/RoleCheckListTemplateHeaderDTO.cs | 19 + .../CheckListHeaderEditPage.cshtml | 2 +- .../Pages/Shared/_Layout.cshtml | 1 + .../RoleCheckListTemplateHeadersPage.cshtml | 98 +++- ...RoleCheckListTemplateHeadersPage.cshtml.cs | 17 +- .../Services/Interfaces/IUserService.cs | 2 +- src/WorkFlowCheck.Web/Services/UserService.cs | 21 + 16 files changed, 808 insertions(+), 7 deletions(-) create mode 100644 src/WorkFlowCheck.BL/DocumentGenerator/DokumentumGenerator.cs create mode 100644 src/WorkFlowCheck.BL/DocumentGenerator/SablonGenerator.cs create mode 100644 src/WorkFlowCheck.Common/DTO/RoleCheckListTemplateHeaderDTO.cs diff --git a/src/WorkFlowCheck.API/Controllers/UserController.cs b/src/WorkFlowCheck.API/Controllers/UserController.cs index 963894f..8ce2aa6 100644 --- a/src/WorkFlowCheck.API/Controllers/UserController.cs +++ b/src/WorkFlowCheck.API/Controllers/UserController.cs @@ -292,5 +292,27 @@ namespace WorkFlowCheck.API.Controllers } + [HttpGet("GetAllRoleCheckListTemplateHeaders")] + public async Task>> GetAllRoleCheckListTemplateHeaders() + { + var retVal = new ApiResponseDTO>() + { + IsSuccess = true, + }; + var results = await _userService.GetAllRoleCheckListTemplateHeadersAsync(); + + if (results != null) + { + retVal.IsSuccess = true; + retVal.Data = results; + } + else + { + retVal.IsSuccess = false; + retVal.Errors.Add("No data!"); + } + + return retVal; + } } } diff --git a/src/WorkFlowCheck.BL/DocumentGenerator/DokumentumGenerator.cs b/src/WorkFlowCheck.BL/DocumentGenerator/DokumentumGenerator.cs new file mode 100644 index 0000000..c0622b0 --- /dev/null +++ b/src/WorkFlowCheck.BL/DocumentGenerator/DokumentumGenerator.cs @@ -0,0 +1,108 @@ +using Aspose.Words; +using Aspose.Words.Tables; +using Serilog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WorkFlowCheck.BL.DocumentGenerator +{ + public class DokumentumGenerator + { + static DokumentumGenerator() + { + Aspose.Words.License license = new Aspose.Words.License(); + + try + { + license.SetLicense("Aspose.Words.lic"); + Log.Information("License set successfully."); + } + catch (Exception e) + { + Log.Error(e, "\nThere was an error setting the license: " + e.Message); + } + } + + public static byte[] HtmlToDocx(string html) + { + byte[] generated = Encoding.UTF8.GetBytes(html); + var docHTML = new Aspose.Words.Document(); + + Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(docHTML); + builder.InsertHtml(html); + + docHTML.CompatibilityOptions.OptimizeFor(Aspose.Words.Settings.MsWordVersion.Word2016); + + MemoryStream outStream = new MemoryStream(); + docHTML.Save(outStream, Aspose.Words.SaveFormat.Docx); + + generated = outStream.ToArray(); + + outStream.Dispose(); + + return generated; + } + + public static byte[] HtmlToPdf(string html) + { + byte[] generated = Encoding.UTF8.GetBytes(html); + + Stream inStream = new MemoryStream(generated); + var docHTML = new Aspose.Words.Document(inStream); + MemoryStream outStream = new MemoryStream(); + docHTML.Save(outStream, Aspose.Words.SaveFormat.Pdf); + + generated = outStream.ToArray(); + + inStream.Dispose(); + outStream.Dispose(); + + return generated; + } + + public static byte[] DocxToPdf(byte[] generated) + { + Stream inStream = new MemoryStream(generated); + var doc = new Aspose.Words.Document(inStream); + MemoryStream outStream = new MemoryStream(); + doc.Save(outStream, Aspose.Words.SaveFormat.Pdf); + + generated = outStream.ToArray(); + + inStream.Dispose(); + outStream.Dispose(); + + return generated; + } + + public static byte[] DocxToPdfForTopic(byte[] generated) + { + Stream inStream = new MemoryStream(generated); + var doc = new Aspose.Words.Document(inStream); + + doc.Styles.DefaultFont.Name = "Times New Roman"; + doc.Styles.DefaultFont.Size = 12; + + var collection = doc.GetChildNodes(NodeType.Row, true); + + foreach (Row row in collection) + { + row.RowFormat.Height = 40; + row.RowFormat.HeightRule = HeightRule.AtLeast; + } + + MemoryStream outStream = new MemoryStream(); + doc.Save(outStream, Aspose.Words.SaveFormat.Pdf); + + generated = outStream.ToArray(); + + inStream.Dispose(); + outStream.Dispose(); + + return generated; + } + } +} diff --git a/src/WorkFlowCheck.BL/DocumentGenerator/SablonGenerator.cs b/src/WorkFlowCheck.BL/DocumentGenerator/SablonGenerator.cs new file mode 100644 index 0000000..25b339f --- /dev/null +++ b/src/WorkFlowCheck.BL/DocumentGenerator/SablonGenerator.cs @@ -0,0 +1,499 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using System.Text.RegularExpressions; + +namespace WorkFlowCheck.BL.DocumentGenerator +{ + public class SablonGenerator : IDisposable + { + private readonly List _currentRoot; + + private MemoryStream Mem { get; } + private WordprocessingDocument Doc { get; set; } + + private List CurrentRoot => Repeater?.SablonRoot ?? _currentRoot; + + private SubSablon Repeater { get; set; } + + protected class SubSablon : IDisposable + { + private List SablonRootBase { get; set; } + protected internal List SablonRoot { get; private set; } + public BookmarkStart BookmarkStart { get; } + public BookmarkEnd BookmarkEnd { get; } + + protected internal SubSablon(WordprocessingDocument doc, string key) + { + var bookmark = doc.MainDocumentPart.RootElement.Descendants() + .FirstOrDefault(x => x.Name == key); + //var parentBookmark = false; + if (bookmark != null) + { + SablonRoot = new List(); + var nextSibling = bookmark.NextSibling(); + if (nextSibling == null) + nextSibling = bookmark.Parent; + while (nextSibling != null) + { + var endBookmark = (nextSibling is BookmarkEnd end && end.Id == bookmark.Id.Value) ? end : null; + if (endBookmark == null) + { + endBookmark = nextSibling.Descendants().FirstOrDefault(x => x.Id == bookmark.Id.Value); + if (endBookmark != null) + SablonRoot.Add(nextSibling); + } + if (endBookmark != null) + { + bookmark.Remove(); + endBookmark.Remove(); + break; + } + SablonRoot.Add(nextSibling); + var tmpNextSibling = nextSibling.NextSibling(); + if (tmpNextSibling == null) + { + tmpNextSibling = nextSibling.Parent; + if (tmpNextSibling != null && !(tmpNextSibling is Body) && !(tmpNextSibling is Document)) + SablonRoot.Clear(); + else + break; + } + nextSibling = tmpNextSibling; + } + } + + if (SablonRoot != null && SablonRoot.Count > 0) + { + SablonRootBase = new List(); + foreach (var item in SablonRoot) + { + SablonRootBase.Add(item.CloneNode(true)); + } + BookmarkStart = new BookmarkStart() { Name = "repeater", Id = "1000" }; + BookmarkEnd = new BookmarkEnd() { Id = "1000" }; + if (SablonRoot.First().Parent != null) + { + SablonRoot.First().InsertBeforeSelf(BookmarkStart); + SablonRoot.First().InsertBeforeSelf(BookmarkEnd); + foreach (var rootItem in SablonRoot) + rootItem.Remove(); + } + else + { + foreach (var rootItem in SablonRoot) + foreach (var rootItemChildElement in rootItem.ChildElements) + rootItemChildElement.Remove(); + SablonRoot.First().AppendChild(BookmarkStart); + SablonRoot.First().AppendChild(BookmarkEnd); + } + Reset(); + } + } + + private void Insert() + { + var root = SablonRoot; + if (root.Count == 1 && root.First() is Document) + { + root = root.First().ChildElements.ToList(); + } + for (var i = 0; i < root.Count; i++) + { + if (i == 0) + BookmarkStart.InsertBeforeSelf(root[i]); + else + root[i - 1].InsertAfterSelf(root[i]); + } + } + + private void Reset() + { + SablonRoot.Clear(); + foreach (var item in SablonRootBase) + { + SablonRoot.Add(item.CloneNode(true)); + } + } + + protected internal void InsertAndReset() + { + Insert(); + Reset(); + } + + public void Dispose() + { + BookmarkStart?.Remove(); + BookmarkEnd?.Remove(); + SablonRootBase = null; + SablonRoot = null; + } + } + + public IDisposable Repeat(string key) + { + Repeater = new SubSablon(Doc, key); + return Repeater; + } + + public SablonGenerator(byte[] content) + { + Mem = new MemoryStream(); + Mem.Write(content, 0, content.Length); + try + { + Doc = WordprocessingDocument.Open(Mem, true, new OpenSettings() + { + MarkupCompatibilityProcessSettings = + new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts, + FileFormatVersions.Office2010) + }); + } + catch (Exception) + { + //if (!string.IsNullOrEmpty(Config.TryGetStringValue("SablonGeneratorErrorPath"))) + //{ + // File.WriteAllBytes(Path.Combine(Config.GetStringValue("SablonGeneratorErrorPath"), DateTime.Now.ToString("yyyyMMddHHHmmss.content")), content); + //} + throw; + } + + _currentRoot = new List(); + CurrentRoot.AddRange(Doc.MainDocumentPart.HeaderParts.Select(x => x.RootElement)); + CurrentRoot.Add(Doc.MainDocumentPart.RootElement); + CurrentRoot.AddRange(Doc.MainDocumentPart.FooterParts.Select(x => x.RootElement)); + } + + public static void CheckOpenXmlDocument(byte[] content) + { + WordprocessingDocument doc = null; + var mem = new MemoryStream(); + mem.Write(content, 0, content.Length); + try + { + doc = WordprocessingDocument.Open(mem, true, new OpenSettings() + { + MarkupCompatibilityProcessSettings = + new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts, + FileFormatVersions.Office2010) + }); + } + catch (Exception ex) + { +#if DEBUG + //LoggerHelper.DiagnosticAudit.Information(DateTime.Now, + //Common.Enums.Area.BaseSystem, + //0, + //string.Format(ex.ToString()), + //new Guid().ToString()); + //LoggerHelper.DiagnosticAudit.Log.Information(ex.ToString()); +#else + //LoggerHelper.DiagnosticAudit.Information(DateTime.Now, + //Common.Enums.Area.BaseSystem, + //0, + //string.Format(ex.Message), + //Guid.Empty.ToString()); +#endif + //throw new BusinessException("Hibás vagy nem megfelelő OpenXML állomány."); + } + finally + { + mem?.Dispose(); + doc?.Dispose(); + } + } + + public void Generate(Dictionary propertyDictionary) + { + ReplaceBookmarks(propertyDictionary); + if (Repeater?.SablonRoot != null) Repeater.InsertAndReset(); + } + + public void SimpleReplace(string key, string value) + { + value = value == null ? "" : value; + + foreach (var headerPart in Doc.MainDocumentPart.HeaderParts) + SimpleReplace2(headerPart.Header, key, value); + SimpleReplace2(Doc.MainDocumentPart.Document.Body, key, value); + } + + protected void SimpleReplace(OpenXmlCompositeElement target, string key, string value) + { + var keyValue = key.Replace("#", ""); + var texts = target.Descendants(); + Text start = null; + Text keyValueText = null; + foreach (var text in texts) + if (text.Text == "#" && start == null) + start = text; + else if (text.Text == "#" && start != null && keyValueText != null) + { + var end = text; + keyValueText.Text = value; + start.Remove(); + end.Remove(); + start = null; + keyValueText = null; + } + else if (start != null && text.Text.ToUpper().Contains(keyValue.ToUpper())) + keyValueText = text; + else if (text.Text.ToUpper().Contains(key.ToUpper())) + { + start = null; + keyValueText = null; + text.Text = Regex.Replace(text.Text, key, value, RegexOptions.IgnoreCase); + } + else + { + start = null; + keyValueText = null; + } + } + + protected void SimpleReplace2(OpenXmlCompositeElement target, string key, string value) + { + var texts = target.Descendants(); + Text start = null; + var tokens = new List(); + string tokenText = ""; + + foreach (var text in texts) + { + if (text.Text == "#" && start == null) + { + start = text; + tokenText += text.Text; + } + else if (text.Text == "#" && start != null) + { + var end = text; + tokenText += text.Text; + + if (tokenText.ToUpper() == key.ToUpper()) + { + start.Text = value; + foreach (var token in tokens) + { + token.Remove(); + } + tokens.Clear(); + end.Remove(); + start = null; + tokenText = ""; + } + else + { + start = null; + tokens.Clear(); + tokenText = ""; + end = null; + } + } + else if (text.Text.Contains('#') && text.Text.ToUpper() == key.ToUpper()) + { + text.Text = value; + } + else if (text.Text.Contains('#')) + { + + } + else if (start != null) + { + tokens.Add(text); + tokenText += text.Text; + } + } + } + + public void SimpleReplaceForCV(string key, string value) + { + value = value == null ? "" : value; + + SimpleReplaceForCV(Doc.MainDocumentPart.Document.Body, key, value); + } + + protected void SimpleReplaceForCV(OpenXmlCompositeElement target, string key, string value) + { + var keyValue = key.Replace("#", ""); + var texts = target.Descendants(); + Text start = null; + Text keyValueText = null; + var keyindox = ""; + foreach (var text in texts) + { + if (text.Text.Contains(key)) + { + text.Text = text.Text.Replace(key, value); + break; + } + + if (text.Text.Contains(keyValue + "#") && start != null) + { + start.Text = ""; + text.Text = text.Text.Replace(keyValue + "#", value); + break; + } + + if ((text.Text == "#" || (text.Text.Contains("#") && text.Text.Count(x => x == '#') == 1)) && start == null) + { + start = text; + keyindox = start.Text; + } + else if (start != null && (text.Text == "#" || text.Text.Contains("#"))) + { + for (int i = texts.ToList().IndexOf(start) + 1; i < texts.ToList().IndexOf(text) + 1; i++) + { + if (texts.ToList()[i].Text.Contains(key)) + { + texts.ToList()[i].Text = texts.ToList()[i].Text.Replace(key, value); + break; + } + + keyindox = keyindox + texts.ToList()[i].Text; + } + keyindox = keyindox.Replace("#", ""); + if (keyindox == keyValue || keyindox.Replace(" ", "") == keyValue) + { + for (int i = texts.ToList().IndexOf(start) + 1; i < texts.ToList().IndexOf(text); i++) + { + texts.ToList()[i].Text = ""; + } + start.Text = ""; + text.Text = value; + } + if (keyindox.Contains(keyValue)) + { + for (int i = texts.ToList().IndexOf(start) + 1; i < texts.ToList().IndexOf(text); i++) + { + texts.ToList()[i].Text = ""; + } + start.Text = ""; + text.Text = keyindox.Replace(keyValue, value); + } + start = null; + keyindox = ""; + } + } + + } + + private void ReplaceBookmarks(Dictionary propertyDictionary) + { + var bookmarkEndList = new List(); + foreach (var item in CurrentRoot) + { + var bookmarkEnds = item.Descendants(); + bookmarkEndList.AddRange(bookmarkEnds.ToList()); + } + + foreach (var docContent in CurrentRoot) + { + var bookmarkStarts = docContent.Descendants(); + + var bookmarkStartList = bookmarkStarts.ToList(); + if (docContent is BookmarkStart) + bookmarkStartList.Add(docContent as BookmarkStart); + + for (int k = 0; k < bookmarkStartList.Count; k++) + { + Run bookmarkRun = bookmarkStartList[k].NextSibling(); + if (bookmarkRun != null) + { + var bookmarkText = bookmarkRun.GetFirstChild().InnerText; + if (propertyDictionary.ContainsKey(bookmarkText)) + { + var itemValue = propertyDictionary[bookmarkText]; + + bookmarkRun.GetFirstChild().Text = itemValue ?? string.Empty; + var id = bookmarkStartList[k].Id.Value; + bookmarkStartList[k].Remove(); + var end = bookmarkEndList.Find(x => x.Id == id); + end.Remove(); + } + } + } + } + } + + /// + /// Táblázat generálás (a keyinrow paramétert keresi a táblázat első sorában (nem fejléc), ezt a sort kitörli, és helyére szúrja be az új sorokat + /// amit az első paraméterben kap meg + /// + /// sorok és benne az egyes cellák tartalma + /// első (nem fejléc) sorában lévő kulcs, ez alapján azonosítjuk be a táblázatot + /// ha igaz, a táblázat összes meglévő sorát törli + public void SetTable(List> rowsAndCells, string keyInRow, bool deleteEmptyRow = false) + { + Body bod = Doc.MainDocumentPart.Document.Body; + var table = bod.Descendants().Where(tbl => tbl.InnerText.Contains(keyInRow)).FirstOrDefault(); + if (table != null) + { + if (deleteEmptyRow) + { + var firstRow = table.ChildElements.Where(x => x is TableRow).FirstOrDefault(); + var deletedRows = table.ChildElements.Where(x => x is TableRow).ToList(); + deletedRows.Remove(firstRow); + foreach (var item in deletedRows) + table.RemoveChild(item); + } + else + { + var deletedRow = table.ChildElements.Where(x => x is TableRow).LastOrDefault(); + table.RemoveChild(deletedRow as TableRow); + } + + foreach (var row in rowsAndCells) + { + List cells = new List(); + + foreach (var cell in row) + { + var tableCell = new TableCell(new Paragraph(new Run(new Text(cell)))); + cells.Add(tableCell); + } + + table.Append(new TableRow(cells)); + } + } + } + + public byte[] CloseAndGetDocument() + { + Doc.Dispose(); + Doc = null; + return Mem.ToArray(); + } + + public void Dispose() + { + Doc?.Dispose(); + Mem.Dispose(); + } + + /// + /// Hozzáfűzi a már megnyitott fájlhoz a paraméterként kapott dokumentum tartalmát. + /// + /// + /// + public void AppendDocument(byte[] document, bool addPageBreak = true) + { + var mainPart = Doc.MainDocumentPart; + string altChunkId = "AltChunk_" + Guid.NewGuid().ToString().Replace("-", ""); + + var chunk = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML, altChunkId); + chunk.FeedData(new MemoryStream(document)); + + // oldaltörés, ha kell + if (addPageBreak) + { + mainPart.Document.Body.AppendChild(new Paragraph(new Run(new Break() { Type = BreakValues.Page }))); + } + + mainPart.Document.Body.AppendChild(new AltChunk() { Id = altChunkId }); + + mainPart.Document.Save(); + } + } +} diff --git a/src/WorkFlowCheck.BL/Mappings/MapperProfile.cs b/src/WorkFlowCheck.BL/Mappings/MapperProfile.cs index 5cf6e04..adab2fd 100644 --- a/src/WorkFlowCheck.BL/Mappings/MapperProfile.cs +++ b/src/WorkFlowCheck.BL/Mappings/MapperProfile.cs @@ -49,6 +49,11 @@ namespace WorkFlowCheck.BL.Mappings CreateMap() .ForMember(dest => dest.CheckListTemplateRowDTO, opt => opt.MapFrom(src => src.CheckListTemplateRow)); + + + CreateMap() + .ForMember(dest => dest.RoleDTO, opt => opt.MapFrom(src => src.Role)) + .ForMember(dest => dest.CheckListTemplateHeaderDTO, opt => opt.MapFrom(src => src.CheckListTemplateHeader)); } } } diff --git a/src/WorkFlowCheck.BL/Services/CheckListService.cs b/src/WorkFlowCheck.BL/Services/CheckListService.cs index 51ddbf8..cc5eb6d 100644 --- a/src/WorkFlowCheck.BL/Services/CheckListService.cs +++ b/src/WorkFlowCheck.BL/Services/CheckListService.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using WorkFlowCheck.BL.DocumentGenerator; using WorkFlowCheck.BL.Services.Interfaces; using WorkFlowCheck.Common.DTO; using WorkFlowCheck.DL; @@ -51,7 +52,7 @@ namespace WorkFlowCheck.BL.Services .OrderBy(r => r.CheckListTemplateRow.CheckPoint?.ShortName ?? string.Empty) .ThenBy(r => r.CheckListTemplateRow.RowIndex) .ToList(); - + } if (res != null) @@ -361,5 +362,17 @@ namespace WorkFlowCheck.BL.Services return retVal; } + + public byte[] CreatePDF(int checkListHeaderId) + { + var location = System.Reflection.Assembly.GetEntryAssembly().Location; + var directory = System.IO.Path.GetDirectoryName(location); + byte[] byteArray = System.IO.File.ReadAllBytes(Path.Combine(directory, "DocumentGenerator", "CheckList_Template_V1.docx")); + SablonGenerator gen = new SablonGenerator(byteArray); + + byte[] content = gen.CloseAndGetDocument(); + + return DokumentumGenerator.DocxToPdf(content); + } } } diff --git a/src/WorkFlowCheck.BL/Services/Interfaces/ICheckListService.cs b/src/WorkFlowCheck.BL/Services/Interfaces/ICheckListService.cs index a924e95..3e1c3b0 100644 --- a/src/WorkFlowCheck.BL/Services/Interfaces/ICheckListService.cs +++ b/src/WorkFlowCheck.BL/Services/Interfaces/ICheckListService.cs @@ -23,5 +23,6 @@ namespace WorkFlowCheck.BL.Services.Interfaces Task GetCheckListTemplateRowAsync(int id); Task UpdateCheckListTemplateRowAsync(CheckListTemplateRowDTO checkListTemplateRowDTO); + byte[] CreatePDF(int checkListHeaderId); } } diff --git a/src/WorkFlowCheck.BL/Services/Interfaces/IUserService.cs b/src/WorkFlowCheck.BL/Services/Interfaces/IUserService.cs index 3bc59e1..ec8eab5 100644 --- a/src/WorkFlowCheck.BL/Services/Interfaces/IUserService.cs +++ b/src/WorkFlowCheck.BL/Services/Interfaces/IUserService.cs @@ -22,7 +22,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces Task> GetAllUserRoleAsync(); Task UpdateUserRoleAsync(UserRoleDTO userRoleDTO); - + Task> GetAllRoleCheckListTemplateHeadersAsync(); string GenerateJwtToken(UserDTO userDTO); } diff --git a/src/WorkFlowCheck.BL/Services/UserService.cs b/src/WorkFlowCheck.BL/Services/UserService.cs index 7bc7101..f0d3c7d 100644 --- a/src/WorkFlowCheck.BL/Services/UserService.cs +++ b/src/WorkFlowCheck.BL/Services/UserService.cs @@ -340,5 +340,6 @@ namespace WorkFlowCheck.BL.Services return retVal; } + public Task> GetAllRoleCheckListTemplateHeadersAsync() => throw new NotImplementedException(); } } diff --git a/src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj b/src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj index bb7420c..bd3f6b2 100644 --- a/src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj +++ b/src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj @@ -7,7 +7,9 @@ + + diff --git a/src/WorkFlowCheck.Common/DTO/RoleCheckListTemplateHeaderDTO.cs b/src/WorkFlowCheck.Common/DTO/RoleCheckListTemplateHeaderDTO.cs new file mode 100644 index 0000000..3437936 --- /dev/null +++ b/src/WorkFlowCheck.Common/DTO/RoleCheckListTemplateHeaderDTO.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WorkFlowCheck.Common.DTO +{ + public class RoleCheckListTemplateHeaderDTO + { + public int Id { get; set; } + public int RoleId { get; set; } + public RoleDTO RoleDTO { get; set; } = null!; + public int CheckListTemplateHeaderId { get; set; } + public CheckListTemplateHeaderDTO CheckListTemplateHeaderDTO { get; set; } = null!; + public bool Enabled { get; set; } = false; + } +} diff --git a/src/WorkFlowCheck.Web/Pages/CheckList/CheckListHeader/CheckListHeaderEditPage.cshtml b/src/WorkFlowCheck.Web/Pages/CheckList/CheckListHeader/CheckListHeaderEditPage.cshtml index ba9aef3..4905d7b 100644 --- a/src/WorkFlowCheck.Web/Pages/CheckList/CheckListHeader/CheckListHeaderEditPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/CheckList/CheckListHeader/CheckListHeaderEditPage.cshtml @@ -15,7 +15,7 @@
-
+
+ + + + + + + + + + + + + + + + + + + + +
IDFirst NameLast NameRoleCheckListTemplateHeaders NameE-mailAction
IDFirst NameLast NameRoleCheckListTemplateHeaders NameE-mailAction
+ + +@section Scripts { + } diff --git a/src/WorkFlowCheck.Web/Pages/UserAndRole/RoleCheckListTemplateHeadersPage.cshtml.cs b/src/WorkFlowCheck.Web/Pages/UserAndRole/RoleCheckListTemplateHeadersPage.cshtml.cs index 62ddc62..298f34b 100644 --- a/src/WorkFlowCheck.Web/Pages/UserAndRole/RoleCheckListTemplateHeadersPage.cshtml.cs +++ b/src/WorkFlowCheck.Web/Pages/UserAndRole/RoleCheckListTemplateHeadersPage.cshtml.cs @@ -1,12 +1,25 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using WorkFlowCheck.Web.Services.Interfaces; namespace WorkFlowCheck.Web.Pages.UserAndRole { - public class RoleCheckListTemplateHeadersPageModel : PageModel + public class RoleCheckListTemplatesPageModel : PageModel { - public void OnGet() + private readonly ILogger _logger; + private readonly IUserService _userService; + public RoleCheckListTemplatesPageModel(ILogger logger, IUserService userService) { + _logger = logger; + _userService = userService; + } + public async Task OnGet() + { + } + public async Task OnGetLoadRoleCheckListTemplates() + { + var results = await _userService.getall(); + return new JsonResult(new { data = results }); } } } diff --git a/src/WorkFlowCheck.Web/Services/Interfaces/IUserService.cs b/src/WorkFlowCheck.Web/Services/Interfaces/IUserService.cs index 8a5bec6..3ab539c 100644 --- a/src/WorkFlowCheck.Web/Services/Interfaces/IUserService.cs +++ b/src/WorkFlowCheck.Web/Services/Interfaces/IUserService.cs @@ -17,6 +17,6 @@ namespace WorkFlowCheck.Web.Services.Interfaces Task> GetAllUserRoles(); Task> UpdateUserRole(UserRoleDTO userRoleDTO); - + Task> GetAllRoleCheckListTemplates(); } } diff --git a/src/WorkFlowCheck.Web/Services/UserService.cs b/src/WorkFlowCheck.Web/Services/UserService.cs index ff54fcd..b6c59de 100644 --- a/src/WorkFlowCheck.Web/Services/UserService.cs +++ b/src/WorkFlowCheck.Web/Services/UserService.cs @@ -265,5 +265,26 @@ namespace WorkFlowCheck.Web.Services } } + public async Task> GetAllRoleCheckListTemplates() + { + string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllRoleCheckListTemplateHeaders"; + var retVal = new List(); + try + { + var response = await _httpClient.GetFromJsonAsync>>(endpoint); + if (response != null) + { + if (response.IsSuccess) + { + return response.Data; + } + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + return retVal; + } } }