Move Saxonite’s projects into a dedicated `Workspace` folder and align the solution with .NET 10 and the current Common workspace. Update encryption integration, test project structure and coverage, and repository guidance and upgrade notes. - Relocate application and library projects while retaining Git rename history. - Split tests into Admin, Online, and Shared projects; add representative behavioral and serialization tests. - Update Common integration, application version, and repository documentation. Application version: 1.3.0 Reviewed-on: #1 Co-authored-by: andy <andy@sarand.com>
194 lines
7.7 KiB
C#
194 lines
7.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
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;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Saxonite.Net.Core.Web.Online.Controllers
|
|
{
|
|
//=======================================================================
|
|
// Online Organisation Controller.
|
|
//=======================================================================
|
|
public partial class OrganisationController : SaxController_Online
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public OrganisationController(SaxLocaliser localiser, ILogger<HomeController> logger) :
|
|
base(localiser, logger)
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[HttpGet]
|
|
public IActionResult Index()
|
|
{
|
|
// Validate session.
|
|
if (!ValidUserSession)
|
|
return RedirectToAction("", "");
|
|
|
|
// No 'Index' view as yet - default to home page.
|
|
return RedirectToAction("", "");
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[HttpGet]
|
|
public IActionResult Members()
|
|
{
|
|
// Validate session.
|
|
if (!ValidUserSession)
|
|
return RedirectToAction("", "");
|
|
|
|
// Model.
|
|
Model_Organisation_Members model = new Model_Organisation_Members(Localiser);
|
|
|
|
// Get a suitable organisation for the filter.
|
|
SysId filterOrganisationId = SessionData_Online.Filter.OrganisationIdMember;
|
|
String filterOrganisationCaption = SessionData_Online.Filter.OrganisationCaptionMember;
|
|
OrganisationData organisationData = GetOrganisationForFilter(filterOrganisationId, filterOrganisationCaption, Sax.OrganisationRole.MemberAdmin);
|
|
if (organisationData == null)
|
|
return RedirectToAction("", "");
|
|
|
|
// Make a note of the filter values.
|
|
model.Filter.OrganisationId = model.EncryptId(organisationData.Id);
|
|
model.Filter.OrganisationCaption = organisationData.Caption;
|
|
SessionData_Online.Filter.OrganisationIdMember = organisationData.Id;
|
|
SessionData_Online.Filter.OrganisationCaptionMember = organisationData.Caption;
|
|
|
|
return View(model);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[HttpGet]
|
|
public IActionResult Events()
|
|
{
|
|
// Validate session.
|
|
if (!ValidUserSession)
|
|
return RedirectToAction("", "");
|
|
|
|
// Model.
|
|
Model_Organisation_Events model = new Model_Organisation_Events(Localiser);
|
|
|
|
// Get a suitable organisation for the filter.
|
|
SysId filterOrganisationId = SessionData_Online.Filter.OrganisationIdMember;
|
|
String filterOrganisationCaption = SessionData_Online.Filter.OrganisationCaptionMember;
|
|
OrganisationData organisationData = GetOrganisationForFilter(filterOrganisationId, filterOrganisationCaption, Sax.OrganisationRole.ScheduleAdmin);
|
|
if (organisationData == null)
|
|
return RedirectToAction("", "");
|
|
|
|
// Make a note of the filter values.
|
|
model.Filter.OrganisationId = model.EncryptId(organisationData.Id);
|
|
model.Filter.OrganisationCaption = organisationData.Caption;
|
|
SessionData_Online.Filter.OrganisationIdMember = organisationData.Id;
|
|
SessionData_Online.Filter.OrganisationCaptionMember = organisationData.Caption;
|
|
|
|
return View(model);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
[HttpGet]
|
|
public IActionResult Opportunities()
|
|
{
|
|
// Validate session.
|
|
if (!ValidUserSession)
|
|
return RedirectToAction("", "");
|
|
|
|
// Model.
|
|
Model_Organisation_Opportunities model = new Model_Organisation_Opportunities(Localiser);
|
|
|
|
// Get a suitable organisation for the filter.
|
|
SysId filterOrganisationId = SessionData_Online.Filter.OrganisationIdMember;
|
|
String filterOrganisationCaption = SessionData_Online.Filter.OrganisationCaptionMember;
|
|
OrganisationData organisationData = GetOrganisationForFilter(filterOrganisationId, filterOrganisationCaption, Sax.OrganisationRole.OpportunityAdmin);
|
|
if (organisationData == null)
|
|
return RedirectToAction("", "");
|
|
|
|
// Make a note of the filter values.
|
|
model.Filter.OrganisationId = model.EncryptId(organisationData.Id);
|
|
model.Filter.OrganisationCaption = organisationData.Caption;
|
|
SessionData_Online.Filter.OrganisationIdMember = organisationData.Id;
|
|
SessionData_Online.Filter.OrganisationCaptionMember = organisationData.Caption;
|
|
|
|
return View(model);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
public class OrganisationData
|
|
{
|
|
public OrganisationData(SysId id) { Id = id; }
|
|
public SysId Id { get; }
|
|
public String Caption { get; set; }
|
|
}
|
|
private OrganisationData GetOrganisationForFilter(SysId filterOrganisationId, String filterOrganisationCaption, Sax.OrganisationRole organisationRole)
|
|
{
|
|
OrganisationData organisationData = null;
|
|
|
|
// Roles (any) required for organisation list.
|
|
List<Sax.OrganisationRole> requiredRoles = new List<Sax.OrganisationRole>() { Sax.OrganisationRole.Admin };
|
|
if (organisationRole > 0)
|
|
requiredRoles.Add(organisationRole);
|
|
|
|
// Filter to identify suitable organisations that user is a member of and has the appropriate rights.
|
|
SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params();
|
|
prmUserOrganisation.UserAccountIdsIncluded.Add(SessionUserAccountId);
|
|
prmUserOrganisation.OrganisationStatusCat = SaxOrganisation.StatusCat.ActiveOnly;
|
|
prmUserOrganisation.OrganisationMembersOnly = true;
|
|
prmUserOrganisation.OrganisationRolesAny.UnionWith(requiredRoles);
|
|
prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly;
|
|
|
|
if (organisationRole == Sax.OrganisationRole.ScheduleAdmin)
|
|
{
|
|
prmUserOrganisation.OrganisationHasScheduledEvents = true;
|
|
}
|
|
|
|
// Restrict to specified Organisation.
|
|
if (SysId.IsValid(filterOrganisationId))
|
|
{
|
|
// Verify that the specified organisation is valid for the filter conditions.
|
|
prmUserOrganisation.OrganisationIdsIncluded.Add(filterOrganisationId);
|
|
if (AccountMgr.GetUserOrganisationCount(prmUserOrganisation) < 1)
|
|
// Specified organisation is not valid - remove restriction.
|
|
prmUserOrganisation.OrganisationIdsIncluded.Clear();
|
|
}
|
|
|
|
// Clear 'Scheduled Events' flag if no organisations available.
|
|
if (prmUserOrganisation.OrganisationHasScheduledEvents && AccountMgr.GetUserOrganisationCount(prmUserOrganisation) < 1)
|
|
prmUserOrganisation.OrganisationHasScheduledEvents = false;
|
|
|
|
// Pick the first valid Organisation.
|
|
ColumnDfn colOrganisationId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.OrganisationId);
|
|
ColumnDfn colOrganisationName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Name);
|
|
prmUserOrganisation.SortColumns.Add(colOrganisationName);
|
|
prmUserOrganisation.ResultsPaging.PageLength = 1;
|
|
prmUserOrganisation.ResultsPaging.PageNo = 1;
|
|
using (DbResultSet resultSet = AccountMgr.ExecuteUserOrganisationQuery(new List<ColumnDfn>() { colOrganisationId, colOrganisationName }, prmUserOrganisation))
|
|
{
|
|
if (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
|
|
{
|
|
NamedValue.Map values = resultSet.GetRecordValues();
|
|
SysId organisationId = new SysId(values.GetLong(colOrganisationId.DataName));
|
|
if (SysId.IsValid(organisationId))
|
|
{
|
|
organisationData = new OrganisationData(organisationId)
|
|
{
|
|
Caption = values.GetString(colOrganisationName.DataName)
|
|
};
|
|
}
|
|
}
|
|
}
|
|
return organisationData;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|