|
|
@@ -642,5 +642,227 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
+
|
|
|
+ #region HelpPages
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Basic helpPage view function
|
|
|
+ /// </summary>
|
|
|
+ [FunctionAuthorize(true, "Misc-HelpPages")]
|
|
|
+ public ActionResult ViewHelpPages()
|
|
|
+ {
|
|
|
+ var helpPages = _miscService.GetAllHelpPages();
|
|
|
+ var helpPageModels = helpPages
|
|
|
+ .Select(u => HelpPageDataModel.FromHelpPage(u, false))
|
|
|
+ .ToList();
|
|
|
+ var helpPageTreeModelList = new List<HelpPageTreeModel>();
|
|
|
+
|
|
|
+ var categoryPageModels = helpPageModels
|
|
|
+ .Where(p => String.IsNullOrEmpty(p.Category))
|
|
|
+ .OrderBy(p => p.DisplayIndex)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ foreach (var categoryPageModel in categoryPageModels)
|
|
|
+ {
|
|
|
+ helpPageTreeModelList.Add(new HelpPageTreeModel
|
|
|
+ {
|
|
|
+ Text = categoryPageModel.Title,
|
|
|
+ HelpPageId = categoryPageModel.Id
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ var categoryModels = helpPageModels
|
|
|
+ .Where(p => !String.IsNullOrEmpty(p.Category))
|
|
|
+ .OrderBy(p => p.DisplayIndex)
|
|
|
+ .GroupBy(p => p.Category)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ foreach (var categoryModel in categoryModels)
|
|
|
+ {
|
|
|
+ var categoryTreeModel = new HelpPageTreeModel
|
|
|
+ {
|
|
|
+ Text = categoryModel.Key
|
|
|
+ };
|
|
|
+
|
|
|
+ helpPageTreeModelList.Add(categoryTreeModel);
|
|
|
+
|
|
|
+ var subcategoryPageModels = helpPageModels
|
|
|
+ .Where(p => p.Category == categoryModel.Key && String.IsNullOrEmpty(p.Subcategory))
|
|
|
+ .OrderBy(p => p.DisplayIndex)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ foreach (var subcategoryPageModel in subcategoryPageModels)
|
|
|
+ {
|
|
|
+ var subcategoryTreePageModel = new HelpPageTreeModel
|
|
|
+ {
|
|
|
+ Text = subcategoryPageModel.Title,
|
|
|
+ HelpPageId = subcategoryPageModel.Id
|
|
|
+ };
|
|
|
+
|
|
|
+ categoryTreeModel.Elements.Add(subcategoryTreePageModel);
|
|
|
+ }
|
|
|
+
|
|
|
+ var subcategoryModels = helpPageModels
|
|
|
+ .Where(p => p.Category == categoryModel.Key && !String.IsNullOrEmpty(p.Subcategory))
|
|
|
+ .OrderBy(p => p.DisplayIndex)
|
|
|
+ .GroupBy(p => p.Subcategory)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ foreach (var subcategoryModel in subcategoryModels)
|
|
|
+ {
|
|
|
+ var subcategoryTreeModel = new HelpPageTreeModel
|
|
|
+ {
|
|
|
+ Text = subcategoryModel.Key
|
|
|
+ };
|
|
|
+
|
|
|
+ categoryTreeModel.Elements.Add(subcategoryTreeModel);
|
|
|
+
|
|
|
+ var subcategoryHelpPageModels = helpPageModels
|
|
|
+ .Where(p => p.Category == categoryModel.Key && p.Subcategory == subcategoryModel.Key)
|
|
|
+ .OrderBy(p => p.DisplayIndex)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ foreach (var subcategoryHelpPageModel in subcategoryHelpPageModels)
|
|
|
+ {
|
|
|
+ var helpPageTreeModel = new HelpPageTreeModel
|
|
|
+ {
|
|
|
+ Text = subcategoryHelpPageModel.Title,
|
|
|
+ HelpPageId = subcategoryHelpPageModel.Id
|
|
|
+ };
|
|
|
+
|
|
|
+ subcategoryTreeModel.Elements.Add(helpPageTreeModel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return View("~/Views/Misc/HelpPages.cshtml", helpPageTreeModelList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Get JSON data of specific helpPage
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id">HelpPage id.</param>
|
|
|
+ public ActionResult GetHelpPage(int id = -1)
|
|
|
+ {
|
|
|
+ var helpPage = _miscService.GetHelpPageById(id);
|
|
|
+ if (helpPage == null)
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = "notFound",
|
|
|
+ JsonRequestBehavior = JsonRequestBehavior.AllowGet
|
|
|
+ };
|
|
|
+
|
|
|
+ var helpPageModel = HelpPageDataModel.FromHelpPage(helpPage, false);
|
|
|
+
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = JsonConvert.SerializeObject(helpPageModel),
|
|
|
+ JsonRequestBehavior = JsonRequestBehavior.AllowGet
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Partial edit for editing of existing or for new helpPage
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id">Id for existing helpPage, otherweise -1.</param>
|
|
|
+ public ActionResult ViewHelpPage(int id = -1)
|
|
|
+ {
|
|
|
+ var helpPage = _miscService.GetHelpPageById(id);
|
|
|
+ var helpPageModel = HelpPageDataModel.FromHelpPage(helpPage, true);
|
|
|
+
|
|
|
+ if (helpPage != null)
|
|
|
+ return PartialView("~/Views/Misc/_HelpPageViewPartial.cshtml", helpPageModel);
|
|
|
+
|
|
|
+ return new EmptyResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Partial edit for editing of existing or for new helpPage
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id">Id for existing helpPage, otherweise -1.</param>
|
|
|
+ public ActionResult EditHelpPage(int id = -1)
|
|
|
+ {
|
|
|
+ var helpPage = _miscService.GetHelpPageById(id);
|
|
|
+ var helpPageModel = HelpPageDataModel.FromHelpPage(helpPage, true);
|
|
|
+
|
|
|
+ return PartialView("~/Views/Misc/_HelpPageEditPartial.cshtml", helpPageModel);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="helpPageModel">HelpPage model to be saved.</param>
|
|
|
+ [HttpPost, ValidateInput(false)]
|
|
|
+ public ActionResult EditHelpPage(HelpPageDataModel helpPageModel)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!ModelState.IsValid)
|
|
|
+ return PartialView("~/Views/Misc/_HelpPageEditPartial.cshtml", helpPageModel);
|
|
|
+
|
|
|
+ if (helpPageModel.Id == -1)
|
|
|
+ {
|
|
|
+ var helpPage = helpPageModel.ToHelpPage();
|
|
|
+
|
|
|
+ _miscService.InsertHelpPage(helpPage);
|
|
|
+
|
|
|
+ _logger.Entity(helpPage, Core.Domain.Logging.LogEntityActivity.Insert, _userHelper.FromCookies());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var helpPage = _miscService.GetHelpPageById(helpPageModel.Id);
|
|
|
+
|
|
|
+ helpPage.Title = helpPageModel.Title;
|
|
|
+ helpPage.Content = helpPageModel.Content;
|
|
|
+ helpPage.Category = helpPage.Category;
|
|
|
+ helpPage.Subcategory = helpPage.Subcategory;
|
|
|
+ helpPage.DisplayIndex = helpPage.DisplayIndex;
|
|
|
+
|
|
|
+ _miscService.UpdateHelpPage(helpPage);
|
|
|
+
|
|
|
+ _logger.Entity(helpPage, Core.Domain.Logging.LogEntityActivity.Update, _userHelper.FromCookies());
|
|
|
+ }
|
|
|
+
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = "success"
|
|
|
+ };
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.Error("Fehler bei Speicherung einer Hilfe-Seite.", ex, _userHelper.FromCookies());
|
|
|
+
|
|
|
+ return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Simple JSON result for deleting a specific helpPage
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id">HelpPage id.</param>
|
|
|
+ [HttpPost]
|
|
|
+ public ActionResult DeleteHelpPage(int id)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var helpPage = _miscService.GetHelpPageById(id);
|
|
|
+
|
|
|
+ if (helpPage != null)
|
|
|
+ _miscService.DeleteHelpPage(helpPage);
|
|
|
+
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = "success"
|
|
|
+ };
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.Error("Fehler bei Löschung einer Hilfe-Seite.", ex, _userHelper.FromCookies());
|
|
|
+
|
|
|
+ return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|