|
|
@@ -0,0 +1,243 @@
|
|
|
+using DevExpress.Utils;
|
|
|
+using DevExpress.Web;
|
|
|
+using DevExpress.Web.ASPxThemes;
|
|
|
+using DevExpress.Web.Mvc;
|
|
|
+using DevExpress.XtraPrinting;
|
|
|
+using GreenTree.Nachtragsmanagement.Core.Domain.Deviation;
|
|
|
+using GreenTree.Nachtragsmanagement.Core.Domain.User;
|
|
|
+using GreenTree.Nachtragsmanagement.Services.Appendix;
|
|
|
+using GreenTree.Nachtragsmanagement.Services.Deviation;
|
|
|
+using GreenTree.Nachtragsmanagement.Services.Misc;
|
|
|
+using GreenTree.Nachtragsmanagement.Services.User;
|
|
|
+using GreenTree.Nachtragsmanagement.Web.Framework.Authorization;
|
|
|
+using GreenTree.Nachtragsmanagement.Web.Models.Global;
|
|
|
+using GreenTree.Nachtragsmanagement.Web.Models.Misc;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Web;
|
|
|
+using System.Web.Mvc;
|
|
|
+using System.Web.UI;
|
|
|
+using System.Web.UI.WebControls;
|
|
|
+
|
|
|
+namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
+{
|
|
|
+ public class MiscController : Controller
|
|
|
+ {
|
|
|
+ private readonly IMiscService _miscService;
|
|
|
+ private readonly IUserService _userService;
|
|
|
+ private readonly INotificationService _notificationService;
|
|
|
+
|
|
|
+ public MiscController(
|
|
|
+ IMiscService miscService,
|
|
|
+ IUserService userService,
|
|
|
+ INotificationService notificationService)
|
|
|
+ {
|
|
|
+ _miscService = miscService;
|
|
|
+ _userService = userService;
|
|
|
+ _notificationService = notificationService;
|
|
|
+
|
|
|
+ ViewData["AllUsers"] = _userService.GetAllUsers();
|
|
|
+ ViewData["AllUsersWithRole"] =
|
|
|
+ _userService.GetAllUsers()
|
|
|
+ .Select(u => new
|
|
|
+ {
|
|
|
+ Id = u.Id,
|
|
|
+ Description = String.Format("{0} - {1}", u.Lastname,
|
|
|
+ String.Join(", ", u.Roles
|
|
|
+ .Select(r => r.Description)))
|
|
|
+ })
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ ViewData["AllNotificationPlugins"] =
|
|
|
+ _notificationService.GetNotificationPlugins();
|
|
|
+ }
|
|
|
+
|
|
|
+ #region MailNotifications
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Basic mailNotification view function
|
|
|
+ /// </summary>
|
|
|
+ [FunctionAuthorize(true, "Misc-MailNotifications")]
|
|
|
+ public ActionResult ViewMailNotifications()
|
|
|
+ {
|
|
|
+ var mailNotifications = _miscService.GetAllMailNotifications();
|
|
|
+ var mailNotificationModels = mailNotifications
|
|
|
+ .Select(u => MailNotificationDataModel.FromMailNotification(u, false, _notificationService))
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ return View("~/Views/Misc/MailNotifications.cshtml", mailNotificationModels);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Get JSON data of specific mailNotification
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id">MailNotification id.</param>
|
|
|
+ public ActionResult GetMailNotification(int id = -1)
|
|
|
+ {
|
|
|
+ var mailNotification = _miscService.GetMailNotificationById(id);
|
|
|
+ if (mailNotification == null)
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = "notFound",
|
|
|
+ JsonRequestBehavior = JsonRequestBehavior.AllowGet
|
|
|
+ };
|
|
|
+
|
|
|
+ var mailNotificationModel = MailNotificationDataModel.FromMailNotification(mailNotification, false, _notificationService);
|
|
|
+
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = JsonConvert.SerializeObject(mailNotificationModel),
|
|
|
+ JsonRequestBehavior = JsonRequestBehavior.AllowGet
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Callback result for mailNotification grid
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="scrollHeight">The height of the grid scrollable component.</param>
|
|
|
+ public ActionResult PartialMailNotifications(int scrollHeight = -1)
|
|
|
+ {
|
|
|
+ var mailNotifications = _miscService.GetAllMailNotifications();
|
|
|
+ var mailNotificationModels = mailNotifications
|
|
|
+ .Select(u => MailNotificationDataModel.FromMailNotification(u, false, _notificationService))
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ ViewData["ScrollHeight"] = scrollHeight;
|
|
|
+
|
|
|
+ return PartialView("~/Views/Misc/_MailNotificationGridPartial.cshtml", mailNotificationModels);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Callback result for mailNotification job combobox
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="pluginSystemName">The system name of the corresponding notification plugin.</param>
|
|
|
+ public ActionResult PartialNotificationPluginJobs(string pluginSystemName)
|
|
|
+ {
|
|
|
+ var notificationPlugin = _notificationService.GetNotificationPlugin(pluginSystemName);
|
|
|
+
|
|
|
+ if (notificationPlugin == null)
|
|
|
+ return PartialView("~/Views/Misc/_MailNotificationPluginJobsPartial.cshtml", null);
|
|
|
+
|
|
|
+ var mailNotificationModel = new MailNotificationDataModel
|
|
|
+ {
|
|
|
+ NotificationPlugin = notificationPlugin
|
|
|
+ };
|
|
|
+
|
|
|
+ return PartialView("~/Views/Misc/_MailNotificationPluginJobsPartial.cshtml", mailNotificationModel);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Export result for mailNotification grid
|
|
|
+ /// </summary>
|
|
|
+ [HttpPost]
|
|
|
+ public ActionResult ExportPartialMailNotifications(GridViewExportFormat exportformat)
|
|
|
+ {
|
|
|
+ if (exportformat == null || String.IsNullOrEmpty(exportformat.Format))
|
|
|
+ return new EmptyResult();
|
|
|
+
|
|
|
+ var mailNotifications = _miscService.GetAllMailNotifications();
|
|
|
+ var mailNotificationModels = mailNotifications
|
|
|
+ .Select(u => MailNotificationDataModel.FromMailNotification(u, false, _notificationService))
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ var viewContext = new ViewContext();
|
|
|
+ var viewPage = new ViewPage();
|
|
|
+ var htmlHelper = new HtmlHelper(viewContext, viewPage);
|
|
|
+
|
|
|
+ var gridViewSettings = Extensions.GridViewSettingsHelper.MailNotificationGridViewSettings(htmlHelper);
|
|
|
+
|
|
|
+ switch (exportformat.Format.ToLower())
|
|
|
+ {
|
|
|
+ case "xlsx":
|
|
|
+ return GridViewExtension.ExportToXlsx(gridViewSettings, mailNotificationModels);
|
|
|
+ case "xls":
|
|
|
+ return GridViewExtension.ExportToXls(gridViewSettings, mailNotificationModels);
|
|
|
+ case "pdf":
|
|
|
+ return GridViewExtension.ExportToPdf(gridViewSettings, mailNotificationModels);
|
|
|
+ default:
|
|
|
+ return new EmptyResult();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Partial edit for editing of existing or for new mailNotification
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id">Id for existing mailNotification, otherweise -1.</param>
|
|
|
+ public ActionResult EditMailNotification(int id = -1)
|
|
|
+ {
|
|
|
+ var mailNotification = _miscService.GetMailNotificationById(id);
|
|
|
+ var mailNotificationModel = MailNotificationDataModel.FromMailNotification(mailNotification, true, _notificationService);
|
|
|
+
|
|
|
+ return PartialView("~/Views/Misc/_MailNotificationEditPartial.cshtml", mailNotificationModel);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="mailNotificationModel">MailNotification model to be saved.</param>
|
|
|
+ [HttpPost, ValidateInput(false)]
|
|
|
+ public ActionResult EditMailNotification(MailNotificationDataModel mailNotificationModel)
|
|
|
+ {
|
|
|
+ if (!ModelState.IsValid)
|
|
|
+ {
|
|
|
+ foreach (var role in mailNotificationModel.UserValues)
|
|
|
+ mailNotificationModel.UserDescriptions.Add(
|
|
|
+ ((IList<User>)ViewData["AllUsers"])
|
|
|
+ .First(r => r.Id == role).Lastname);
|
|
|
+
|
|
|
+ return PartialView("~/Views/Misc/_MailNotificationEditPartial.cshtml", mailNotificationModel);
|
|
|
+ }
|
|
|
+
|
|
|
+ var selectedUsers = _userService.GetUsersByIds(mailNotificationModel.UserValues.ToArray());
|
|
|
+
|
|
|
+ if (mailNotificationModel.Id == -1)
|
|
|
+ {
|
|
|
+ var mailNotification = mailNotificationModel.ToMailNotification();
|
|
|
+
|
|
|
+ mailNotification.SetUsers(selectedUsers);
|
|
|
+
|
|
|
+ _miscService.InsertMailNotification(mailNotification);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var mailNotification = _miscService.GetMailNotificationById(mailNotificationModel.Id);
|
|
|
+
|
|
|
+ mailNotification.CronExpression = mailNotificationModel.CronExpression;
|
|
|
+ mailNotification.NotificationPluginSystemName = mailNotificationModel.NotificationPluginSystemName;
|
|
|
+ mailNotification.NotificationJobSystemName = mailNotificationModel.NotificationJobSystemName;
|
|
|
+
|
|
|
+ mailNotification.SetUsers(selectedUsers);
|
|
|
+
|
|
|
+ _miscService.UpdateMailNotification(mailNotification);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = "success"
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Simple JSON result for deleting a specific mailNotification
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id">MailNotification id.</param>
|
|
|
+ [HttpPost]
|
|
|
+ public ActionResult DeleteMailNotification(int id)
|
|
|
+ {
|
|
|
+ var mailNotification = _miscService.GetMailNotificationById(id);
|
|
|
+
|
|
|
+ if (mailNotification != null)
|
|
|
+ _miscService.DeleteMailNotification(mailNotification);
|
|
|
+
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = "success"
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+}
|