Dynamic user profile per tenant
This commit is contained in:
21
Oqtane.Client/Services/Interfaces/IProfileService.cs
Normal file
21
Oqtane.Client/Services/Interfaces/IProfileService.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using Oqtane.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public interface IProfileService
|
||||
{
|
||||
Task<List<Profile>> GetProfilesAsync();
|
||||
|
||||
Task<List<Profile>> GetProfilesAsync(int SiteId);
|
||||
|
||||
Task<Profile> GetProfileAsync(int ProfileId);
|
||||
|
||||
Task<Profile> AddProfileAsync(Profile Profile);
|
||||
|
||||
Task<Profile> UpdateProfileAsync(Profile Profile);
|
||||
|
||||
Task DeleteProfileAsync(int ProfileId);
|
||||
}
|
||||
}
|
@ -26,6 +26,10 @@ namespace Oqtane.Services
|
||||
|
||||
Task<Setting> UpdateModuleSettingsAsync(List<Setting> ModuleSettings, int ModuleId, string SettingName, string SettingValue);
|
||||
|
||||
Task<List<Setting>> GetUserSettingsAsync(int UserId);
|
||||
|
||||
Task<Setting> UpdateUserSettingsAsync(List<Setting> UserSettings, int UserId, string SettingName, string SettingValue);
|
||||
|
||||
|
||||
Task<List<Setting>> GetSettingsAsync(string EntityName, int EntityId);
|
||||
|
||||
@ -35,9 +39,13 @@ namespace Oqtane.Services
|
||||
|
||||
Task<Setting> UpdateSettingAsync(Setting Setting);
|
||||
|
||||
Task<Setting> UpdateSettingsAsync(List<Setting> Settings, string EntityName, int EntityId, string SettingName, string SettingValue);
|
||||
|
||||
Task DeleteSettingAsync(int SettingId);
|
||||
|
||||
|
||||
string GetSetting(List<Setting> Settings, string SettingName, string DefaultValue);
|
||||
}
|
||||
|
||||
List<Setting> SetSetting(List<Setting> Settings, string EntityName, int EntityId, string SettingName, string SettingValue);
|
||||
}
|
||||
}
|
||||
|
59
Oqtane.Client/Services/ProfileService.cs
Normal file
59
Oqtane.Client/Services/ProfileService.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using Oqtane.Models;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public class ProfileService : ServiceBase, IProfileService
|
||||
{
|
||||
private readonly HttpClient http;
|
||||
private readonly SiteState sitestate;
|
||||
private readonly IUriHelper urihelper;
|
||||
|
||||
public ProfileService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
|
||||
{
|
||||
this.http = http;
|
||||
this.sitestate = sitestate;
|
||||
this.urihelper = urihelper;
|
||||
}
|
||||
|
||||
private string apiurl
|
||||
{
|
||||
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Profile"); }
|
||||
}
|
||||
|
||||
public async Task<List<Profile>> GetProfilesAsync()
|
||||
{
|
||||
return await http.GetJsonAsync<List<Profile>>(apiurl);
|
||||
}
|
||||
|
||||
public async Task<List<Profile>> GetProfilesAsync(int SiteId)
|
||||
{
|
||||
List<Profile> Profiles = await http.GetJsonAsync<List<Profile>>(apiurl + "?siteid=" + SiteId.ToString());
|
||||
return Profiles.OrderBy(item => item.ViewOrder).ToList();
|
||||
}
|
||||
|
||||
public async Task<Profile> GetProfileAsync(int ProfileId)
|
||||
{
|
||||
return await http.GetJsonAsync<Profile>(apiurl + "/" + ProfileId.ToString());
|
||||
}
|
||||
|
||||
public async Task<Profile> AddProfileAsync(Profile Profile)
|
||||
{
|
||||
return await http.PostJsonAsync<Profile>(apiurl, Profile);
|
||||
}
|
||||
|
||||
public async Task<Profile> UpdateProfileAsync(Profile Profile)
|
||||
{
|
||||
return await http.PutJsonAsync<Profile>(apiurl + "/" + Profile.SiteId.ToString(), Profile);
|
||||
}
|
||||
public async Task DeleteProfileAsync(int ProfileId)
|
||||
{
|
||||
await http.DeleteAsync(apiurl + "/" + ProfileId.ToString());
|
||||
}
|
||||
}
|
||||
}
|
@ -33,22 +33,7 @@ namespace Oqtane.Services
|
||||
|
||||
public async Task<Setting> UpdateHostSettingsAsync(List<Setting> HostSettings, string SettingName, string SettingValue)
|
||||
{
|
||||
Setting setting = HostSettings.Where(item => item.SettingName == SettingName).FirstOrDefault();
|
||||
if (setting == null)
|
||||
{
|
||||
setting = new Setting();
|
||||
setting.EntityName = "Host";
|
||||
setting.EntityId = -1;
|
||||
setting.SettingName = SettingName;
|
||||
setting.SettingValue = SettingValue;
|
||||
setting = await AddSettingAsync(setting);
|
||||
}
|
||||
else
|
||||
{
|
||||
setting.SettingValue = SettingValue;
|
||||
setting = await UpdateSettingAsync(setting);
|
||||
}
|
||||
return setting;
|
||||
return await UpdateSettingsAsync(HostSettings, "Host", -1, SettingName, SettingValue);
|
||||
}
|
||||
|
||||
public async Task<List<Setting>> GetSiteSettingsAsync(int SiteId)
|
||||
@ -58,22 +43,7 @@ namespace Oqtane.Services
|
||||
|
||||
public async Task<Setting> UpdateSiteSettingsAsync(List<Setting> SiteSettings, int SiteId, string SettingName, string SettingValue)
|
||||
{
|
||||
Setting setting = SiteSettings.Where(item => item.SettingName == SettingName).FirstOrDefault();
|
||||
if (setting == null)
|
||||
{
|
||||
setting = new Setting();
|
||||
setting.EntityName = "Site";
|
||||
setting.EntityId = SiteId;
|
||||
setting.SettingName = SettingName;
|
||||
setting.SettingValue = SettingValue;
|
||||
setting = await AddSettingAsync(setting);
|
||||
}
|
||||
else
|
||||
{
|
||||
setting.SettingValue = SettingValue;
|
||||
setting = await UpdateSettingAsync(setting);
|
||||
}
|
||||
return setting;
|
||||
return await UpdateSettingsAsync(SiteSettings, "Site", SiteId, SettingName, SettingValue);
|
||||
}
|
||||
|
||||
public async Task<List<Setting>> GetPageSettingsAsync(int PageId)
|
||||
@ -83,22 +53,7 @@ namespace Oqtane.Services
|
||||
|
||||
public async Task<Setting> UpdatePageSettingsAsync(List<Setting> PageSettings, int PageId, string SettingName, string SettingValue)
|
||||
{
|
||||
Setting setting = PageSettings.Where(item => item.SettingName == SettingName).FirstOrDefault();
|
||||
if (setting == null)
|
||||
{
|
||||
setting = new Setting();
|
||||
setting.EntityName = "Page";
|
||||
setting.EntityId = PageId;
|
||||
setting.SettingName = SettingName;
|
||||
setting.SettingValue = SettingValue;
|
||||
setting = await AddSettingAsync(setting);
|
||||
}
|
||||
else
|
||||
{
|
||||
setting.SettingValue = SettingValue;
|
||||
setting = await UpdateSettingAsync(setting);
|
||||
}
|
||||
return setting;
|
||||
return await UpdateSettingsAsync(PageSettings, "Page", PageId, SettingName, SettingValue);
|
||||
}
|
||||
|
||||
public async Task<List<Setting>> GetPageModuleSettingsAsync(int PageModuleId)
|
||||
@ -108,22 +63,7 @@ namespace Oqtane.Services
|
||||
|
||||
public async Task<Setting> UpdatePageModuleSettingsAsync(List<Setting> PageModuleSettings, int PageModuleId, string SettingName, string SettingValue)
|
||||
{
|
||||
Setting setting = PageModuleSettings.Where(item => item.SettingName == SettingName).FirstOrDefault();
|
||||
if (setting == null)
|
||||
{
|
||||
setting = new Setting();
|
||||
setting.EntityName = "PageModule";
|
||||
setting.EntityId = PageModuleId;
|
||||
setting.SettingName = SettingName;
|
||||
setting.SettingValue = SettingValue;
|
||||
setting = await AddSettingAsync(setting);
|
||||
}
|
||||
else
|
||||
{
|
||||
setting.SettingValue = SettingValue;
|
||||
setting = await UpdateSettingAsync(setting);
|
||||
}
|
||||
return setting;
|
||||
return await UpdateSettingsAsync(PageModuleSettings, "PageModule", PageModuleId, SettingName, SettingValue);
|
||||
}
|
||||
|
||||
public async Task<List<Setting>> GetModuleSettingsAsync(int ModuleId)
|
||||
@ -133,22 +73,17 @@ namespace Oqtane.Services
|
||||
|
||||
public async Task<Setting> UpdateModuleSettingsAsync(List<Setting> ModuleSettings, int ModuleId, string SettingName, string SettingValue)
|
||||
{
|
||||
Setting setting = ModuleSettings.Where(item => item.SettingName == SettingName).FirstOrDefault();
|
||||
if (setting == null)
|
||||
{
|
||||
setting = new Setting();
|
||||
setting.EntityName = "Module";
|
||||
setting.EntityId = ModuleId;
|
||||
setting.SettingName = SettingName;
|
||||
setting.SettingValue = SettingValue;
|
||||
setting = await AddSettingAsync(setting);
|
||||
}
|
||||
else
|
||||
{
|
||||
setting.SettingValue = SettingValue;
|
||||
setting = await UpdateSettingAsync(setting);
|
||||
}
|
||||
return setting;
|
||||
return await UpdateSettingsAsync(ModuleSettings, "Module", ModuleId, SettingName, SettingValue);
|
||||
}
|
||||
|
||||
public async Task<List<Setting>> GetUserSettingsAsync(int UserId)
|
||||
{
|
||||
return await GetSettingsAsync("User", UserId);
|
||||
}
|
||||
|
||||
public async Task<Setting> UpdateUserSettingsAsync(List<Setting> UserSettings, int UserId, string SettingName, string SettingValue)
|
||||
{
|
||||
return await UpdateSettingsAsync(UserSettings, "User", UserId, SettingName, SettingValue);
|
||||
}
|
||||
|
||||
public async Task<List<Setting>> GetSettingsAsync(string EntityName, int EntityId)
|
||||
@ -171,6 +106,27 @@ namespace Oqtane.Services
|
||||
{
|
||||
return await http.PutJsonAsync<Setting>(apiurl + "/" + Setting.SettingId.ToString(), Setting);
|
||||
}
|
||||
|
||||
public async Task<Setting> UpdateSettingsAsync(List<Setting> Settings, string EntityName, int EntityId, string SettingName, string SettingValue)
|
||||
{
|
||||
Setting setting = Settings.Where(item => item.SettingName == SettingName).FirstOrDefault();
|
||||
if (setting == null || setting.SettingId == -1)
|
||||
{
|
||||
setting = new Setting();
|
||||
setting.EntityName = EntityName;
|
||||
setting.EntityId = EntityId;
|
||||
setting.SettingName = SettingName;
|
||||
setting.SettingValue = SettingValue;
|
||||
setting = await AddSettingAsync(setting);
|
||||
}
|
||||
else
|
||||
{
|
||||
setting.SettingValue = SettingValue;
|
||||
setting = await UpdateSettingAsync(setting);
|
||||
}
|
||||
return setting;
|
||||
}
|
||||
|
||||
public async Task DeleteSettingAsync(int SettingId)
|
||||
{
|
||||
await http.DeleteAsync(apiurl + "/" + SettingId.ToString());
|
||||
@ -187,5 +143,19 @@ namespace Oqtane.Services
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public List<Setting> SetSetting(List<Setting> Settings, string EntityName, int EntityId, string SettingName, string SettingValue)
|
||||
{
|
||||
int index = Settings.FindIndex(item => item.EntityName == EntityName && item.EntityId == EntityId && item.SettingName == SettingName);
|
||||
if (index != -1)
|
||||
{
|
||||
Settings[index].SettingValue = SettingValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Settings.Add(new Setting { SettingId = -1, EntityName = EntityName, EntityId = EntityId, SettingName = SettingName, SettingValue = SettingValue });
|
||||
}
|
||||
return Settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user