|
|
@@ -8,12 +8,14 @@ using GreenTree.Nachtragsmanagement.Core.Authentication;
|
|
|
using GreenTree.Nachtragsmanagement.Core.Domain.Deviation;
|
|
|
using GreenTree.Nachtragsmanagement.Core.Domain.User;
|
|
|
using GreenTree.Nachtragsmanagement.Services.Appendix;
|
|
|
+using GreenTree.Nachtragsmanagement.Services.Configuration;
|
|
|
using GreenTree.Nachtragsmanagement.Services.Deviation;
|
|
|
using GreenTree.Nachtragsmanagement.Services.Logging;
|
|
|
using GreenTree.Nachtragsmanagement.Services.Misc;
|
|
|
using GreenTree.Nachtragsmanagement.Services.Scheduling;
|
|
|
using GreenTree.Nachtragsmanagement.Services.User;
|
|
|
using GreenTree.Nachtragsmanagement.Web.Framework.Authorization;
|
|
|
+using GreenTree.Nachtragsmanagement.Web.Models.Config;
|
|
|
using GreenTree.Nachtragsmanagement.Web.Models.Global;
|
|
|
using GreenTree.Nachtragsmanagement.Web.Models.Misc;
|
|
|
using Newtonsoft.Json;
|
|
|
@@ -34,6 +36,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
private readonly IUserService _userService;
|
|
|
private readonly INotificationService _notificationService;
|
|
|
private readonly INotificationScheduler _notificationScheduler;
|
|
|
+ private readonly IConfigurationService _configurationService;
|
|
|
private readonly IUserHelper _userHelper;
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
@@ -42,6 +45,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
IUserService userService,
|
|
|
INotificationService notificationService,
|
|
|
INotificationScheduler notificationScheduler,
|
|
|
+ IConfigurationService configurationService,
|
|
|
IUserHelper userHelper,
|
|
|
ILogger logger)
|
|
|
{
|
|
|
@@ -49,6 +53,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
_userService = userService;
|
|
|
_notificationService = notificationService;
|
|
|
_notificationScheduler = notificationScheduler;
|
|
|
+ _configurationService = configurationService;
|
|
|
_userHelper = userHelper;
|
|
|
_logger = logger;
|
|
|
|
|
|
@@ -451,5 +456,152 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
+
|
|
|
+ #region ConfigItems
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Basic configItem view function
|
|
|
+ /// </summary>
|
|
|
+ [FunctionAuthorize(true, "Misc-ConfigItems")]
|
|
|
+ public ActionResult ViewConfigItems()
|
|
|
+ {
|
|
|
+ var configItems = _configurationService.GetAllConfigItems();
|
|
|
+ var configItemModels = configItems
|
|
|
+ .Select(u => ConfigItemDataModel.FromConfigItem(u, false))
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ return View("~/Views/Config/View.cshtml", configItemModels);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Get JSON data of specific configItem
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id">ConfigItem id.</param>
|
|
|
+ public ActionResult GetConfigItem(int id = -1)
|
|
|
+ {
|
|
|
+ var configItem = _configurationService.GetConfigItemById(id);
|
|
|
+ if (configItem == null)
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = "notFound",
|
|
|
+ JsonRequestBehavior = JsonRequestBehavior.AllowGet
|
|
|
+ };
|
|
|
+
|
|
|
+ var configItemModel = ConfigItemDataModel.FromConfigItem(configItem, false);
|
|
|
+
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = JsonConvert.SerializeObject(configItemModel),
|
|
|
+ JsonRequestBehavior = JsonRequestBehavior.AllowGet
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Callback result for configItem grid
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="scrollHeight">The height of the grid scrollable component.</param>
|
|
|
+ public ActionResult PartialConfigItems(int scrollHeight = -1)
|
|
|
+ {
|
|
|
+ var configItems = _configurationService.GetAllConfigItems();
|
|
|
+ var configItemModels = configItems
|
|
|
+ .Select(u => ConfigItemDataModel.FromConfigItem(u, false))
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ ViewData["ScrollHeight"] = scrollHeight;
|
|
|
+
|
|
|
+ return PartialView("~/Views/Config/_ConfigItemGridPartial.cshtml", configItemModels);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Partial edit for editing of existing or for new configItem
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id">Id for existing configItem, otherweise -1.</param>
|
|
|
+ public ActionResult EditConfigItem(int id = -1)
|
|
|
+ {
|
|
|
+ var configItem = _configurationService.GetConfigItemById(id);
|
|
|
+ var configItemModel = ConfigItemDataModel.FromConfigItem(configItem, true);
|
|
|
+
|
|
|
+ return PartialView("~/Views/Config/_ConfigItemEditPartial.cshtml", configItemModel);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="configItemModel">ConfigItem model to be saved.</param>
|
|
|
+ [HttpPost, ValidateInput(false)]
|
|
|
+ public ActionResult EditConfigItem(ConfigItemDataModel configItemModel)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!ModelState.IsValid)
|
|
|
+ return PartialView("~/Views/Config/_ConfigItemEditPartial.cshtml", configItemModel);
|
|
|
+
|
|
|
+ if (configItemModel.Id == -1)
|
|
|
+ {
|
|
|
+ var configItem = configItemModel.ToConfigItem();
|
|
|
+
|
|
|
+ _configurationService.InsertConfigItem(configItem);
|
|
|
+
|
|
|
+ _logger.Entity(configItem, Core.Domain.Logging.LogEntityActivity.Insert, _userHelper.FromCookies());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var configItem = _configurationService.GetConfigItemById(configItemModel.Id);
|
|
|
+
|
|
|
+ configItem.Name = configItemModel.Name;
|
|
|
+ configItem.TypeFullName = configItemModel.TypeFullName;
|
|
|
+ configItem.Value = configItemModel.Value;
|
|
|
+ configItem.Description = configItem.Description;
|
|
|
+
|
|
|
+ _configurationService.UpdateConfigItem(configItem);
|
|
|
+
|
|
|
+ _logger.Entity(configItem, Core.Domain.Logging.LogEntityActivity.Update, _userHelper.FromCookies());
|
|
|
+ }
|
|
|
+
|
|
|
+ _notificationScheduler.Start();
|
|
|
+
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = "success"
|
|
|
+ };
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.Error("Fehler bei Speicherung einer Einstellung.", ex, _userHelper.FromCookies());
|
|
|
+
|
|
|
+ return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Simple JSON result for deleting a specific configItem
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id">ConfigItem id.</param>
|
|
|
+ [HttpPost]
|
|
|
+ public ActionResult DeleteConfigItem(int id)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var configItem = _configurationService.GetConfigItemById(id);
|
|
|
+
|
|
|
+ if (configItem != null)
|
|
|
+ _configurationService.DeleteConfigItem(configItem);
|
|
|
+
|
|
|
+ _logger.Entity(configItem, Core.Domain.Logging.LogEntityActivity.Delete, _userHelper.FromCookies());
|
|
|
+
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = "success"
|
|
|
+ };
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.Error("Fehler bei Löschung einer Einstellung.", ex, _userHelper.FromCookies());
|
|
|
+
|
|
|
+ return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|