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. private class OrganisationResponseData : AjaxResponse_Data.ItemData_Base { public String Name { get; set; } public String RegionId { get; set; } public String RegionName { get; set; } public String 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 Organisations { get; } = new List(); } //------------------------------------------------------------------- [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 columns = new List() { 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 = model.EncryptId(new SysId(values.GetLong(colOrganisationId.DataName))), Name = values.GetString(colOrganisationName.DataName), RegionId = model.EncryptId(new SysId(values.GetLong(colRegionId.DataName))), RegionName = values.GetString(colRegionName.DataName), SportId = model.EncryptId(new SysId(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 Admin Organisation List ajax request. //------------------------------------------------------------------- private class AjaxResponse_MemberAdminOrganisationList : AjaxResponse_Data { // Construction. public AjaxResponse_MemberAdminOrganisationList(SaxModel_Online model) : base(model) { } // Organisation list. public List Organisations { get; } = new List(); } //------------------------------------------------------------------- [HttpPost] [Route("Organisation/Ajax/GetMemberAdminOrganisationList")] public IActionResult Ajax_GetMemberAdminOrganisationList(Model_Organisation model) { String fn = GetType().Name + ".Ajax_GetMemberAdminOrganisationList"; String messageTitle = Localiser["organisation.caption.organisations"]; AjaxResponse_MemberAdminOrganisationList responseData = new AjaxResponse_MemberAdminOrganisationList(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 columns = new List() { colOrganisationId, colOrganisationName, colRegionId, colRegionName, colSportId, colSportName }; // Organisation filter SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params(); prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId); prmUserOrganisation.OrganisationStatusCat = SaxOrganisation.StatusCat.ActiveOnly; prmUserOrganisation.OrganisationMembersOnly = true; prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.Admin); prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.MemberAdmin); 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 = model.EncryptId(new SysId(values.GetLong(colOrganisationId.DataName))), Name = values.GetString(colOrganisationName.DataName), RegionId = model.EncryptId(new SysId(values.GetLong(colRegionId.DataName))), RegionName = values.GetString(colRegionName.DataName), SportId = model.EncryptId(new SysId(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 Event Admin Organisation List ajax request. //------------------------------------------------------------------- private class AjaxResponse_EventAdminOrganisationList : AjaxResponse_Data { // Construction. public AjaxResponse_EventAdminOrganisationList(SaxModel_Online model) : base(model) { } // Organisation list. public List Organisations { get; } = new List(); } //------------------------------------------------------------------- [HttpPost] [Route("Organisation/Ajax/GetEventAdminOrganisationList")] public IActionResult Ajax_GetEventAdminOrganisationList(Model_Organisation model) { String fn = GetType().Name + ".Ajax_GetEventAdminOrganisationList"; String messageTitle = Localiser["organisation.caption.organisations"]; AjaxResponse_EventAdminOrganisationList responseData = new AjaxResponse_EventAdminOrganisationList(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 columns = new List() { colOrganisationId, colOrganisationName, colRegionId, colRegionName, colSportId, colSportName }; // Organisation filter SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params(); prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId); prmUserOrganisation.OrganisationStatusCat = SaxOrganisation.StatusCat.ActiveOnly; prmUserOrganisation.OrganisationMembersOnly = true; prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.Admin); prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.ScheduleAdmin); 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 = model.EncryptId(new SysId(values.GetLong(colOrganisationId.DataName))), Name = values.GetString(colOrganisationName.DataName), RegionId = model.EncryptId(new SysId(values.GetLong(colRegionId.DataName))), RegionName = values.GetString(colRegionName.DataName), SportId = model.EncryptId(new SysId(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 Opportunity Admin Organisation List ajax request. //------------------------------------------------------------------- private class AjaxResponse_OpportunityAdminOrganisationList : AjaxResponse_Data { // Construction. public AjaxResponse_OpportunityAdminOrganisationList(SaxModel_Online model) : base(model) { } // Organisation list. public List Organisations { get; } = new List(); } //------------------------------------------------------------------- [HttpPost] [Route("Organisation/Ajax/GetOpportunityAdminOrganisationList")] public IActionResult Ajax_GetOpportunityAdminOrganisationList(Model_Organisation model) { String fn = GetType().Name + ".Ajax_GetOpportunityAdminOrganisationList"; String messageTitle = Localiser["organisation.caption.organisations"]; AjaxResponse_OpportunityAdminOrganisationList responseData = new AjaxResponse_OpportunityAdminOrganisationList(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 columns = new List() { colOrganisationId, colOrganisationName, colRegionId, colRegionName, colSportId, colSportName }; // Organisation filter SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params(); prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId); prmUserOrganisation.OrganisationStatusCat = SaxOrganisation.StatusCat.ActiveOnly; prmUserOrganisation.OrganisationMembersOnly = true; prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.Admin); prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.OpportunityAdmin); 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 = model.EncryptId(new SysId(values.GetLong(colOrganisationId.DataName))), Name = values.GetString(colOrganisationName.DataName), RegionId = model.EncryptId(new SysId(values.GetLong(colRegionId.DataName))), RegionName = values.GetString(colRegionName.DataName), SportId = model.EncryptId(new SysId(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); } //------------------------------------------------------------------- } //======================================================================= }