From 1e4c07889bf4e5c797c904149719114f8295bb65 Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Tue, 3 Sep 2019 20:39:29 -0400 Subject: [PATCH] Dynamic user profile per tenant --- .../Admin/ModuleDefinitions/Index.razor | 2 +- .../Modules/Admin/ModuleSettings/Index.razor | 8 +- Oqtane.Client/Modules/Admin/Pages/Add.razor | 3 +- .../Modules/Admin/Pages/Delete.razor | 2 +- Oqtane.Client/Modules/Admin/Pages/Edit.razor | 2 +- Oqtane.Client/Modules/Admin/Pages/Index.razor | 2 +- .../Modules/Admin/Profile/Index.razor | 116 ++++++++++++++++ Oqtane.Client/Modules/Admin/Roles/Index.razor | 2 +- Oqtane.Client/Modules/Admin/Sites/Add.razor | 2 +- Oqtane.Client/Modules/Admin/Sites/Index.razor | 2 +- .../Modules/Admin/Themes/Index.razor | 2 +- .../Modules/Controls/PermissionGrid.razor | 122 ++++++++-------- .../Services/Interfaces/IProfileService.cs | 21 +++ .../Services/Interfaces/ISettingService.cs | 10 +- Oqtane.Client/Services/ProfileService.cs | 59 ++++++++ Oqtane.Client/Services/SettingService.cs | 130 +++++++----------- Oqtane.Client/Startup.cs | 1 + Oqtane.Client/Themes/Controls/Profile.razor | 7 +- .../Controllers/ProfileController.cs | 73 ++++++++++ .../Repository/Context/TenantDBContext.cs | 1 + .../Interfaces/IProfileRepository.cs | 15 ++ Oqtane.Server/Repository/ProfileRepository.cs | 53 +++++++ Oqtane.Server/Scripts/00.00.00.sql | 52 +++++++ Oqtane.Server/Startup.cs | 2 + Oqtane.Shared/Models/Profile.cs | 24 ++++ 25 files changed, 558 insertions(+), 155 deletions(-) create mode 100644 Oqtane.Client/Modules/Admin/Profile/Index.razor create mode 100644 Oqtane.Client/Services/Interfaces/IProfileService.cs create mode 100644 Oqtane.Client/Services/ProfileService.cs create mode 100644 Oqtane.Server/Controllers/ProfileController.cs create mode 100644 Oqtane.Server/Repository/Interfaces/IProfileRepository.cs create mode 100644 Oqtane.Server/Repository/ProfileRepository.cs create mode 100644 Oqtane.Shared/Models/Profile.cs diff --git a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Index.razor b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Index.razor index 4d3f8de3..87c2beff 100644 --- a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Index.razor +++ b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Index.razor @@ -12,7 +12,7 @@ } else { - +
diff --git a/Oqtane.Client/Modules/Admin/ModuleSettings/Index.razor b/Oqtane.Client/Modules/Admin/ModuleSettings/Index.razor index 80ebca10..90fb186e 100644 --- a/Oqtane.Client/Modules/Admin/ModuleSettings/Index.razor +++ b/Oqtane.Client/Modules/Admin/ModuleSettings/Index.razor @@ -11,7 +11,8 @@ @inject IModuleService ModuleService @inject IPageModuleService PageModuleService -
Name
+
+ + + -
@@ -20,6 +21,8 @@
@@ -55,7 +58,8 @@
+ + @DynamicComponent diff --git a/Oqtane.Client/Modules/Admin/Pages/Add.razor b/Oqtane.Client/Modules/Admin/Pages/Add.razor index 14c3db9c..b5ea1d43 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Add.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Add.razor @@ -11,7 +11,8 @@ @inject IThemeService ThemeService - + +
diff --git a/Oqtane.Client/Modules/Admin/Pages/Delete.razor b/Oqtane.Client/Modules/Admin/Pages/Delete.razor index 5c5da1ff..a6327769 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Delete.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Delete.razor @@ -12,7 +12,7 @@ - +
diff --git a/Oqtane.Client/Modules/Admin/Pages/Edit.razor b/Oqtane.Client/Modules/Admin/Pages/Edit.razor index 43c64ee5..4eaa0287 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Edit.razor @@ -12,7 +12,7 @@ - +
diff --git a/Oqtane.Client/Modules/Admin/Pages/Index.razor b/Oqtane.Client/Modules/Admin/Pages/Index.razor index cd972c59..ad7f0afe 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Index.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Index.razor @@ -12,7 +12,7 @@ else { - +
diff --git a/Oqtane.Client/Modules/Admin/Profile/Index.razor b/Oqtane.Client/Modules/Admin/Profile/Index.razor new file mode 100644 index 00000000..32cebad4 --- /dev/null +++ b/Oqtane.Client/Modules/Admin/Profile/Index.razor @@ -0,0 +1,116 @@ +@using Microsoft.AspNetCore.Components.Routing +@using Oqtane.Client.Modules.Controls +@using Oqtane.Modules +@using Oqtane.Models +@using Oqtane.Services +@inherits ModuleBase +@inject IUriHelper UriHelper +@inject IUserService UserService +@inject IProfileService ProfileService +@inject ISettingService SettingService + + + +@if (profiles != null) +{ +
 
+ + + + + + + + + + @foreach (Profile profile in profiles) + { + var p = profile; + if (p.Category != category) + { + + + + category = p.Category; + } + + + + + } +
+ + + +
+ + + +
+ @p.Category +
+ + + +
+ + +} + +@code { + public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } } + + string message = ""; + string displayname = ""; + string email = ""; + List profiles; + List settings; + string category = ""; + + protected override async Task OnInitializedAsync() + { + try + { + displayname = PageState.User.DisplayName; + email = PageState.User.Email; + profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId); + settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId); + } + catch (Exception ex) + { + message = ex.Message; + } + } + + private string GetProfileValue(string SettingName, string DefaultValue) + { + return SettingService.GetSetting(settings, SettingName, DefaultValue); + } + + private async Task SaveUser() + { + User user = PageState.User; + user.DisplayName = displayname; + user.Email = email; + await UserService.UpdateUserAsync(user); + + foreach (Profile profile in profiles) + { + string value = SettingService.GetSetting(settings, profile.Name, ""); + await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId, profile.Name, value); + } + + UriHelper.NavigateTo(""); + } + + private void Cancel() + { + UriHelper.NavigateTo(NavigateUrl("")); // navigate to home + } + + private void ProfileChanged(UIChangeEventArgs e, string SettingName) + { + string value = (string)e.Value; + settings = SettingService.SetSetting(settings, "User", PageState.User.UserId, SettingName, value); + } +} diff --git a/Oqtane.Client/Modules/Admin/Roles/Index.razor b/Oqtane.Client/Modules/Admin/Roles/Index.razor index c21f185d..012f2052 100644 --- a/Oqtane.Client/Modules/Admin/Roles/Index.razor +++ b/Oqtane.Client/Modules/Admin/Roles/Index.razor @@ -11,7 +11,7 @@ } else { - +
diff --git a/Oqtane.Client/Modules/Admin/Sites/Add.razor b/Oqtane.Client/Modules/Admin/Sites/Add.razor index 48fc1dc5..d55e955f 100644 --- a/Oqtane.Client/Modules/Admin/Sites/Add.razor +++ b/Oqtane.Client/Modules/Admin/Sites/Add.razor @@ -17,7 +17,7 @@ } else { -
Name
+
+
diff --git a/Oqtane.Client/Modules/Admin/Sites/Index.razor b/Oqtane.Client/Modules/Admin/Sites/Index.razor index 8c57d292..f80dd108 100644 --- a/Oqtane.Client/Modules/Admin/Sites/Index.razor +++ b/Oqtane.Client/Modules/Admin/Sites/Index.razor @@ -12,7 +12,7 @@ } else { - +
diff --git a/Oqtane.Client/Modules/Admin/Themes/Index.razor b/Oqtane.Client/Modules/Admin/Themes/Index.razor index 743215ee..34855ec8 100644 --- a/Oqtane.Client/Modules/Admin/Themes/Index.razor +++ b/Oqtane.Client/Modules/Admin/Themes/Index.razor @@ -11,7 +11,7 @@ } else { -
Name
+
diff --git a/Oqtane.Client/Modules/Controls/PermissionGrid.razor b/Oqtane.Client/Modules/Controls/PermissionGrid.razor index f1762af4..e2f40f00 100644 --- a/Oqtane.Client/Modules/Controls/PermissionGrid.razor +++ b/Oqtane.Client/Modules/Controls/PermissionGrid.razor @@ -10,73 +10,71 @@ @if (roles != null) {
-
-
-
Name
- +
+ + + + @foreach (PermissionString permission in permissions) + { + + } + + @foreach (Role role in roles) + { + + + @foreach (PermissionString permission in permissions) + { + var p = permission; + + } + + } + +
Role@permission.PermissionName @EntityName
@role.Name + +
+ @if (@users.Count != 0) + { + + + + + @foreach (PermissionString permission in permissions) + { + + } + + + + @foreach (User user in users) + { + string userid = "[" + user.UserId.ToString() + "]"; - + @foreach (PermissionString permission in permissions) { - + var p = permission; + } - @foreach (Role role in roles) - { - - - @foreach (PermissionString permission in permissions) - { - var p = permission; - - } - - } - -
User@permission.PermissionName @EntityName
Role@user.DisplayName@permission.PermissionName @EntityName + +
@role.Name - -
- - @if (@users.Count != 0) - { -
- - - - - @foreach (PermissionString permission in permissions) - { - - } - - - - @foreach (User user in users) - { - string userid = "[" + user.UserId.ToString() + "]"; - - - @foreach (PermissionString permission in permissions) - { - var p = permission; - - } - - } - -
User@permission.PermissionName @EntityName
@user.DisplayName - -
-
- } -
- - - -
-
- - + } +
+ } + + + + + + + + +
+
+ } @code { diff --git a/Oqtane.Client/Services/Interfaces/IProfileService.cs b/Oqtane.Client/Services/Interfaces/IProfileService.cs new file mode 100644 index 00000000..e5f70bac --- /dev/null +++ b/Oqtane.Client/Services/Interfaces/IProfileService.cs @@ -0,0 +1,21 @@ +using Oqtane.Models; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Oqtane.Services +{ + public interface IProfileService + { + Task> GetProfilesAsync(); + + Task> GetProfilesAsync(int SiteId); + + Task GetProfileAsync(int ProfileId); + + Task AddProfileAsync(Profile Profile); + + Task UpdateProfileAsync(Profile Profile); + + Task DeleteProfileAsync(int ProfileId); + } +} diff --git a/Oqtane.Client/Services/Interfaces/ISettingService.cs b/Oqtane.Client/Services/Interfaces/ISettingService.cs index c6b617c5..56fccb43 100644 --- a/Oqtane.Client/Services/Interfaces/ISettingService.cs +++ b/Oqtane.Client/Services/Interfaces/ISettingService.cs @@ -26,6 +26,10 @@ namespace Oqtane.Services Task UpdateModuleSettingsAsync(List ModuleSettings, int ModuleId, string SettingName, string SettingValue); + Task> GetUserSettingsAsync(int UserId); + + Task UpdateUserSettingsAsync(List UserSettings, int UserId, string SettingName, string SettingValue); + Task> GetSettingsAsync(string EntityName, int EntityId); @@ -35,9 +39,13 @@ namespace Oqtane.Services Task UpdateSettingAsync(Setting Setting); + Task UpdateSettingsAsync(List Settings, string EntityName, int EntityId, string SettingName, string SettingValue); + Task DeleteSettingAsync(int SettingId); string GetSetting(List Settings, string SettingName, string DefaultValue); - } + + List SetSetting(List Settings, string EntityName, int EntityId, string SettingName, string SettingValue); + } } diff --git a/Oqtane.Client/Services/ProfileService.cs b/Oqtane.Client/Services/ProfileService.cs new file mode 100644 index 00000000..4024c143 --- /dev/null +++ b/Oqtane.Client/Services/ProfileService.cs @@ -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> GetProfilesAsync() + { + return await http.GetJsonAsync>(apiurl); + } + + public async Task> GetProfilesAsync(int SiteId) + { + List Profiles = await http.GetJsonAsync>(apiurl + "?siteid=" + SiteId.ToString()); + return Profiles.OrderBy(item => item.ViewOrder).ToList(); + } + + public async Task GetProfileAsync(int ProfileId) + { + return await http.GetJsonAsync(apiurl + "/" + ProfileId.ToString()); + } + + public async Task AddProfileAsync(Profile Profile) + { + return await http.PostJsonAsync(apiurl, Profile); + } + + public async Task UpdateProfileAsync(Profile Profile) + { + return await http.PutJsonAsync(apiurl + "/" + Profile.SiteId.ToString(), Profile); + } + public async Task DeleteProfileAsync(int ProfileId) + { + await http.DeleteAsync(apiurl + "/" + ProfileId.ToString()); + } + } +} diff --git a/Oqtane.Client/Services/SettingService.cs b/Oqtane.Client/Services/SettingService.cs index f6bfaac2..02a53dfe 100644 --- a/Oqtane.Client/Services/SettingService.cs +++ b/Oqtane.Client/Services/SettingService.cs @@ -33,22 +33,7 @@ namespace Oqtane.Services public async Task UpdateHostSettingsAsync(List 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> GetSiteSettingsAsync(int SiteId) @@ -58,22 +43,7 @@ namespace Oqtane.Services public async Task UpdateSiteSettingsAsync(List 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> GetPageSettingsAsync(int PageId) @@ -83,22 +53,7 @@ namespace Oqtane.Services public async Task UpdatePageSettingsAsync(List 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> GetPageModuleSettingsAsync(int PageModuleId) @@ -108,22 +63,7 @@ namespace Oqtane.Services public async Task UpdatePageModuleSettingsAsync(List 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> GetModuleSettingsAsync(int ModuleId) @@ -133,22 +73,17 @@ namespace Oqtane.Services public async Task UpdateModuleSettingsAsync(List 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> GetUserSettingsAsync(int UserId) + { + return await GetSettingsAsync("User", UserId); + } + + public async Task UpdateUserSettingsAsync(List UserSettings, int UserId, string SettingName, string SettingValue) + { + return await UpdateSettingsAsync(UserSettings, "User", UserId, SettingName, SettingValue); } public async Task> GetSettingsAsync(string EntityName, int EntityId) @@ -171,6 +106,27 @@ namespace Oqtane.Services { return await http.PutJsonAsync(apiurl + "/" + Setting.SettingId.ToString(), Setting); } + + public async Task UpdateSettingsAsync(List 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 SetSetting(List 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; + } } } diff --git a/Oqtane.Client/Startup.cs b/Oqtane.Client/Startup.cs index 754ca6ad..2b8f456b 100644 --- a/Oqtane.Client/Startup.cs +++ b/Oqtane.Client/Startup.cs @@ -46,6 +46,7 @@ namespace Oqtane.Client services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/Oqtane.Client/Themes/Controls/Profile.razor b/Oqtane.Client/Themes/Controls/Profile.razor index 0ff591a3..90808163 100644 --- a/Oqtane.Client/Themes/Controls/Profile.razor +++ b/Oqtane.Client/Themes/Controls/Profile.razor @@ -7,7 +7,7 @@ ... - + @@ -21,6 +21,11 @@ { UriHelper.NavigateTo(NavigateUrl("register")); } + + private void UpdateProfile() + { + UriHelper.NavigateTo(NavigateUrl("profile")); + } } diff --git a/Oqtane.Server/Controllers/ProfileController.cs b/Oqtane.Server/Controllers/ProfileController.cs new file mode 100644 index 00000000..7281b2a0 --- /dev/null +++ b/Oqtane.Server/Controllers/ProfileController.cs @@ -0,0 +1,73 @@ +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using Oqtane.Repository; +using Oqtane.Models; +using Oqtane.Shared; + +namespace Oqtane.Controllers +{ + [Route("{site}/api/[controller]")] + public class ProfileController : Controller + { + private readonly IProfileRepository Profiles; + + public ProfileController(IProfileRepository Profiles) + { + this.Profiles = Profiles; + } + + // GET: api/?siteid=x + [HttpGet] + public IEnumerable Get(string siteid) + { + if (siteid == "") + { + return Profiles.GetProfiles(); + } + else + { + return Profiles.GetProfiles(int.Parse(siteid)); + } + } + + // GET api//5 + [HttpGet("{id}")] + public Profile Get(int id) + { + return Profiles.GetProfile(id); + } + + // POST api/ + [HttpPost] + [Authorize(Roles = Constants.AdminRole)] + public Profile Post([FromBody] Profile Profile) + { + if (ModelState.IsValid) + { + Profile = Profiles.AddProfile(Profile); + } + return Profile; + } + + // PUT api//5 + [HttpPut("{id}")] + [Authorize(Roles = Constants.AdminRole)] + public Profile Put(int id, [FromBody] Profile Profile) + { + if (ModelState.IsValid) + { + Profile = Profiles.UpdateProfile(Profile); + } + return Profile; + } + + // DELETE api//5 + [HttpDelete("{id}")] + [Authorize(Roles = Constants.AdminRole)] + public void Delete(int id) + { + Profiles.DeleteProfile(id); + } + } +} diff --git a/Oqtane.Server/Repository/Context/TenantDBContext.cs b/Oqtane.Server/Repository/Context/TenantDBContext.cs index f214302b..6cf6a7b9 100644 --- a/Oqtane.Server/Repository/Context/TenantDBContext.cs +++ b/Oqtane.Server/Repository/Context/TenantDBContext.cs @@ -11,6 +11,7 @@ namespace Oqtane.Repository public virtual DbSet PageModule { get; set; } public virtual DbSet Module { get; set; } public virtual DbSet User { get; set; } + public virtual DbSet Profile { get; set; } public virtual DbSet SiteUser { get; set; } public virtual DbSet Role { get; set; } public virtual DbSet UserRole { get; set; } diff --git a/Oqtane.Server/Repository/Interfaces/IProfileRepository.cs b/Oqtane.Server/Repository/Interfaces/IProfileRepository.cs new file mode 100644 index 00000000..51f4c142 --- /dev/null +++ b/Oqtane.Server/Repository/Interfaces/IProfileRepository.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using Oqtane.Models; + +namespace Oqtane.Repository +{ + public interface IProfileRepository + { + IEnumerable GetProfiles(); + IEnumerable GetProfiles(int SiteId); + Profile AddProfile(Profile Profile); + Profile UpdateProfile(Profile Profile); + Profile GetProfile(int ProfileId); + void DeleteProfile(int ProfileId); + } +} diff --git a/Oqtane.Server/Repository/ProfileRepository.cs b/Oqtane.Server/Repository/ProfileRepository.cs new file mode 100644 index 00000000..b6902dda --- /dev/null +++ b/Oqtane.Server/Repository/ProfileRepository.cs @@ -0,0 +1,53 @@ +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Linq; +using Oqtane.Models; + +namespace Oqtane.Repository +{ + public class ProfileRepository : IProfileRepository + { + private TenantDBContext db; + + public ProfileRepository(TenantDBContext context) + { + db = context; + } + + public IEnumerable GetProfiles() + { + return db.Profile; + } + + public IEnumerable GetProfiles(int SiteId) + { + return db.Profile.Where(item => item.SiteId == SiteId); + } + + public Profile AddProfile(Profile Profile) + { + db.Profile.Add(Profile); + db.SaveChanges(); + return Profile; + } + + public Profile UpdateProfile(Profile Profile) + { + db.Entry(Profile).State = EntityState.Modified; + db.SaveChanges(); + return Profile; + } + + public Profile GetProfile(int ProfileId) + { + return db.Profile.Find(ProfileId); + } + + public void DeleteProfile(int ProfileId) + { + Profile Profile = db.Profile.Find(ProfileId); + db.Profile.Remove(Profile); + db.SaveChanges(); + } + } +} diff --git a/Oqtane.Server/Scripts/00.00.00.sql b/Oqtane.Server/Scripts/00.00.00.sql index 2f97a61e..406e9a23 100644 --- a/Oqtane.Server/Scripts/00.00.00.sql +++ b/Oqtane.Server/Scripts/00.00.00.sql @@ -183,6 +183,8 @@ CREATE TABLE [dbo].[Profile]( [ProfileId] [int] IDENTITY(1,1) NOT NULL, [SiteId] [int] NULL, [Name] [nvarchar](50) NOT NULL, + [Title] [nvarchar](50) NOT NULL, + [Description] [nvarchar](256) NULL, [Category] [nvarchar](50) NOT NULL, [ViewOrder] [int] NOT NULL, [MaxLength] [int] NOT NULL, @@ -378,6 +380,35 @@ GO SET IDENTITY_INSERT [dbo].[Role] OFF GO +SET IDENTITY_INSERT [dbo].[Profile] ON +GO +INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) +VALUES (1, 1, 'FirstName', 'First Name', 'Your First Or Given Name', 'Name', 1, 50, '', 1, 0, '', getdate(), '', getdate()) +GO +INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) +VALUES (2, 1, 'LastName', 'Last Name', 'Your Last Or family Name', 'Name', 2, 50, '', 1, 0, '', getdate(), '', getdate()) +GO +INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) +VALUES (3, 1, 'Street', 'Street', 'Street Or Building Address', 'Address', 3, 50, '', 1, 0, '', getdate(), '', getdate()) +GO +INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) +VALUES (4, 1, 'City', 'City', 'City', 'Address', 4, 50, '', 1, 0, '', getdate(), '', getdate()) +GO +INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) +VALUES (5, 1, 'Region', 'Region', 'State Or Province', 'Address', 5, 50, '', 1, 0, '', getdate(), '', getdate()) +GO +INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) +VALUES (6, 1, 'Country', 'Country', 'Country', 'Address', 6, 50, '', 1, 0, '', getdate(), '', getdate()) +GO +INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) +VALUES (7, 1, 'PostalCode', 'Postal Code', 'Postal Code Or Zip Code', 'Address', 7, 50, '', 1, 0, '', getdate(), '', getdate()) +GO +INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) +VALUES (8, 1, 'Phone', 'Phone Number', 'Phone Number', 'Contact', 8, 50, '', 1, 0, '', getdate(), '', getdate()) +GO +SET IDENTITY_INSERT [dbo].[Profile] OFF +GO + SET IDENTITY_INSERT [dbo].[Page] ON GO INSERT [dbo].[Page] ([PageId], [SiteId], [Name], [Path], [ThemeType], [Icon], [Panes], [ParentId], [Order], [IsNavigation], [LayoutType], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) @@ -508,6 +539,15 @@ INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], GO INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Page', 16, 'Edit', 1, null, 1, '', getdate(), '', getdate()) GO +INSERT [dbo].[Page] ([PageId], [SiteId], [Name], [Path], [ThemeType], [Icon], [Panes], [ParentId], [Order], [IsNavigation], [LayoutType], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) +VALUES (17, 1, N'Profile', N'profile', N'Oqtane.Client.Themes.Theme2.Theme2, Oqtane.Client', N'', N'Top;Bottom', NULL, 1, 0, N'', '', getdate(), '', getdate()) +GO +INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Page', 17, 'View', -1, null, 1, '', getdate(), '', getdate()) +GO +INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Page', 17, 'View', 1, null, 1, '', getdate(), '', getdate()) +GO +INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Page', 17, 'Edit', 1, null, 1, '', getdate(), '', getdate()) +GO SET IDENTITY_INSERT [dbo].[Page] OFF GO @@ -677,6 +717,15 @@ INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], GO INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Module', 20, 'Edit', 1, null, 1, '', getdate(), '', getdate()) GO +INSERT [dbo].[Module] ([ModuleId], [SiteId], [ModuleDefinitionName], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) +VALUES (21, 1, N'Oqtane.Client.Modules.Admin.Profile, Oqtane.Client', '', getdate(), '', getdate()) +GO +INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Module', 21, 'View', -1, null, 1, '', getdate(), '', getdate()) +GO +INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Module', 21, 'View', 1, null, 1, '', getdate(), '', getdate()) +GO +INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Module', 21, 'Edit', 1, null, 1, '', getdate(), '', getdate()) +GO SET IDENTITY_INSERT [dbo].[Module] OFF GO @@ -742,6 +791,9 @@ GO INSERT [dbo].[PageModule] ([PageModuleId], [PageId], [ModuleId], [Title], [Pane], [Order], [ContainerType], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (20, 16, 20, N'Role Management', N'Top', 0, N'Oqtane.Client.Themes.Theme2.Container2, Oqtane.Client', '', getdate(), '', getdate()) GO +INSERT [dbo].[PageModule] ([PageModuleId], [PageId], [ModuleId], [Title], [Pane], [Order], [ContainerType], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) +VALUES (21, 17, 21, N'User Profile', N'Top', 0, N'Oqtane.Client.Themes.Theme2.Container2, Oqtane.Client', '', getdate(), '', getdate()) +GO SET IDENTITY_INSERT [dbo].[PageModule] OFF GO diff --git a/Oqtane.Server/Startup.cs b/Oqtane.Server/Startup.cs index 4b441aff..516e63cb 100644 --- a/Oqtane.Server/Startup.cs +++ b/Oqtane.Server/Startup.cs @@ -91,6 +91,7 @@ namespace Oqtane.Server services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -178,6 +179,7 @@ namespace Oqtane.Server services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/Oqtane.Shared/Models/Profile.cs b/Oqtane.Shared/Models/Profile.cs new file mode 100644 index 00000000..cd82553f --- /dev/null +++ b/Oqtane.Shared/Models/Profile.cs @@ -0,0 +1,24 @@ +using System; + +namespace Oqtane.Models +{ + public class Profile : IAuditable + { + public int ProfileId { get; set; } + public int SiteId { get; set; } + public string Name { get; set; } + public string Title { get; set; } + public string Description { get; set; } + public string Category { get; set; } + public int ViewOrder { get; set; } + public int MaxLength { get; set; } + public string DefaultValue { get; set; } + public bool IsRequired { get; set; } + public bool IsPrivate { get; set; } + + public string CreatedBy { get; set; } + public DateTime CreatedOn { get; set; } + public string ModifiedBy { get; set; } + public DateTime ModifiedOn { get; set; } + } +}