| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- using DevExpress.Web.Mvc;
- using GreenTree.Nachtragsmanagement.Services.Appendix;
- using GreenTree.Nachtragsmanagement.Services.Deviation;
- using GreenTree.Nachtragsmanagement.Services.User;
- using GreenTree.Nachtragsmanagement.Web.Models.Appendix;
- using GreenTree.Nachtragsmanagement.Web.Models.Deviation;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using Newtonsoft.Json.Serialization;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Web;
- using System.Web.Mvc;
- namespace GreenTree.Nachtragsmanagement.Web.Controllers
- {
- public class DataCallbackController : Controller
- {
- private readonly IUserService _userService;
- private readonly IDeviationService _deviationService;
- private readonly IAppendixService _appendixService;
- private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
- {
- Error = (serializer, ex) => { ex.ErrorContext.Handled = true; }
- };
- public DataCallbackController(
- IUserService userService,
- IDeviationService deviationService,
- IAppendixService appendixService)
- {
- _userService = userService;
- _deviationService = deviationService;
- _appendixService = appendixService;
- }
- #region User
- /// <summary>
- /// Returns a DevExpress ComboBox for all roles
- /// </summary>
- /// <param name="settingsKey">Current comboBox settings key.</param>
- /// <param name="model">JSON-serialized model.</param>
- /// <param name="type">Type of model.</param>
- public ActionResult RolesComboBox(string settingsKey, string model = null, string type = null)
- {
- return RolesComboBoxExcluded(settingsKey, model, type, null);
- }
- /// <summary>
- /// Returns a DevExpress ComboBox for all roles
- /// </summary>
- /// <param name="settingsKey">Current comboBox settings key.</param>
- /// <param name="model">JSON-serialized model.</param>
- /// <param name="type">Type of model.</param>
- /// <param name="excludedIdsJson">Ids of the excluded roles.</param>
- public ActionResult RolesComboBoxExcluded(string settingsKey, string model, string type, int[] excludedIds)
- {
- var allRoles = _userService.GetAllRoles();
- if (excludedIds != null)
- {
- foreach (var excludedId in excludedIds)
- {
- var item = allRoles
- .FirstOrDefault(s => s.Id == excludedId);
- allRoles.Remove(item);
- }
- }
- ViewData["AllRoles"] = allRoles;
- ViewData["RolesComboBoxSettings"] = settingsKey;
- if (model != null && type != null)
- {
- var modelType = Type.GetType(type);
- var modelObject = JsonConvert.DeserializeObject(model, modelType, _serializerSettings);
- return PartialView("~/Views/Shared/DataEditorTemplates/_RolesComboBox.cshtml", modelObject);
- }
- return PartialView("~/Views/Shared/DataEditorTemplates/_RolesComboBox.cshtml", null);
- }
- #endregion
- #region Deviations
- /// <summary>
- /// Returns a DevExpress ComboBox for all statuses
- /// </summary>
- /// <param name="settingsKey">Current comboBox settings key.</param>
- /// <param name="model">JSON-serialized model.</param>
- /// <param name="type">Type of model.</param>
- public ActionResult StatusesComboBox(string settingsKey, string model, string type)
- {
- return StatusesComboBoxExcluded(settingsKey, model, type, null);
- }
- /// <summary>
- /// Returns a DevExpress ComboBox for all statuses
- /// </summary>
- /// <param name="settingsKey">Current comboBox settings key.</param>
- /// <param name="model">JSON-serialized model.</param>
- /// <param name="type">Type of model.</param>
- /// <param name="excludedIdsJson">Ids of the excluded statuses.</param>
- public ActionResult StatusesComboBoxExcluded(string settingsKey, string model, string type, int[] excludedIds)
- {
- var allStatuses = _deviationService.GetAllStatuses();
- if (excludedIds != null)
- {
- foreach (var excludedId in excludedIds)
- {
- var item = allStatuses
- .FirstOrDefault(s => s.Id == excludedId);
- allStatuses.Remove(item);
- }
- }
- ViewData["AllStatuses"] = allStatuses;
- ViewData["StatusesComboBoxSettings"] = settingsKey;
- if (model != null && type != null)
- {
- var modelType = Type.GetType(type);
- var modelObject = JsonConvert.DeserializeObject(model, modelType, _serializerSettings);
- return PartialView("~/Views/Shared/DataEditorTemplates/_StatusesComboBox.cshtml", modelObject);
- }
- return PartialView("~/Views/Shared/DataEditorTemplates/_StatusesComboBox.cshtml", null);
- }
- /// <summary>
- /// Returns a DevExpress ComboBox for all disturbances
- /// </summary>
- /// <param name="settingsKey">Current comboBox settings key.</param>
- /// <param name="model">JSON-serialized model.</param>
- /// <param name="type">Type of model.</param>
- public ActionResult DisturbancesComboBox(string settingsKey, string model, string type)
- {
- return DisturbancesComboBoxExcluded(settingsKey, model, type, null);
- }
- /// <summary>
- /// Returns a DevExpress ComboBox for all disturbances
- /// </summary>
- /// <param name="settingsKey">Current comboBox settings key.</param>
- /// <param name="model">JSON-serialized model.</param>
- /// <param name="type">Type of model.</param>
- /// <param name="excludedIdsJson">Ids of the excluded disturbances.</param>
- public ActionResult DisturbancesComboBoxExcluded(string settingsKey, string model, string type, int[] excludedIds)
- {
- var allDisturbances = _deviationService.GetAllDisturbances();
- if (excludedIds != null)
- {
- foreach (var excludedId in excludedIds)
- {
- var item = allDisturbances
- .FirstOrDefault(s => s.Id == excludedId);
- allDisturbances.Remove(item);
- }
- }
- ViewData["AllDisturbances"] = allDisturbances;
- ViewData["DisturbancesComboBoxSettings"] = settingsKey;
- if (model != null && type != null)
- {
- var modelType = Type.GetType(type);
- var modelObject = JsonConvert.DeserializeObject(model, modelType, _serializerSettings);
- return PartialView("~/Views/Shared/DataEditorTemplates/_DisturbancesComboBox.cshtml", modelObject);
- }
- return PartialView("~/Views/Shared/DataEditorTemplates/_DisturbancesComboBox.cshtml", null);
- }
- /// <summary>
- /// Returns a DevExpress ComboBox for all kinds
- /// </summary>
- /// <param name="settingsKey">Current comboBox settings key.</param>
- /// <param name="model">JSON-serialized model.</param>
- /// <param name="type">Type of model.</param>
- public ActionResult KindsComboBox(string settingsKey, string model, string type)
- {
- var allKinds = _deviationService.GetAllKinds();
- ViewData["AllKinds"] = allKinds;
- ViewData["KindsComboBoxSettings"] = settingsKey;
- if (model != null && type != null)
- {
- var modelType = Type.GetType(type);
- var modelObject = JsonConvert.DeserializeObject(model, modelType, _serializerSettings);
- return PartialView("~/Views/Shared/DataEditorTemplates/_KindsComboBox.cshtml", modelObject);
- }
- return PartialView("~/Views/Shared/DataEditorTemplates/_KindsComboBox.cshtml", null);
- }
- /// <summary>
- /// Returns a DevExpress ComboBox for all kinds
- /// </summary>
- /// <param name="settingsKey">Current comboBox settings key.</param>
- /// <param name="model">JSON-serialized model.</param>
- /// <param name="type">Type of model.</param>
- /// <param name="excludedIdsJson">Ids of the excluded kinds.</param>
- public ActionResult KindsComboBoxExcluded(string settingsKey, string model, string type, int[] excludedIds)
- {
- var allKinds = _deviationService.GetAllKinds();
- if (excludedIds != null)
- {
- foreach (var excludedId in excludedIds)
- {
- var item = allKinds
- .FirstOrDefault(s => s.Id == excludedId);
- allKinds.Remove(item);
- }
- }
- ViewData["AllKinds"] = allKinds;
- ViewData["KindsComboBoxSettings"] = settingsKey;
- if (model != null && type != null)
- {
- var modelType = Type.GetType(type);
- var modelObject = JsonConvert.DeserializeObject(model, modelType, _serializerSettings);
- return PartialView("~/Views/Shared/DataEditorTemplates/_KindsComboBox.cshtml", modelObject);
- }
- return PartialView("~/Views/Shared/DataEditorTemplates/_KindsComboBox.cshtml", null);
- }
- #endregion
- #region Appendices
- /// <summary>
- /// Returns a DevExpress ComboBox for all states
- /// </summary>
- /// <param name="settingsKey">Current comboBox settings key.</param>
- /// <param name="model">JSON-serialized model.</param>
- /// <param name="type">Type of model.</param>
- public ActionResult StatesComboBox(string settingsKey, string model, string type)
- {
- return StatesComboBoxExcluded(settingsKey, model, type, null);
- }
- /// <summary>
- /// Returns a DevExpress ComboBox for all states
- /// </summary>
- /// <param name="settingsKey">Current comboBox settings key.</param>
- /// <param name="model">JSON-serialized model.</param>
- /// <param name="type">Type of model.</param>
- /// <param name="excludedIdsJson">Ids of the excluded states.</param>
- public ActionResult StatesComboBoxExcluded(string settingsKey, string model, string type, int[] excludedIds)
- {
- var allStates = _appendixService.GetAllStates();
- if (excludedIds != null)
- {
- foreach (var excludedId in excludedIds)
- {
- var item = allStates
- .FirstOrDefault(s => s.Id == excludedId);
- allStates.Remove(item);
- }
- }
- ViewData["AllStates"] = allStates;
- ViewData["StatesComboBoxSettings"] = settingsKey;
- if (model != null && type != null)
- {
- var modelType = Type.GetType(type);
- var modelObject = JsonConvert.DeserializeObject(model, modelType, _serializerSettings);
- return PartialView("~/Views/Shared/DataEditorTemplates/_StatesComboBox.cshtml", modelObject);
- }
- return PartialView("~/Views/Shared/DataEditorTemplates/_StatesComboBox.cshtml", null);
- }
- #endregion
- }
- }
|