public static string ToEnglishList(UserContextName context) { var items = new List <string>(); if (context == UserContextName.All) { return(AppGlobal.Language.GetText("UserContext_Name_All", "All")); } if (context == UserContextName.None) { return(AppGlobal.Language.GetText("UserContext_Name_None", "None")); } if ((context & UserContextName.Administration) != 0) { items.Add(AppGlobal.Language.GetText("UserContext_Name_Administration", "Administration")); } if ((context & UserContextName.Provider) != 0) { items.Add(AppGlobal.Language.GetText("UserContext_Name_Provider", "Provider")); } if ((context & UserContextName.Organisation) != 0) { items.Add(AppGlobal.Language.GetText("UserContext_Name_Organisation", "Organisation")); } if ((context & UserContextName.AuthenticatedNoAccess) != 0) { items.Add(AppGlobal.Language.GetText("UserContext_Name_AuthenticatedNoAccess", "AuthenticatedNoAccess")); } if ((context & UserContextName.Unauthenticated) != 0) { items.Add(AppGlobal.Language.GetText("UserContext_Name_Unauthenticated", "Unauthenticated")); } if ((context & UserContextName.DeletedProvider) != 0) { items.Add(AppGlobal.Language.GetText("UserContext_Name_DeletedProvider", "DeletedProvider")); } if ((context & UserContextName.DeletedOrganisation) != 0) { items.Add(AppGlobal.Language.GetText("UserContext_Name_DeletedOrganisation", "DeletedOrganisation")); } return(String.Join(", ", items)); }
/// <summary> /// Create a new instance of the <c ref="UserContextInfo" /> class. /// </summary> /// <param name="contextName">The <c ref="UserContextName" /></param> public UserContextInfo(UserContextName contextName) : this(contextName, null) { }
/// <summary> /// Create a new instance of the <c ref="UserContextInfo" /> class. /// </summary> /// <param name="contextName">The <c ref="UserContextName" /></param> /// <param name="itemId">The related entity ID.</param> public UserContextInfo(UserContextName contextName, int?itemId) { ContextName = contextName; ItemId = itemId; }
/// <summary> /// Change the current user context. /// </summary> /// <param name="db">A valid <c ref="ProviderPortalentities"/> context.</param> /// <param name="context">The desired user context.</param> /// <param name="itemId">The related item ID.</param> /// <param name="force">When true, removes the record status check.</param> /// <returns>Whether the context change succeeded.</returns> public static bool SetUserContext(ProviderPortalEntities db, UserContextName context, int?itemId = null, bool force = false) { var currentContext = GetUserContext(); if (currentContext.ContextName == context && currentContext.ItemId == itemId) { return(true); } var currentUserId = Permission.GetCurrentUserId(); bool canViewAdmin = Permission.HasPermission(false, true, Permission.PermissionName.CanViewAdministratorHomePage); bool success = false; switch (context) { case UserContextName.DeletedProvider: case UserContextName.Provider: var provider = db.Providers.FirstOrDefault(x => x.ProviderId == itemId); if (provider == null) { break; } bool canViewProvider = Permission.HasPermission(false, true, Permission.PermissionName.CanViewProviderHomePage); // Success if an admin, associated provider user or organisation user with edit permission success = canViewProvider && (canViewAdmin || provider.AspNetUsers.Any(x => x.Id == currentUserId) || provider.OrganisationProviders.Any( x => x.CanOrganisationEditProvider && x.IsAccepted && !x.IsRejected && x.Organisation.AspNetUsers.Any(y => y.Id == currentUserId))); context = force ? context : provider.RecordStatusId != (int)Constants.RecordStatus.Live ? UserContextName.DeletedProvider : UserContextName.Provider; break; case UserContextName.DeletedOrganisation: case UserContextName.Organisation: var organisation = db.Organisations.FirstOrDefault(x => x.OrganisationId == itemId); if (organisation == null) { break; } bool canViewOrganisation = Permission.HasPermission(false, true, Permission.PermissionName.CanViewOrganisationHomePage); // Success if an admin or associated organisation user success = canViewOrganisation && (canViewAdmin || organisation.AspNetUsers.Any(x => x.Id == currentUserId)); context = force ? context : organisation.RecordStatusId != (int)Constants.RecordStatus.Live ? UserContextName.DeletedOrganisation : UserContextName.Organisation; break; case UserContextName.Administration: // Success if admin success = canViewAdmin; break; } if (success) { var newContext = new UserContextInfo(context, itemId); SetSessionContext(newContext); } return(success); }