184 lines
8.2 KiB
C#
184 lines
8.2 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Sarand.Net.Standard.Base.App;
|
|
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.Online.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 - Ajax actions.
|
|
//=======================================================================
|
|
partial class OrganisationController
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Organisation data.
|
|
public class OrganisationResponseData
|
|
{
|
|
public long Id { get; set; }
|
|
public String Name { get; set; }
|
|
public long RegionId { get; set; }
|
|
public String RegionName { get; set; }
|
|
public long SportId { get; set; }
|
|
public String SportName { get; set; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Get Organisation List ajax request.
|
|
//-------------------------------------------------------------------
|
|
private class AjaxResponse_OrganisationList : AjaxResponse_Data
|
|
{
|
|
// Construction.
|
|
public AjaxResponse_OrganisationList(SaxModel_Online model) : base(model) { }
|
|
// Organisation list.
|
|
public List<OrganisationResponseData> Organisations { get; } = new List<OrganisationResponseData>();
|
|
}
|
|
//-------------------------------------------------------------------
|
|
[HttpPost]
|
|
[Route("Organisation/Ajax/GetOrganisationList")]
|
|
public IActionResult Ajax_GetOrganisationList(Model_Organisation model)
|
|
{
|
|
String fn = GetType().Name + ".Ajax_GetOrganisationList";
|
|
String messageTitle = Localiser["organisation.caption.organisations"];
|
|
AjaxResponse_OrganisationList responseData = new AjaxResponse_OrganisationList(model);
|
|
|
|
// Validate session and referrer.
|
|
if (!ValidReferer) return Forbid();
|
|
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
|
RefreshModel(model);
|
|
|
|
// Query columns.
|
|
ColumnDfn colOrganisationId = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.Id);
|
|
ColumnDfn colOrganisationName = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.Name);
|
|
ColumnDfn colRegionId = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.RegionId);
|
|
ColumnDfn colRegionName = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.Region_Name);
|
|
ColumnDfn colSportId = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.SportId);
|
|
ColumnDfn colSportName = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.Sport_Name);
|
|
List<ColumnDfn> columns = new List<ColumnDfn>()
|
|
{
|
|
colOrganisationId, colOrganisationName,
|
|
colRegionId, colRegionName,
|
|
colSportId, colSportName
|
|
};
|
|
|
|
// Organisation filter.
|
|
SaxOrganisation.Params prmOrganisation = new SaxOrganisation.Params();
|
|
prmOrganisation.OrganisationFilter = model.Filter.Organisation;
|
|
prmOrganisation.RegionIdsIncluded.AddId(model.ExtractSysId(model.Filter.RegionId));
|
|
prmOrganisation.SportIdsIncluded.AddId(model.ExtractSysId(model.Filter.SportId));
|
|
prmOrganisation.StatusCat = SaxOrganisation.StatusCat.ActiveOnly;
|
|
prmOrganisation.SortColumns.Add(colOrganisationName);
|
|
model.Paging.ItemTotal = (ulong)AccountMgr.GetOrganisationCount(prmOrganisation);
|
|
model.PopulatePagingTo(prmOrganisation.ResultsPaging);
|
|
using (DbResultSet resultSet = AccountMgr.ExecuteOrganisationQuery(columns, prmOrganisation))
|
|
{
|
|
while (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
|
|
{
|
|
NamedValue.Map values = resultSet.GetRecordValues();
|
|
OrganisationResponseData organisationData = new OrganisationResponseData()
|
|
{
|
|
Id = values.GetLong(colOrganisationId.DataName),
|
|
Name = values.GetString(colOrganisationName.DataName),
|
|
RegionId = values.GetLong(colRegionId.DataName),
|
|
RegionName = values.GetString(colRegionName.DataName),
|
|
SportId = values.GetLong(colSportId.DataName),
|
|
SportName = values.GetString(colSportName.DataName),
|
|
};
|
|
responseData.Organisations.Add(organisationData);
|
|
}
|
|
}
|
|
if (model.Paging.IsPaged)
|
|
model.Paging.ItemCount = (ushort)responseData.Organisations.Count;
|
|
|
|
// Complete response.
|
|
responseData.SetPaging(model);
|
|
responseData.Success = true;
|
|
return Json(responseData);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Get Member Organisation List ajax request.
|
|
//-------------------------------------------------------------------
|
|
private class AjaxResponse_MemberOrganisationList : AjaxResponse_Data
|
|
{
|
|
// Construction.
|
|
public AjaxResponse_MemberOrganisationList(SaxModel_Online model) : base(model) { }
|
|
// Organisation list.
|
|
public List<OrganisationResponseData> Organisations { get; } = new List<OrganisationResponseData>();
|
|
}
|
|
//-------------------------------------------------------------------
|
|
[HttpPost]
|
|
[Route("Organisation/Ajax/GetMemberOrganisationList")]
|
|
public IActionResult Ajax_GetMemberOrganisationList(Model_Organisation model)
|
|
{
|
|
String fn = GetType().Name + ".Ajax_GetMemberOrganisationList";
|
|
String messageTitle = Localiser["organisation.caption.organisations"];
|
|
AjaxResponse_MemberOrganisationList responseData = new AjaxResponse_MemberOrganisationList(model);
|
|
|
|
// Validate session and referrer.
|
|
if (!ValidReferer) return Forbid();
|
|
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
|
RefreshModel(model);
|
|
|
|
// Query columns.
|
|
ColumnDfn colOrganisationId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.OrganisationId);
|
|
ColumnDfn colOrganisationName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Name);
|
|
ColumnDfn colRegionId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_RegionId);
|
|
ColumnDfn colRegionName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Region_Name);
|
|
ColumnDfn colSportId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_SportId);
|
|
ColumnDfn colSportName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Sport_Name);
|
|
List<ColumnDfn> columns = new List<ColumnDfn>()
|
|
{
|
|
colOrganisationId, colOrganisationName,
|
|
colRegionId, colRegionName,
|
|
colSportId, colSportName
|
|
};
|
|
|
|
// Organisation filter
|
|
SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params();
|
|
prmUserOrganisation.UserAccountIdsIncluded.Add(SessionData.User.UserAccountId);
|
|
prmUserOrganisation.OrganisationMembersOnly = true;
|
|
prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly;
|
|
prmUserOrganisation.SortColumns.Add(colOrganisationName);
|
|
model.Paging.ItemTotal = (ulong)AccountMgr.GetUserOrganisationCount(prmUserOrganisation);
|
|
model.PopulatePagingTo(prmUserOrganisation.ResultsPaging);
|
|
using (DbResultSet resultSet = AccountMgr.ExecuteUserOrganisationQuery(columns, prmUserOrganisation))
|
|
{
|
|
while (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
|
|
{
|
|
NamedValue.Map values = resultSet.GetRecordValues();
|
|
OrganisationResponseData organisationData = new OrganisationResponseData()
|
|
{
|
|
Id = values.GetLong(colOrganisationId.DataName),
|
|
Name = values.GetString(colOrganisationName.DataName),
|
|
RegionId = values.GetLong(colRegionId.DataName),
|
|
RegionName = values.GetString(colRegionName.DataName),
|
|
SportId = values.GetLong(colSportId.DataName),
|
|
SportName = values.GetString(colSportName.DataName),
|
|
};
|
|
responseData.Organisations.Add(organisationData);
|
|
}
|
|
}
|
|
if (model.Paging.IsPaged)
|
|
model.Paging.ItemCount = (ushort)responseData.Organisations.Count;
|
|
|
|
// Complete response.
|
|
responseData.SetPaging(model);
|
|
responseData.Success = true;
|
|
return Json(responseData);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|