using System.Collections.Generic; using System.Linq; using BeWoPlanerMobil.Service; using BeWoPlanerMobil.Util; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; namespace BeWoPlanerMobil.Models { public class AbstractModel { public static bool IsDeleteBtnVisible => CheckRight(UserRightType.ServiceRecordView_Delete); public static bool IsAllowedToSeeScheduler => MobileSessionFacade.LoggedInUser != null && CheckRight(UserRightType.KalenderAnsehen) || CheckRight(UserRightType.ViewAll); public static bool IsAllowedToSeeCustomers => CheckRight(UserRightType.ViewAll) || CheckRight(UserRightType.CustomerView_View) || CheckRight(UserRightType.Customer_ViewMyCustomers); public static bool IsEmployeeSelectionVisible => CheckRight(UserRightType.ServiceRecord_AllowCreationForOtherEmployees) || CheckRight(UserRightType.ServiceRecord_AllowCreationForOtherTeamMember); public static bool HasRightForGroupBookings => CheckRight(UserRightType.ServiceRecord_AllowCreatingGroupBooking); public static bool HasRightToViewCustomerAppointments => CheckRight(UserRightType.KalenderKliententermineAlleAnsehen) || CheckRight(UserRightType.CustomerView_View) || CheckRight(UserRightType.Customer_ViewMyCustomers) || CheckRight(UserRightType.Customer_ViewMyTeams); public static bool HasRightToViewEmployeeAppointments => CheckRight(UserRightType.KalenderMitarbeitertermineAnsehen) || CheckRight(UserRightType.ViewAll); public static bool HasRightToViewAllResourceAppointments => CheckRight(UserRightType.KalenderRessourcentermineAnsehen) || CheckRight(UserRightType.ViewAll); public EmployeeDC Employee { get; set; } public string LoggedInEmplyeeFirstNameLastName => Employee != null ? $"{Employee.FirstName} {Employee.LastName}" : "BeWoPlaner"; public static bool HasRightToSeeAllSupportConcepts => CheckRight(UserRightType.SupportConcept_ViewAllSupportConcepts) || CheckRight(UserRightType.ViewAll); public static bool HasRightToSeeTextModules => CheckRight(UserRightType.TextbausteineNurEigeneAnsehen) || CheckRight(UserRightType.TextbausteineAlleAnsehen); public static bool HasRightToSeeOwnTextModules => CheckRight(UserRightType.TextbausteineNurEigeneAnsehen); public static bool HasRightToSeeGlobalTextModules => CheckRight(UserRightType.TextbausteineAlleAnsehen); public static bool HasRightToSeeServiceRecords => CheckRight(UserRightType.ServiceRecordView_View) && CheckRight(UserRightType.ServiceRecordView_Create); public static string TimeOfLastAction { get; set; } public static bool HasRightToInsertRessourceAppointments => CheckRight(UserRightType.KalenderRessourcentermineAnlegen) || CheckRight(UserRightType.CreateAll); public static bool HasRightToViewQuittierungsbelege { get { var mandator = new MobileSessionFacade().OperationsService.GetMandator(); var showEmployeeSignatureSetting = MobileUtils.GetSettingValue(mandator.Settings, SettingsKeys.ShowSignature); #if DEBUG showEmployeeSignatureSetting = "1"; #endif return CheckRights(new List{ UserRightType.Analysis_ServiceOverview_View, UserRightType.Signature_ProvideMonthlySignature }) && showEmployeeSignatureSetting != null && showEmployeeSignatureSetting.Equals("1"); } } public static bool IsAllowedToSeeSupportConceptFilter { get { var user = MobileSessionFacade.LoggedInUser; if(user != null) { return user.CheckForAtLeastOneRight(new List { UserRightType.ViewAll, UserRightType.SupportConcept_ViewAllSupportConcepts }) || user.CheckForRight(UserRightType.SupportConcept_ViewMyTeams); } return false; } } public static string UserSettings { get { var user = MobileSessionFacade.LoggedInUser; return user?.SettingList.FirstOrDefault(f => f.Type.Equals(SettingsType.ApplicationSettings))?.Value; } } public static bool IsAllowedToSeeCustomerFilter { get { var user = MobileSessionFacade.LoggedInUser; if(user != null) { return user.CheckForRight(UserRightType.ViewAll) || user.CheckForRight(UserRightType.Customer_ViewMyTeams); } return false; } } public static bool IsAllowedToSeeMedikamentenliste { get { var mandator = new MobileSessionFacade().OperationsService.GetMandator(); var hasSetting = MobileUtils.GetSettingValue(mandator.Settings, SettingsKeys.ShowMedication) == "1"; var hasRight = CheckRight(UserRightType.Customer_ViewMedication); return hasSetting && hasRight; } } public static bool CheckRight(UserRightType userRightType) { return MobileSessionFacade.CheckForUserRight(userRightType); } public static bool CheckRights(List userRightTypes) { return userRightTypes.All(MobileSessionFacade.CheckForUserRight); } public static bool CheckForAtLeastOneRight(UserRightType[] rights) { return rights.Any(MobileSessionFacade.CheckForUserRight); } public static bool HasRightToInsertEmployeeAppointments => CheckRight(UserRightType.KalenderMitarbeitertermineAnlegen) || CheckRight(UserRightType.CreateAll); public static bool HasRightToEditEmployeeAppointments => CheckRight(UserRightType.KalenderMitarbeitertermineAendern) || CheckRight(UserRightType.EditAll); public static bool HasRightToEditResourceAppointments => CheckRight(UserRightType.KalenderRessourcentermineAendern) || CheckRight(UserRightType.EditAll); public static bool HasRightToEditOthersResourceAppointments => CheckRight(UserRightType.KalenderRessourcentermineAndererAendern) || CheckRight(UserRightType.EditAll); public static bool HasRightToInsertCustomerAppointments => CheckRight(UserRightType.KalenderKliententermineAnlegen) && (CheckRight(UserRightType.CustomerView_View) || CheckRight(UserRightType.Customer_ViewMyCustomers) || CheckRight(UserRightType.Customer_ViewMyTeams)) || CheckRight(UserRightType.CreateAll); public static bool HasRightToEditCustomerAppointments => CheckRight(UserRightType.KalenderKliententermineAendern) || CheckRight(UserRightType.EditAll); public static bool ShowServiceRecordInsertedOn { get; set; } public static bool HasRightToViewCustomerSelectionInScheduler => CheckRight(UserRightType.CustomerView_View) || CheckRight(UserRightType.Customer_ViewMyCustomers) || CheckRight(UserRightType.Customer_ViewMyTeams); public static bool HasRightToViewTeams => CheckRight(UserRightType.TeamView_ViewMyTeams) || CheckRight(UserRightType.TeamView_ViewAll); public static bool HasRightForMultiBooking => CheckRight(UserRightType.ServiceRecord_AllowCreatingMultiBooking); public static bool HasRightToDeleteReceiptSignatures => CheckRight(UserRightType.ConfirmationReceiptSignatures_Delete); public static bool HasRightToRateGoals => CheckRight(UserRightType.BewertenInZeiterfassung); public static bool HasRightToEditCustomers => CheckRight(UserRightType.CustomerView_Edit); public static bool HasRightMitarbeiterstundenkontoViewAll => CheckRight(UserRightType.Mitarbeiterstundenkonto_ViewAll); public static bool HasRightMitarbeiterstundenkontoViewTeams => CheckRight(UserRightType.Mitarbeiterstundenkonto_ViewTeams); public static bool HasRightMitarbeiterstundenkontoViewSelf => CheckRight(UserRightType.Mitarbeiterstundenkonto_ViewSelf); public static bool HasRightToViewReports => CheckForAtLeastOneRight(new UserRightType[] { UserRightType.ViewAll, UserRightType.QueryView_View, UserRightType.Analysis_ServiceOverview_View, UserRightType.Analysis_Auslastung_View, UserRightType.Analysis_AuslastungAllEmployee_View, UserRightType.Analysis_AuslastungTeam_View, UserRightType.Kilometerauswertung_View, UserRightType.KilometerauswertungEigene_View, UserRightType.BewertungAuswertung_View, UserRightType.PivotTabelleAnsehen, UserRightType.DienstplanungAnsehen, UserRightType.AbwesenheitsPlanungAnsehen, UserRightType.Mitarbeiterstundenkonto_ViewAll, UserRightType.Mitarbeiterstundenkonto_ViewSelf, UserRightType.Mitarbeiterstundenkonto_ViewTeams, UserRightType.Jahresbericht, UserRightType.Auswertungen_BerichteAnsehen, UserRightType.Auswertungen_StundenuebersichtAnsehen, UserRightType.Auswertungen_HilfeplanuebersichtAnsehen }); public static bool HasRightToViewMitarbeiterstundenkonto { get { return MobileSessionFacade.Tenant != "3010479871" && CheckForAtLeastOneRight(new[] { UserRightType.Mitarbeiterstundenkonto_ViewAll, UserRightType.Mitarbeiterstundenkonto_ViewTeams, UserRightType.Mitarbeiterstundenkonto_ViewSelf }); } } public static bool HasRightToViewDiagnosen => CheckRight(UserRightType.Customer_ViewDiagnosis); public static bool HasRightToProvideSingleSignature => CheckRight(UserRightType.Signature_ProvideSingleSignature); public static bool HasRightToViewOwnCustomersBargeldkassen => CheckRight(UserRightType.BargeldverwaltungNurEigeneAnsehen); public static bool HasRightToViewAllCustomersBargeldkassen => CheckRight(UserRightType.BargeldverwaltungAnsehen); public static bool HasRightToDeleteCustomerBargeldkassen => CheckRight(UserRightType.BargeldverwaltungLoeschen); public static bool HasRightToCreateCustomerBargeldkassen => CheckRight(UserRightType.BargeldverwaltungAnlegen); public static bool HasRightToEditCustomerBargeldkassen => CheckRight(UserRightType.BargeldverwaltungBearbeiten); public static bool HasRightToViewCustomerAbsenceTimes => CheckRight(UserRightType.Customer_ViewAbsenceTimes); } }