90 lines
3.5 KiB
C#
90 lines
3.5 KiB
C#
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;
|
|
|
|
namespace Saxonite.Net.Core.Web.Online.Controllers
|
|
{
|
|
//=======================================================================
|
|
// Online Account Controller - Organisations - Ajax actions.
|
|
//=======================================================================
|
|
partial class AccountController
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Account - Get Organisations.
|
|
//-------------------------------------------------------------------
|
|
public class ProfileOrganisationResponseData
|
|
{
|
|
public ProfileOrganisationResponseData(SaxOrganisation organisation)
|
|
{
|
|
Name = organisation.Name;
|
|
}
|
|
public String Name { get; }
|
|
}
|
|
public class AjaxResponse_ProfileOrganisationsData : AjaxResponse_Data
|
|
{
|
|
public List<ProfileOrganisationResponseData> Organisations { get; } = new List<ProfileOrganisationResponseData>();
|
|
}
|
|
// Ajax request.
|
|
[HttpPost]
|
|
[Route("Account/Ajax/GetProfileOrganisations")]
|
|
public IActionResult GetProfileOrganisations(Model_Account model)
|
|
{
|
|
String fn = GetType().Name + ".GetProfileOrganisations";
|
|
AjaxResponse_ProfileOrganisationsData responseData = new AjaxResponse_ProfileOrganisationsData();
|
|
String messageTitle = Localiser["account.caption.profile.organisations"];
|
|
|
|
// Validate session and referrer.
|
|
if (!ValidReferer)
|
|
return Forbid();
|
|
if (!ValidUserSession)
|
|
return GetAjaxResult_InvalidSession(responseData);
|
|
|
|
// Retrieve users organisations.
|
|
SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params();
|
|
prmUserOrganisation.UserAccountIdsIncluded.Add(SessionData.User.UserAccountId);
|
|
prmUserOrganisation.OrganisationMembersOnly = true;
|
|
prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly;
|
|
List<SaxUserOrganisation> userOrganisations = AccountMgr.GetUserOrganisationList(prmUserOrganisation);
|
|
List<SysId> organisationIds = userOrganisations.GetOrganisationIds();
|
|
|
|
// Retrieve the organisation details.
|
|
List<SaxOrganisation> organisations = new List<SaxOrganisation>();
|
|
if (!organisationIds.IsEmpty())
|
|
{
|
|
SaxOrganisation.Params prmOrganisation = new SaxOrganisation.Params();
|
|
prmOrganisation.IdsIncluded.AddRange(organisationIds);
|
|
prmOrganisation.StatusCat = SaxOrganisation.StatusCat.ActiveOnly;
|
|
prmOrganisation.SortColumns.Add(AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.Name));
|
|
organisations.AddRange(AccountMgr.GetOrganisationList(prmOrganisation));
|
|
}
|
|
|
|
// Add the organisations to the response.
|
|
foreach (SaxUserOrganisation userOrganisation in userOrganisations)
|
|
{
|
|
SaxOrganisation organisation = organisations.GetOrganisationById(userOrganisation.OrganisationId);
|
|
if (organisation == null) continue;
|
|
ProfileOrganisationResponseData organisationData = new ProfileOrganisationResponseData(organisation);
|
|
responseData.Organisations.Add(organisationData);
|
|
}
|
|
|
|
// Complete response.
|
|
responseData.Success = true;
|
|
return Json(responseData);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|