v1.1.8
This commit is contained in:
@@ -59,6 +59,10 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Ensure data is paged to avoid leaking large volumes.
|
||||
model.Paging.PageNo = Math.Max(1, model.Paging.PageNo);
|
||||
model.Paging.PageLength = Math.Max(Math.Min(Sax.Config.Online.Search.Organisations.PageLengthMax, model.Paging.PageLength), (ushort)1);
|
||||
|
||||
// Query organisations that user is a member of.
|
||||
SaxOrganisation.Params prmOrganisation = new SaxOrganisation.Params();
|
||||
prmOrganisation.OrganisationFilter = model.Filter.Organisation;
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Saxonite.Net.Core.Web.Online.Models;
|
||||
using Saxonite.Net.Core.Web.Base.App;
|
||||
using Saxonite.Net.Core.Web.Base.Controllers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
// Online Search Controller - Users - Ajax actions.
|
||||
//=======================================================================
|
||||
partial class SearchController
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Account - Get Users.
|
||||
//-------------------------------------------------------------------
|
||||
private class UserListData
|
||||
{
|
||||
public String Id { get; set; }
|
||||
public String Name { get; set; }
|
||||
public String Location { get; set; }
|
||||
}
|
||||
private class AjaxResponse_Search_Users : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_Search_Users(SaxModel_Online model) : base(model) { }
|
||||
// User list.
|
||||
public List<UserListData> Users { get; } = new List<UserListData>();
|
||||
}
|
||||
// Ajax request.
|
||||
[HttpPost]
|
||||
[Route("Search/Ajax/Users")]
|
||||
[Route("Search/Ajax/GetUsers")]
|
||||
public IActionResult GetProfileUsers(Model_Search_Users model)
|
||||
{
|
||||
String fn = GetType().Name + ".GetProfileUsers";
|
||||
AjaxResponse_Search_Users responseData = new AjaxResponse_Search_Users(model);
|
||||
String messageTitle = Localiser["label.users"];
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Ensure filter has something to restrict the list.
|
||||
// ToDo May be able to show some results, such as friends when no filter provided.
|
||||
if (StringUtil.IsEmpty(StringUtil.TrimAll(model.Filter.User)))
|
||||
{
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
// Ensure data is paged to avoid leaking large volumes.
|
||||
model.Paging.PageNo = Math.Max(1, model.Paging.PageNo);
|
||||
model.Paging.PageLength = Math.Max(Math.Min(Sax.Config.Online.Search.Users.PageLengthMax, model.Paging.PageLength), (ushort)1);
|
||||
|
||||
// Query users that user is a member of.
|
||||
SaxUserAccount.Params prmUserAccount = new SaxUserAccount.Params();
|
||||
prmUserAccount.UserFilter = model.Filter.User;
|
||||
if (SysId.IsValid(model.FilterSportId))
|
||||
prmUserAccount.SportIdsIncluded.Add(model.FilterSportId);
|
||||
if (SysId.IsValid(model.FilterRegionId))
|
||||
prmUserAccount.RegionIdsIncluded.Add(model.FilterRegionId);
|
||||
prmUserAccount.StatusCat = SaxUserAccount.StatusCat.ActiveOnly;
|
||||
model.Paging.ItemTotal = (ulong)AccountMgr.GetUserAccountCount(prmUserAccount);
|
||||
model.PopulatePagingTo(prmUserAccount.ResultsPaging);
|
||||
|
||||
List<SaxUserAccount> users = AccountMgr.GetUserAccountList(prmUserAccount);
|
||||
List<SysId> userIds = users.GetIds();
|
||||
|
||||
// Item columns.
|
||||
ColumnDfn colId = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.Id);
|
||||
ColumnDfn colTitle = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.Title);
|
||||
ColumnDfn colFirstName = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.FirstName);
|
||||
ColumnDfn colLastName = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.LastName);
|
||||
ColumnDfn colRegionCountryName = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.RegionCountry_Name);
|
||||
ColumnDfn colRegionProvinceName = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.RegionProvince_Name);
|
||||
List<ColumnDfn> columns = new List<ColumnDfn>()
|
||||
{
|
||||
colId, colTitle, colFirstName, colLastName,
|
||||
colRegionCountryName,colRegionProvinceName,
|
||||
};
|
||||
|
||||
// Sort columns.
|
||||
colLastName.SortAscending = true;
|
||||
prmUserAccount.SortColumns.Add(colLastName);
|
||||
|
||||
// Query items.
|
||||
using (DbResultSet resultSet = AccountMgr.ExecuteUserAccountQuery(columns, prmUserAccount))
|
||||
{
|
||||
while (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
|
||||
{
|
||||
NamedValue.Map values = resultSet.GetRecordValues();
|
||||
String displayName = SaxUserAccount.GetDisplayName(values.GetString(colTitle.DataName), values.GetString(colFirstName.DataName), values.GetString(colLastName.DataName));
|
||||
List<String> location = new List<string>() { values.GetString(colRegionProvinceName.DataName), values.GetString(colRegionCountryName.DataName) };
|
||||
UserListData userData = new UserListData()
|
||||
{
|
||||
Id = model.EncryptId(new SysId(values.GetLong(colId.DataName))),
|
||||
Name = displayName,
|
||||
Location = location.Concat(", ", "", "", true, true),
|
||||
};
|
||||
responseData.Users.Add(userData);
|
||||
}
|
||||
}
|
||||
if (model.Paging.IsPaged)
|
||||
model.Paging.ItemCount = (ushort)responseData.Users.Count;
|
||||
|
||||
// Complete response.
|
||||
responseData.SetPaging(model);
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Account - Get Users.
|
||||
//-------------------------------------------------------------------
|
||||
private class UserData
|
||||
{
|
||||
public String Id { get; set; }
|
||||
public String Name { get; set; }
|
||||
public String Location { get; set; }
|
||||
}
|
||||
private class AjaxResponse_Search_User : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_Search_User(SaxModel_Online model) : base(model) { }
|
||||
// User list.
|
||||
public UserData User { get; set; }
|
||||
}
|
||||
// Ajax request.
|
||||
[HttpPost]
|
||||
[Route("Search/Ajax/User")]
|
||||
[Route("Search/Ajax/GetUser")]
|
||||
public IActionResult GetProfileUser(Model_Search_Users model)
|
||||
{
|
||||
String fn = GetType().Name + ".GetProfileUser";
|
||||
AjaxResponse_Search_User responseData = new AjaxResponse_Search_User(model);
|
||||
String messageTitle = Localiser["label.user"];
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
// Retrieve user.
|
||||
SysId userAccountId = model.ExtractSysId(model.UserId);
|
||||
if (!SysId.IsValid(userAccountId))
|
||||
{
|
||||
SaLogger.Warn(fn + " User Id not supplied.");
|
||||
return Json(responseData);
|
||||
}
|
||||
SaxUserAccount userAccount = AccountMgr.GetUserAccountById(userAccountId);
|
||||
if (userAccount == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user. Id: " + model.UserId);
|
||||
return Json(responseData);
|
||||
}
|
||||
disposableItems.Add(userAccount);
|
||||
|
||||
// Populate response.
|
||||
List<String> location = new List<string>() { model.GetRegionCaption(userAccount.RegionIdProvince), model.GetRegionCaption(userAccount.RegionIdCountry) };
|
||||
UserData userData = new UserData()
|
||||
{
|
||||
Id = model.EncryptId(userAccount.Id),
|
||||
Name = userAccount.GetDisplayName(),
|
||||
Location = location.Concat(", ", "", "", true, true),
|
||||
};
|
||||
responseData.User = userData;
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Core.Web.Base.App;
|
||||
using Saxonite.Net.Core.Web.Online.Models;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -38,6 +39,25 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
return RedirectToAction("", "");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Search - Users.
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public IActionResult Users()
|
||||
{
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return RedirectToAction("", "");
|
||||
|
||||
// Model.
|
||||
Model_Search_Users model = new Model_Search_Users(Localiser);
|
||||
model.Paging.PageNo = 1;
|
||||
model.Paging.PageLength = Sax.Config.Online.Search.Organisations.PageLengthDefault;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Search - Organisations.
|
||||
@@ -52,7 +72,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
// Model.
|
||||
Model_Search_Organisations model = new Model_Search_Organisations(Localiser);
|
||||
model.Paging.PageNo = 1;
|
||||
model.Paging.PageLength = 12;
|
||||
model.Paging.PageLength = Sax.Config.Online.Search.Users.PageLengthDefault;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Helpers;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Core.Web.Base.App;
|
||||
using Saxonite.Net.Core.Web.Base.Controllers;
|
||||
using Saxonite.Net.Core.Web.Base.Models;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using Saxonite.Net.Standard.Base.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Online.Models
|
||||
{
|
||||
//=======================================================================
|
||||
public class Model_Search_Users : SaxModel_Online
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public Model_Search_Users(SaxLocaliser localiser) :
|
||||
base(localiser)
|
||||
{
|
||||
//AdditionalFiles_CSS.Add("css/sax-src-usr.css");
|
||||
AdditionalFiles_JS.Add("js/sax-src-usr.js");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Page configuration.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form properties.
|
||||
public class FilterData
|
||||
{
|
||||
public String User { get; set; }
|
||||
public String RegionId { get; set; }
|
||||
public String SportId { get; set; }
|
||||
}
|
||||
public FilterData Filter { get; } = new FilterData();
|
||||
public SysId FilterSportId { get { return ExtractSysId(Filter.SportId); } }
|
||||
public SysId FilterRegionId { get { return ExtractSysId(Filter.RegionId); } }
|
||||
public String UserId { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validation.
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user