Files
BeWoPlaner/BeWoPlanerMobil/Controllers/AbstractBaseController.cs
Lyndon bacc7fcedd Verhindern, dass Ressourcen doppelt gebucht werden mit Recht: ToDoOID=91266751
Serientermine können gelöscht werden, aber es fehlt noch eine Abfrage, ob man wirklich löschen will bei normalen Terminen.
2026-07-13 20:32:48 +02:00

177 lines
6.3 KiB
C#

using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.ServiceContracts;
using BeWo.Service.ServiceContracts.Enhanced;
using BeWoPlanerMobil.Models;
using BeWoPlanerMobil.Service;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using ReportingService.ServiceContracts;
using System;
using System.Diagnostics;
using System.Web.Mvc;
using System.Web.Security;
namespace BeWoPlanerMobil.Controllers
{
public abstract class AbstractBaseController : Controller
{
protected readonly ICustomerService CustomerService = new MobileSessionFacade().CustomerService;
protected readonly IOperationsService OperationsService = new MobileSessionFacade().OperationsService;
protected readonly IEmployeeService EmployeeService = new MobileSessionFacade().EmployeeService;
protected readonly IValueListService ValueListService = new MobileSessionFacade().ValueListService;
protected readonly IResourceService KalenderService = new MobileSessionFacade().ResourceService;
protected readonly IUserService UserService = new MobileSessionFacade().UserService;
protected readonly IDownloadService DownloadService = new MobileSessionFacade().DownloadService;
protected readonly IReportService ReportService = new MobileSessionFacade().ReportService;
protected readonly IQueryService QueryService = new MobileSessionFacade().QueryService;
protected readonly IAiEnhancedService AiService = new MobileSessionFacade().AiService;
protected const string LeerzeichenFuerGetMethoden = " ";
protected static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static readonly string IsSessionTimedOut = "isSessionTimedOut";
private UserDC loggedInUserDc = null;
private EmployeeDC loggedInEmployeeDC = null;
protected ActionResult Logout()
{
#if DEBUG
Debug.WriteLine($"+++>Logout aufrufende Methode: {new StackTrace().GetFrame(1).GetMethod().Name}");
#endif
MobileSessionFacade.LogUserOut();
FormsAuthentication.SignOut();
AbstractModel.TimeOfLastAction = null;
return RedirectToActionPermanent("Index", "Login", new {tenant = MobileSessionFacade.Tenant, message = ViewData[LoginController.LoginErrorIndex]?.ToString() });
}
protected virtual void InitModel(AbstractModel model)
{
model.LoggedInUser = LoggedInUser;
model.LoggedInEmployee = LoggedInEmployee;
model.Mandator = Mandator;
if (model.SessionModel != null)
{
String sessionkey = model.GetType().Name;
if (Session[sessionkey] is null)
{
Session[sessionkey] = model.SessionModel;
}
else
{
model.SessionModel = (BaseSessionModel)Session[sessionkey];
}
}
}
protected UserDC LoggedInUser
{
get
{
if (loggedInUserDc == null)
{
var user = DAOFactory.GenericDAO.LoadByID<ApplicationUser>(MobileSessionFacade.LoggedInUserOid.Value);
loggedInUserDc = MapperFactory.UserDC_User.MapToNewDC(user);
loggedInEmployeeDC = MapperFactory.EmployeeDC_Employee.MapToNewDC(user.Employee);
}
return loggedInUserDc;
}
}
protected EmployeeDC LoggedInEmployee
{
get
{
if(loggedInEmployeeDC == null)
{
var tmp = LoggedInUser; //Sets employee
}
return loggedInEmployeeDC;
}
}
protected MokMandator Mandator
{
get
{
return MobileSessionFacade.Mandator;
}
}
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
if(MobileSessionFacade.IsUserLoggedIn())
{
AbstractModel.TimeOfLastAction = $"{DateTime.Now:yyyy-MM-dd}T{DateTime.Now:HH:mm:ss}";
}
}
public static int TimeoutLimit => System.Web.HttpContext.Current.Session.Timeout;
public bool IsUserLoggedIn()
{
return MobileSessionFacade.IsUserLoggedIn();
}
[Authorize]
public ActionResult UpdateApplicationSettings(string pKey, string pValue)
{
var userSettings = LoggedInUser.Settings;
UserSettingsUtils.SetSettingValue(SettingsType.ApplicationSettings, pKey, pValue, userSettings);
if(LoggedInUser?.UserOid.HasValue ?? false)
{
UserService.UpdateUserSettings(LoggedInUser.UserOid.Value, userSettings);
}
return RedirectToAction("Main");
}
[Authorize]
public void UpdateUserSettingsWithoutReload(string key, string value)
{
var userSettings = LoggedInUser.Settings;
UserSettingsUtils.SetSettingValue(SettingsType.ApplicationSettings, key, value, userSettings);
var loggedInUser = LoggedInUser;
if(loggedInUser?.UserOid.HasValue ?? false)
{
UserService.UpdateUserSettings(loggedInUser.UserOid.Value, userSettings);
}
}
public abstract string SaveCollapsibleStatus(bool isOpen, string identifier);
public string SaveCollapsibleStatusToModel(AbstractModel model, bool isOpen, string identifier)
{
if (model?.Collapsibles2IsShown != null)
{
model.Collapsibles2IsShown[identifier] = isOpen;
}
return LeerzeichenFuerGetMethoden;
}
public ActionResult Error()
{
#if DEBUG
ViewBag.ErrorMessage = "[HIER KOMMT DIE FEHLERMELDUNG HIN]";
#endif
return View("Error");
}
}
}