notification service and user management improvements

This commit is contained in:
Shaun Walker
2020-02-03 16:43:37 -05:00
parent d8d5e768b2
commit 0aed11e71c
50 changed files with 2077 additions and 284 deletions

View File

@ -0,0 +1,93 @@
using Oqtane.Models;
using System.Threading.Tasks;
using System.Linq;
using System.Net.Http;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using Oqtane.Shared;
using System;
namespace Oqtane.Services
{
public class FolderService : ServiceBase, IFolderService
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly NavigationManager NavigationManager;
public FolderService(HttpClient http, SiteState sitestate, NavigationManager NavigationManager)
{
this.http = http;
this.sitestate = sitestate;
this.NavigationManager = NavigationManager;
}
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, NavigationManager.Uri, "Folder"); }
}
public async Task<List<Folder>> GetFoldersAsync(int SiteId)
{
List<Folder> folders = await http.GetJsonAsync<List<Folder>>(apiurl + "?siteid=" + SiteId.ToString());
folders = GetFoldersHierarchy(folders);
return folders;
}
public async Task<Folder> GetFolderAsync(int FolderId)
{
return await http.GetJsonAsync<Folder>(apiurl + "/" + FolderId.ToString());
}
public async Task<Folder> AddFolderAsync(Folder Folder)
{
return await http.PostJsonAsync<Folder>(apiurl, Folder);
}
public async Task<Folder> UpdateFolderAsync(Folder Folder)
{
return await http.PutJsonAsync<Folder>(apiurl + "/" + Folder.FolderId.ToString(), Folder);
}
public async Task UpdateFolderOrderAsync(int SiteId, int FolderId, int? ParentId)
{
await http.PutJsonAsync(apiurl + "/?siteid=" + SiteId.ToString() + "&folderid=" + FolderId.ToString() + "&parentid=" + ((ParentId == null) ? "" : ParentId.ToString()), null);
}
public async Task DeleteFolderAsync(int FolderId)
{
await http.DeleteAsync(apiurl + "/" + FolderId.ToString());
}
private static List<Folder> GetFoldersHierarchy(List<Folder> Folders)
{
List<Folder> hierarchy = new List<Folder>();
Action<List<Folder>, Folder> GetPath = null;
GetPath = (List<Folder> folders, Folder folder) =>
{
IEnumerable<Folder> children;
int level;
if (folder == null)
{
level = -1;
children = Folders.Where(item => item.ParentId == null);
}
else
{
level = folder.Level;
children = Folders.Where(item => item.ParentId == folder.FolderId);
}
foreach (Folder child in children)
{
child.Level = level + 1;
child.HasChildren = Folders.Where(item => item.ParentId == child.FolderId).Any();
hierarchy.Add(child);
GetPath(folders, child);
}
};
Folders = Folders.OrderBy(item => item.Order).ToList();
GetPath(Folders, null);
return hierarchy;
}
}
}

View File

@ -0,0 +1,16 @@
using Oqtane.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Oqtane.Services
{
public interface IFolderService
{
Task<List<Folder>> GetFoldersAsync(int SiteId);
Task<Folder> GetFolderAsync(int FolderId);
Task<Folder> AddFolderAsync(Folder Folder);
Task<Folder> UpdateFolderAsync(Folder Folder);
Task UpdateFolderOrderAsync(int SiteId, int FolderId, int? ParentId);
Task DeleteFolderAsync(int FolderId);
}
}

View File

@ -0,0 +1,19 @@
using Oqtane.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Oqtane.Services
{
public interface INotificationService
{
Task<List<Notification>> GetNotificationsAsync(int SiteId, string Direction, int UserId);
Task<Notification> GetNotificationAsync(int NotificationId);
Task<Notification> AddNotificationAsync(Notification Notification);
Task<Notification> UpdateNotificationAsync(Notification Notification);
Task DeleteNotificationAsync(int NotificationId);
}
}

View File

@ -23,5 +23,9 @@ namespace Oqtane.Services
Task<User> LoginUserAsync(User User, bool SetCookie, bool IsPersistent);
Task LogoutUserAsync(User User);
Task ForgotPasswordAsync(User User);
Task<User> ResetPasswordAsync(User User, string Token);
}
}

View File

@ -0,0 +1,55 @@
using Oqtane.Models;
using System.Threading.Tasks;
using System.Net.Http;
using Microsoft.AspNetCore.Components;
using Oqtane.Shared;
using System.Collections.Generic;
using System.Linq;
namespace Oqtane.Services
{
public class NotificationService : ServiceBase, INotificationService
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly NavigationManager NavigationManager;
public NotificationService(HttpClient http, SiteState sitestate, NavigationManager NavigationManager)
{
this.http = http;
this.sitestate = sitestate;
this.NavigationManager = NavigationManager;
}
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, NavigationManager.Uri, "Notification"); }
}
public async Task<List<Notification>> GetNotificationsAsync(int SiteId, string Direction, int UserId)
{
string querystring = "?siteid=" + SiteId.ToString() + "&direction=" + Direction.ToLower() + "&userid=" + UserId.ToString();
List<Notification> Notifications = await http.GetJsonAsync<List<Notification>>(apiurl + querystring);
return Notifications.OrderByDescending(item => item.CreatedOn).ToList();
}
public async Task<Notification> GetNotificationAsync(int NotificationId)
{
return await http.GetJsonAsync<Notification>(apiurl + "/" + NotificationId.ToString());
}
public async Task<Notification> AddNotificationAsync(Notification Notification)
{
return await http.PostJsonAsync<Notification>(apiurl, Notification);
}
public async Task<Notification> UpdateNotificationAsync(Notification Notification)
{
return await http.PutJsonAsync<Notification>(apiurl + "/" + Notification.NotificationId.ToString(), Notification);
}
public async Task DeleteNotificationAsync(int NotificationId)
{
await http.DeleteAsync(apiurl + "/" + NotificationId.ToString());
}
}
}

View File

@ -50,7 +50,7 @@ namespace Oqtane.Services
public async Task<Role> UpdateRoleAsync(Role Role)
{
return await http.PutJsonAsync<Role>(apiurl + "/" + Role.SiteId.ToString(), Role);
return await http.PutJsonAsync<Role>(apiurl + "/" + Role.RoleId.ToString(), Role);
}
public async Task DeleteRoleAsync(int RoleId)
{

View File

@ -86,5 +86,16 @@ namespace Oqtane.Services
// best practices recommend post is preferrable to get for logout
await http.PostJsonAsync(apiurl + "/logout", User);
}
public async Task ForgotPasswordAsync(User User)
{
await http.PostJsonAsync(apiurl + "/forgot", User);
}
public async Task<User> ResetPasswordAsync(User User, string Token)
{
return await http.PostJsonAsync<User>(apiurl + "/reset?token=" + Token, User);
}
}
}