Merge pull request #70 from sbwalker/master

Dynamic user profile per tenant
This commit is contained in:
Shaun Walker 2019-09-03 20:40:50 -04:00 committed by GitHub
commit 26dc7c7fb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 558 additions and 155 deletions

View File

@ -12,7 +12,7 @@
} }
else else
{ {
<table class="table"> <table class="table table-borderless">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>

View File

@ -11,7 +11,8 @@
@inject IModuleService ModuleService @inject IModuleService ModuleService
@inject IPageModuleService PageModuleService @inject IPageModuleService PageModuleService
<table class="form-group"> <table class="table table-borderless">
<thead>
<tr> <tr>
<td> <td>
<label for="Title" class="control-label">Title: </label> <label for="Title" class="control-label">Title: </label>
@ -20,6 +21,8 @@
<input type="text" name="Title" class="form-control" @bind="@title" /> <input type="text" name="Title" class="form-control" @bind="@title" />
</td> </td>
</tr> </tr>
</thead>
<tbody>
<tr> <tr>
<td> <td>
<label for="Container" class="control-label">Container: </label> <label for="Container" class="control-label">Container: </label>
@ -55,7 +58,8 @@
</select> </select>
</td> </td>
</tr> </tr>
</table> </tbody>
</table>
@DynamicComponent @DynamicComponent

View File

@ -11,7 +11,8 @@
@inject IThemeService ThemeService @inject IThemeService ThemeService
<ModuleMessage Message="@message" /> <ModuleMessage Message="@message" />
<table class="form-group">
<table class="table table-borderless">
<tr> <tr>
<td> <td>
<label for="Name" class="control-label">Name: </label> <label for="Name" class="control-label">Name: </label>

View File

@ -12,7 +12,7 @@
<ModuleMessage Message="@message" /> <ModuleMessage Message="@message" />
<table class="form-group"> <table class="table table-borderless">
<tr> <tr>
<td> <td>
<label for="Name" class="control-label">Name: </label> <label for="Name" class="control-label">Name: </label>

View File

@ -12,7 +12,7 @@
<ModuleMessage Message="@message" /> <ModuleMessage Message="@message" />
<table class="form-group"> <table class="table table-borderless">
<tr> <tr>
<td> <td>
<label for="Name" class="control-label">Name: </label> <label for="Name" class="control-label">Name: </label>

View File

@ -12,7 +12,7 @@
else else
{ {
<ActionLink Action="Add" Text="Add Page" Style="float: right; margin: 10px;" /> <ActionLink Action="Add" Text="Add Page" Style="float: right; margin: 10px;" />
<table class="table"> <table class="table table-borderless">
<thead> <thead>
<tr> <tr>
<th>&nbsp;</th> <th>&nbsp;</th>

View File

@ -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
<ModuleMessage Message="@message" />
@if (profiles != null)
{
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Name: </label>
</td>
<td>
<input class="form-control" @bind="@displayname" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Email: </label>
</td>
<td>
<input class="form-control" @bind="@email" />
</td>
</tr>
@foreach (Profile profile in profiles)
{
var p = profile;
if (p.Category != category)
{
<tr>
<th colspan="2" style="text-align: center;">
@p.Category
</th>
</tr>
category = p.Category;
}
<tr>
<td>
<label for="@p.Name" class="control-label">@p.Title: </label>
</td>
<td>
<input class="form-control" maxlength="@p.MaxLength" value="@GetProfileValue(p.Name, p.DefaultValue)" @onchange="@(e => ProfileChanged(e, p.Name))" />
</td>
</tr>
}
</table>
<button type="button" class="btn btn-primary" @onclick="@SaveUser">Save</button>
<button type="button" class="btn btn-secondary" @onclick="@Cancel">Cancel</button>
}
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } }
string message = "";
string displayname = "";
string email = "";
List<Profile> profiles;
List<Setting> 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);
}
}

View File

@ -11,7 +11,7 @@
} }
else else
{ {
<table class="table"> <table class="table table-borderless">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>

View File

@ -17,7 +17,7 @@
} }
else else
{ {
<table class="form-group"> <table class="table table-borderless">
<tr> <tr>
<td> <td>
<label for="Name" class="control-label">Tenant: </label> <label for="Name" class="control-label">Tenant: </label>

View File

@ -12,7 +12,7 @@
} }
else else
{ {
<table class="table"> <table class="table table-borderless">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>

View File

@ -11,7 +11,7 @@
} }
else else
{ {
<table class="table"> <table class="table table-borderless">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>

View File

@ -10,73 +10,71 @@
@if (roles != null) @if (roles != null)
{ {
<br /> <br />
<div class="container"> <table class="table">
<div class="form-group"> <tbody>
<table class="table"> <tr>
<tbody> <th>Role</th>
@foreach (PermissionString permission in permissions)
{
<th style="text-align: center;">@permission.PermissionName @EntityName</th>
}
</tr>
@foreach (Role role in roles)
{
<tr>
<td>@role.Name</td>
@foreach (PermissionString permission in permissions)
{
var p = permission;
<td style="text-align: center;">
<TriStateCheckBox Value=@GetPermissionValue(p.Permissions, role.Name) Disabled=@GetPermissionDisabled(role.Name) OnChange="@(e => PermissionChanged(e, p.PermissionName, role.Name))" />
</td>
}
</tr>
}
</tbody>
</table>
@if (@users.Count != 0)
{
<table class="table">
<thead>
<tr>
<th>User</th>
@foreach (PermissionString permission in permissions)
{
<th style="text-align: center;">@permission.PermissionName @EntityName</th>
}
</tr>
</thead>
<tbody>
@foreach (User user in users)
{
string userid = "[" + user.UserId.ToString() + "]";
<tr> <tr>
<th>Role</th> <td>@user.DisplayName</td>
@foreach (PermissionString permission in permissions) @foreach (PermissionString permission in permissions)
{ {
<th>@permission.PermissionName @EntityName</th> var p = permission;
<td style="text-align: center;">
<TriStateCheckBox Value=@GetPermissionValue(p.Permissions, userid) Disabled=@GetPermissionDisabled(userid) OnChange="@(e => PermissionChanged(e, p.PermissionName, userid))" />
</td>
} }
</tr> </tr>
@foreach (Role role in roles) }
{ </tbody>
<tr> </table>
<td>@role.Name</td> }
@foreach (PermissionString permission in permissions) <table class="table">
{ <tbody>
var p = permission; <tr>
<td align="center"> <td><label for="Username" class="control-label">User: </label></td>
<TriStateCheckBox Value=@GetPermissionValue(p.Permissions, role.Name) Disabled=@GetPermissionDisabled(role.Name) OnChange="@(e => PermissionChanged(e, p.PermissionName, role.Name))" /> <td><input type="text" name="Username" class="form-control" placeholder="Enter Username" @bind="@username" /></td>
</td> <td><button type="button" class="btn btn-primary" @onclick="@AddUser">Add</button></td>
} </tr>
</tr> </tbody>
} </table>
</tbody> <br />
</table> <ModuleMessage Type="MessageType.Error" Message="@message" />
</div>
@if (@users.Count != 0)
{
<div class="form-group">
<table class="table">
<thead>
<tr>
<th>User</th>
@foreach (PermissionString permission in permissions)
{
<th>@permission.PermissionName @EntityName</th>
}
</tr>
</thead>
<tbody>
@foreach (User user in users)
{
string userid = "[" + user.UserId.ToString() + "]";
<tr>
<td>@user.DisplayName</td>
@foreach (PermissionString permission in permissions)
{
var p = permission;
<td align="center">
<TriStateCheckBox Value=@GetPermissionValue(p.Permissions, userid) Disabled=@GetPermissionDisabled(userid) OnChange="@(e => PermissionChanged(e, p.PermissionName, userid))" />
</td>
}
</tr>
}
</tbody>
</table>
</div>
}
<div style="white-space:nowrap;">
<label for="Username" class="control-label" style="display:inline-block;">User: </label>
<input type="text" name="Username" class="form-control" style="display:inline-block; width: auto !important;" placeholder="Enter Username" @bind="@username" />
<button type="button" class="btn btn-primary" style="display:inline-block;" @onclick="@AddUser">Add</button>
</div>
<br />
<ModuleMessage Type="MessageType.Error" Message="@message" />
</div>
} }
@code { @code {

View 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);
}
}

View File

@ -26,6 +26,10 @@ namespace Oqtane.Services
Task<Setting> UpdateModuleSettingsAsync(List<Setting> ModuleSettings, int ModuleId, string SettingName, string SettingValue); 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); Task<List<Setting>> GetSettingsAsync(string EntityName, int EntityId);
@ -35,9 +39,13 @@ namespace Oqtane.Services
Task<Setting> UpdateSettingAsync(Setting Setting); Task<Setting> UpdateSettingAsync(Setting Setting);
Task<Setting> UpdateSettingsAsync(List<Setting> Settings, string EntityName, int EntityId, string SettingName, string SettingValue);
Task DeleteSettingAsync(int SettingId); Task DeleteSettingAsync(int SettingId);
string GetSetting(List<Setting> Settings, string SettingName, string DefaultValue); string GetSetting(List<Setting> Settings, string SettingName, string DefaultValue);
}
List<Setting> SetSetting(List<Setting> Settings, string EntityName, int EntityId, string SettingName, string SettingValue);
}
} }

View 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());
}
}
}

View File

@ -33,22 +33,7 @@ namespace Oqtane.Services
public async Task<Setting> UpdateHostSettingsAsync(List<Setting> HostSettings, string SettingName, string SettingValue) public async Task<Setting> UpdateHostSettingsAsync(List<Setting> HostSettings, string SettingName, string SettingValue)
{ {
Setting setting = HostSettings.Where(item => item.SettingName == SettingName).FirstOrDefault(); return await UpdateSettingsAsync(HostSettings, "Host", -1, SettingName, SettingValue);
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;
} }
public async Task<List<Setting>> GetSiteSettingsAsync(int SiteId) 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) public async Task<Setting> UpdateSiteSettingsAsync(List<Setting> SiteSettings, int SiteId, string SettingName, string SettingValue)
{ {
Setting setting = SiteSettings.Where(item => item.SettingName == SettingName).FirstOrDefault(); return await UpdateSettingsAsync(SiteSettings, "Site", SiteId, SettingName, SettingValue);
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;
} }
public async Task<List<Setting>> GetPageSettingsAsync(int PageId) 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) public async Task<Setting> UpdatePageSettingsAsync(List<Setting> PageSettings, int PageId, string SettingName, string SettingValue)
{ {
Setting setting = PageSettings.Where(item => item.SettingName == SettingName).FirstOrDefault(); return await UpdateSettingsAsync(PageSettings, "Page", PageId, SettingName, SettingValue);
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;
} }
public async Task<List<Setting>> GetPageModuleSettingsAsync(int PageModuleId) 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) public async Task<Setting> UpdatePageModuleSettingsAsync(List<Setting> PageModuleSettings, int PageModuleId, string SettingName, string SettingValue)
{ {
Setting setting = PageModuleSettings.Where(item => item.SettingName == SettingName).FirstOrDefault(); return await UpdateSettingsAsync(PageModuleSettings, "PageModule", PageModuleId, SettingName, SettingValue);
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;
} }
public async Task<List<Setting>> GetModuleSettingsAsync(int ModuleId) 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) public async Task<Setting> UpdateModuleSettingsAsync(List<Setting> ModuleSettings, int ModuleId, string SettingName, string SettingValue)
{ {
Setting setting = ModuleSettings.Where(item => item.SettingName == SettingName).FirstOrDefault(); return await UpdateSettingsAsync(ModuleSettings, "Module", ModuleId, SettingName, SettingValue);
if (setting == null) }
{
setting = new Setting(); public async Task<List<Setting>> GetUserSettingsAsync(int UserId)
setting.EntityName = "Module"; {
setting.EntityId = ModuleId; return await GetSettingsAsync("User", UserId);
setting.SettingName = SettingName; }
setting.SettingValue = SettingValue;
setting = await AddSettingAsync(setting); public async Task<Setting> UpdateUserSettingsAsync(List<Setting> UserSettings, int UserId, string SettingName, string SettingValue)
} {
else return await UpdateSettingsAsync(UserSettings, "User", UserId, SettingName, SettingValue);
{
setting.SettingValue = SettingValue;
setting = await UpdateSettingAsync(setting);
}
return setting;
} }
public async Task<List<Setting>> GetSettingsAsync(string EntityName, int EntityId) 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); 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) public async Task DeleteSettingAsync(int SettingId)
{ {
await http.DeleteAsync(apiurl + "/" + SettingId.ToString()); await http.DeleteAsync(apiurl + "/" + SettingId.ToString());
@ -187,5 +143,19 @@ namespace Oqtane.Services
} }
return value; 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;
}
} }
} }

View File

@ -46,6 +46,7 @@ namespace Oqtane.Client
services.AddScoped<IModuleService, ModuleService>(); services.AddScoped<IModuleService, ModuleService>();
services.AddScoped<IPageModuleService, PageModuleService>(); services.AddScoped<IPageModuleService, PageModuleService>();
services.AddScoped<IUserService, UserService>(); services.AddScoped<IUserService, UserService>();
services.AddScoped<IProfileService, ProfileService>();
services.AddScoped<IRoleService, RoleService>(); services.AddScoped<IRoleService, RoleService>();
services.AddScoped<IUserRoleService, UserRoleService>(); services.AddScoped<IUserRoleService, UserRoleService>();
services.AddScoped<ISettingService, SettingService>(); services.AddScoped<ISettingService, SettingService>();

View File

@ -7,7 +7,7 @@
<text>...</text> <text>...</text>
</Authorizing> </Authorizing>
<Authorized> <Authorized>
<button type="button" class="btn btn-primary" @onclick="@RegisterUser">@context.User.Identity.Name</button> <button type="button" class="btn btn-primary" @onclick="@UpdateProfile">@context.User.Identity.Name</button>
</Authorized> </Authorized>
<NotAuthorized> <NotAuthorized>
<button type="button" class="btn btn-primary" @onclick="@RegisterUser">Register</button> <button type="button" class="btn btn-primary" @onclick="@RegisterUser">Register</button>
@ -21,6 +21,11 @@
{ {
UriHelper.NavigateTo(NavigateUrl("register")); UriHelper.NavigateTo(NavigateUrl("register"));
} }
private void UpdateProfile()
{
UriHelper.NavigateTo(NavigateUrl("profile"));
}
} }

View File

@ -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/<controller>?siteid=x
[HttpGet]
public IEnumerable<Profile> Get(string siteid)
{
if (siteid == "")
{
return Profiles.GetProfiles();
}
else
{
return Profiles.GetProfiles(int.Parse(siteid));
}
}
// GET api/<controller>/5
[HttpGet("{id}")]
public Profile Get(int id)
{
return Profiles.GetProfile(id);
}
// POST api/<controller>
[HttpPost]
[Authorize(Roles = Constants.AdminRole)]
public Profile Post([FromBody] Profile Profile)
{
if (ModelState.IsValid)
{
Profile = Profiles.AddProfile(Profile);
}
return Profile;
}
// PUT api/<controller>/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/<controller>/5
[HttpDelete("{id}")]
[Authorize(Roles = Constants.AdminRole)]
public void Delete(int id)
{
Profiles.DeleteProfile(id);
}
}
}

View File

@ -11,6 +11,7 @@ namespace Oqtane.Repository
public virtual DbSet<PageModule> PageModule { get; set; } public virtual DbSet<PageModule> PageModule { get; set; }
public virtual DbSet<Module> Module { get; set; } public virtual DbSet<Module> Module { get; set; }
public virtual DbSet<User> User { get; set; } public virtual DbSet<User> User { get; set; }
public virtual DbSet<Profile> Profile { get; set; }
public virtual DbSet<SiteUser> SiteUser { get; set; } public virtual DbSet<SiteUser> SiteUser { get; set; }
public virtual DbSet<Role> Role { get; set; } public virtual DbSet<Role> Role { get; set; }
public virtual DbSet<UserRole> UserRole { get; set; } public virtual DbSet<UserRole> UserRole { get; set; }

View File

@ -0,0 +1,15 @@
using System.Collections.Generic;
using Oqtane.Models;
namespace Oqtane.Repository
{
public interface IProfileRepository
{
IEnumerable<Profile> GetProfiles();
IEnumerable<Profile> GetProfiles(int SiteId);
Profile AddProfile(Profile Profile);
Profile UpdateProfile(Profile Profile);
Profile GetProfile(int ProfileId);
void DeleteProfile(int ProfileId);
}
}

View File

@ -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<Profile> GetProfiles()
{
return db.Profile;
}
public IEnumerable<Profile> 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();
}
}
}

View File

@ -183,6 +183,8 @@ CREATE TABLE [dbo].[Profile](
[ProfileId] [int] IDENTITY(1,1) NOT NULL, [ProfileId] [int] IDENTITY(1,1) NOT NULL,
[SiteId] [int] NULL, [SiteId] [int] NULL,
[Name] [nvarchar](50) NOT NULL, [Name] [nvarchar](50) NOT NULL,
[Title] [nvarchar](50) NOT NULL,
[Description] [nvarchar](256) NULL,
[Category] [nvarchar](50) NOT NULL, [Category] [nvarchar](50) NOT NULL,
[ViewOrder] [int] NOT NULL, [ViewOrder] [int] NOT NULL,
[MaxLength] [int] NOT NULL, [MaxLength] [int] NOT NULL,
@ -378,6 +380,35 @@ GO
SET IDENTITY_INSERT [dbo].[Role] OFF SET IDENTITY_INSERT [dbo].[Role] OFF
GO 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 SET IDENTITY_INSERT [dbo].[Page] ON
GO GO
INSERT [dbo].[Page] ([PageId], [SiteId], [Name], [Path], [ThemeType], [Icon], [Panes], [ParentId], [Order], [IsNavigation], [LayoutType], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) 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 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()) 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 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 SET IDENTITY_INSERT [dbo].[Page] OFF
GO GO
@ -677,6 +717,15 @@ INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName],
GO 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()) 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 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 SET IDENTITY_INSERT [dbo].[Module] OFF
GO GO
@ -742,6 +791,9 @@ GO
INSERT [dbo].[PageModule] ([PageModuleId], [PageId], [ModuleId], [Title], [Pane], [Order], [ContainerType], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) 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()) VALUES (20, 16, 20, N'Role Management', N'Top', 0, N'Oqtane.Client.Themes.Theme2.Container2, Oqtane.Client', '', getdate(), '', getdate())
GO 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 SET IDENTITY_INSERT [dbo].[PageModule] OFF
GO GO

View File

@ -91,6 +91,7 @@ namespace Oqtane.Server
services.AddScoped<IModuleService, ModuleService>(); services.AddScoped<IModuleService, ModuleService>();
services.AddScoped<IPageModuleService, PageModuleService>(); services.AddScoped<IPageModuleService, PageModuleService>();
services.AddScoped<IUserService, UserService>(); services.AddScoped<IUserService, UserService>();
services.AddScoped<IProfileService, ProfileService>();
services.AddScoped<IRoleService, RoleService>(); services.AddScoped<IRoleService, RoleService>();
services.AddScoped<IUserRoleService, UserRoleService>(); services.AddScoped<IUserRoleService, UserRoleService>();
services.AddScoped<ISettingService, SettingService>(); services.AddScoped<ISettingService, SettingService>();
@ -178,6 +179,7 @@ namespace Oqtane.Server
services.AddTransient<IModuleRepository, ModuleRepository>(); services.AddTransient<IModuleRepository, ModuleRepository>();
services.AddTransient<IPageModuleRepository, PageModuleRepository>(); services.AddTransient<IPageModuleRepository, PageModuleRepository>();
services.AddTransient<IUserRepository, UserRepository>(); services.AddTransient<IUserRepository, UserRepository>();
services.AddTransient<IProfileRepository, ProfileRepository>();
services.AddTransient<ISiteUserRepository, SiteUserRepository>(); services.AddTransient<ISiteUserRepository, SiteUserRepository>();
services.AddTransient<IRoleRepository, RoleRepository>(); services.AddTransient<IRoleRepository, RoleRepository>();
services.AddTransient<IUserRoleRepository, UserRoleRepository>(); services.AddTransient<IUserRoleRepository, UserRoleRepository>();

View File

@ -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; }
}
}