public async Task <ActionResult <DataWithVersion <UserSettingsForClient> > > UserSettingsForClient() { try { int userId = _tenantInfo.UserId(); var user = await _db.LocalUsers.FirstOrDefaultAsync(e => e.Id == userId); // prepare the result var forClient = new UserSettingsForClient { UserId = userId, Name = user.Name, Name2 = user.Name2, ImageId = user.ImageId, }; var result = new DataWithVersion <UserSettingsForClient> { Version = user.UserSettingsVersion.ToString(), Data = forClient }; return(Ok(result)); } catch (Exception ex) { _logger.LogError($"Error: {ex.Message} {ex.StackTrace}"); return(BadRequest(ex.Message)); } }
void AddToCaches(string key, byte[] buffer, long commit) { var record = new DataWithVersion(commit, buffer); _all = ImmutableAdd(_all, new DataWithName(key, buffer)); _items.AddOrUpdate(key, s => new[] { record }, (s, records) => ImmutableAdd(records, record)); }
private async Task <DataWithVersion <SettingsForClient> > GetForClientImpl() { M.Settings mSettings = await _db.Settings.FirstOrDefaultAsync(); if (mSettings == null) { // This should never happen throw new BadRequestException("Settings have not been initialized"); } // Prepare the settings for client var settings = _mapper.Map <SettingsForClient>(mSettings); settings.PrimaryLanguageName = _culturesRepo.GetCulture(settings.PrimaryLanguageId)?.Name; settings.SecondaryLanguageName = _culturesRepo.GetCulture(settings.SecondaryLanguageId)?.Name; // Tag the settings for client with their current version var result = new DataWithVersion <SettingsForClient> { Version = mSettings.SettingsVersion.ToString(), Data = settings }; return(result); }
void AddToCaches(string key, byte[] buffer, long commit) { var record = new DataWithVersion(commit, buffer); this._all = AddToNewArray(this._all, new DataWithName(key, buffer)); this._items.AddOrUpdate(key, s => new[] { record }, (s, records) => AddToNewArray(records, record)); }
public virtual async Task <ActionResult <DataWithVersion <PermissionsForClient> > > PermissionsForClient() { try { // Retrieve the user permissions and their current version var(version, permissions) = await _repo.Permissions__Load(); // Arrange the permission in a DTO that is easy for clients to consume var permissionsForClient = new PermissionsForClient(); foreach (var gView in permissions.GroupBy(e => e.View)) { string view = gView.Key; Dictionary <string, bool> viewActions = gView .GroupBy(e => e.Action) .ToDictionary(g => g.Key, g => true); permissionsForClient[view] = viewActions; } // Tag the permissions for client with their current version var result = new DataWithVersion <PermissionsForClient> { Version = version.ToString(), Data = permissionsForClient }; // Return the result return(Ok(result)); } catch (Exception ex) { _logger.LogError($"Error: {ex.Message} {ex.StackTrace}"); return(BadRequest(ex.Message)); } }
public async Task <ActionResult <DataWithVersion <UserSettingsForClient> > > UserSettingsForClient() { return(await ControllerUtilities.InvokeActionImpl(async() => { var(version, user, customSettings) = await _appRepo.UserSettings__Load(); // prepare the result var userSettingsForClient = new UserSettingsForClient { UserId = user.Id, Name = user.Name, Name2 = user.Name2, Name3 = user.Name3, ImageId = user.ImageId, PreferredLanguage = user.PreferredLanguage, CustomSettings = customSettings.ToDictionary(e => e.Key, e => e.Value) }; var result = new DataWithVersion <UserSettingsForClient> { Version = version.ToString(), Data = userSettingsForClient }; return Ok(result); }, _logger)); }
void AddToCaches(string key, byte[] buffer, long commit) { var storeVersion = _all.Length + 1; var record = new DataWithVersion(commit, buffer, storeVersion); _all = AddToNewArray(_all, new DataWithKey(key, buffer, commit, storeVersion)); _items.AddOrUpdate(key, s => new[] { record }, (s, records) => AddToNewArray(records, record)); }
/// <summary> /// Implementation of <see cref="ISettingsCache"/> /// </summary> public void SetSettings(int databaseId, DataWithVersion <SettingsForClient> Settings) { if (databaseId == 0) { throw new ArgumentException($"{nameof(databaseId)} must be provided"); } if (Settings is null) { throw new ArgumentNullException(nameof(Settings)); } _cache.AddOrUpdate(databaseId, Settings, (i, d) => Settings); }
/// <summary> /// Implementation of <see cref="IDefinitionsCache"/> /// </summary> public void SetDefinitions(int databaseId, DataWithVersion <DefinitionsForClient> definitions) { if (databaseId == 0) { throw new ArgumentException($"{nameof(databaseId)} must be provided"); } if (definitions is null) { throw new ArgumentNullException(nameof(definitions)); } _cache.AddOrUpdate(databaseId, definitions, (i, d) => definitions); }
public static async Task <DataWithVersion <SettingsForClient> > LoadSettingsForClient(ApplicationRepository repo) { var(isMultiResponsibilityCenter, settings) = await repo.Settings__Load(); if (settings == null) { // This should never happen throw new BadRequestException("Settings have not been initialized"); } // Prepare the settings for client SettingsForClient settingsForClient = new SettingsForClient(); foreach (var forClientProp in typeof(SettingsForClient).GetProperties()) { var settingsProp = typeof(Settings).GetProperty(forClientProp.Name); if (settingsProp != null) { var value = settingsProp.GetValue(settings); forClientProp.SetValue(settingsForClient, value); } } // Is Multi Responsibility Center settingsForClient.IsMultiResponsibilityCenter = isMultiResponsibilityCenter; // Functional currency settingsForClient.FunctionalCurrencyDecimals = settings.FunctionalCurrency.E ?? 0; settingsForClient.FunctionalCurrencyName = settings.FunctionalCurrency.Name; settingsForClient.FunctionalCurrencyName2 = settings.FunctionalCurrency.Name2; settingsForClient.FunctionalCurrencyName3 = settings.FunctionalCurrency.Name3; settingsForClient.FunctionalCurrencyDescription = settings.FunctionalCurrency.Description; settingsForClient.FunctionalCurrencyDescription2 = settings.FunctionalCurrency.Description2; settingsForClient.FunctionalCurrencyDescription3 = settings.FunctionalCurrency.Description3; // Language settingsForClient.PrimaryLanguageName = GetCultureDisplayName(settingsForClient.PrimaryLanguageId); settingsForClient.SecondaryLanguageName = GetCultureDisplayName(settingsForClient.SecondaryLanguageId); settingsForClient.TernaryLanguageName = GetCultureDisplayName(settingsForClient.TernaryLanguageId); // Tag the settings for client with their current version var result = new DataWithVersion <SettingsForClient> { Version = settings.SettingsVersion.ToString(), Data = settingsForClient }; return(result); }
public virtual async Task <ActionResult <DataWithVersion <PermissionsForClient> > > GetForClient() { try { // Retrieve the current version of the permissions int userId = _tenantInfo.UserId(); Guid version = await _db.LocalUsers.Where(e => e.Id == userId).Select(e => e.PermissionsVersion).FirstOrDefaultAsync(); if (version == null) { // This should never happen return(BadRequest("No user in the system")); } // Retrieve all the permissions var allPermissions = await _db.AbstractPermissions.FromSql($@" DECLARE @UserId INT = CONVERT(INT, SESSION_CONTEXT(N'UserId')); SELECT ViewId, Criteria, Level, Mask FROM [dbo].[Permissions] P JOIN [dbo].[Roles] R ON P.RoleId = R.Id JOIN [dbo].[RoleMemberships] RM ON R.Id = RM.RoleId WHERE R.IsActive = 1 AND RM.UserId = @UserId UNION SELECT ViewId, Criteria, Level, Mask FROM [dbo].[Permissions] P JOIN [dbo].[Roles] R ON P.RoleId = R.Id WHERE R.IsPublic = 1 AND R.IsActive = 1 ").ToListAsync(); // Arrange the permission in a DTO that is easy for clients to consume var permissions = new PermissionsForClient(); foreach (var gViewIds in allPermissions.GroupBy(e => e.ViewId)) { string viewId = gViewIds.Key; var gLevels = gViewIds.GroupBy(e => e.Level); var viewPermissions = new ViewPermissionsForClient(); foreach (var gLevel in gLevels) { var level = gLevel.Key; if (level == Constants.Read) { viewPermissions.Read = true; } if (level == Constants.Create) { viewPermissions.Create = true; } if (level == Constants.ReadCreate) { viewPermissions.Read = true; viewPermissions.Create = true; } if (level == Constants.Update) { viewPermissions.Update = true; } if (level == Constants.Sign) { viewPermissions.Sign = true; } } permissions[viewId] = viewPermissions; } // Tag the permissions for client with their current version var result = new DataWithVersion <PermissionsForClient> { Version = version.ToString(), Data = permissions }; // Return the result return(Ok(result)); } catch (Exception ex) { _logger.LogError($"Error: {ex.Message} {ex.StackTrace}"); return(BadRequest(ex.Message)); } }