diff --git a/SaxoniteCoreWeb/Base/App/SaxLocaliser.cs b/SaxoniteCoreWeb/Base/App/SaxLocaliser.cs index dbdce7f..56a4bee 100644 --- a/SaxoniteCoreWeb/Base/App/SaxLocaliser.cs +++ b/SaxoniteCoreWeb/Base/App/SaxLocaliser.cs @@ -261,6 +261,12 @@ namespace Saxonite.Net.Core.Web.Base.App return GetCodeTypeCaption(Sax.CodeType.OrganisationRole, organisationRole); } + // Event type. + public String GetEventTypeCaption(Sax.EventType eventType) + { + return GetCodeTypeCaption(Sax.CodeType.EventType, eventType); + } + // Opportunity type. public String GetOpportunityTypeCaption(Sax.OpportunityType opportunityType) { diff --git a/SaxoniteCoreWeb/Base/Consoles/SaxDataCacheConsole_Web.cs b/SaxoniteCoreWeb/Base/Consoles/SaxDataCacheConsole_Web.cs index acd2516..1b41409 100644 --- a/SaxoniteCoreWeb/Base/Consoles/SaxDataCacheConsole_Web.cs +++ b/SaxoniteCoreWeb/Base/Consoles/SaxDataCacheConsole_Web.cs @@ -75,21 +75,24 @@ namespace Saxonite.Net.Core.Web.Base.Consoles if (!(new List() { Sax.DataItemType.Sport, Sax.DataItemType.Region }).Contains(itemType)) return candidateValue; - Dictionary itemIds = data.encryptedIdCache.GetValue(itemType, null); - if (itemIds == null) + lock (data.encryptedIdCache) { - // Add cache entry for this item type. - itemIds = new Dictionary(); - data.encryptedIdCache.Add(itemType, itemIds); + Dictionary itemIds = data.encryptedIdCache.GetValue(itemType, null); + if (itemIds == null) + { + // Add cache entry for this item type. + itemIds = new Dictionary(); + data.encryptedIdCache.Add(itemType, itemIds); + } + String encryptedId = itemIds.GetValue(id, null); + if (encryptedId == null && !StringUtil.IsEmpty(candidateValue)) + { + // Use the candidate value and store it. + encryptedId = candidateValue; + itemIds.Add(id, encryptedId); + } + return encryptedId; } - String encryptedId = itemIds.GetValue(id, null); - if (encryptedId == null && !StringUtil.IsEmpty(candidateValue)) - { - // Use the candidate value and store it. - encryptedId = candidateValue; - itemIds.Add(id, encryptedId); - } - return encryptedId; } //------------------------------------------------------------------- diff --git a/SaxoniteCoreWeb/Base/Controllers/SaxController_Base.cs b/SaxoniteCoreWeb/Base/Controllers/SaxController_Base.cs index 5bd4688..63c06ef 100644 --- a/SaxoniteCoreWeb/Base/Controllers/SaxController_Base.cs +++ b/SaxoniteCoreWeb/Base/Controllers/SaxController_Base.cs @@ -119,6 +119,7 @@ namespace Saxonite.Net.Core.Web.Base.Controllers public List OrganisationCategoryCodes { get { return Internals.OrganisationCategoryCodes; } } public List OrganisationRoleCodes { get { return Internals.OrganisationRoleCodes; } } public List AddressTypeCodes { get { return Internals.AddressTypeCodes; } } + public List EventTypeCodes { get { return Internals.EventTypeCodes; } } public List OpportunityTypeCodes { get { return Internals.OpportunityTypeCodes; } } public List ActivityReactionCodes { get { return Internals.ActivityReactionCodes; } } // Email. @@ -240,7 +241,7 @@ namespace Saxonite.Net.Core.Web.Base.Controllers // Copy the list of parameters, adding a random name/value pair to randomise the encryption. NameValueCollection parametersToEncrypt = new NameValueCollection(parameters); // NB Range 10-189 intended to have equal chance of 2 or 3 digit number. - parametersToEncrypt.Add("!" + SacsRandomHelper.GetInt32(10, 190).ToString(), SacsRandomHelper.GetInt32(10, 190).ToString()); + parametersToEncrypt.Add("!" + SacsRandomHelper.getRandomLengthNumber(4), null); // Sort the keys to ensure that the random '!' param is first in the query string. String[] paramKeys = parametersToEncrypt.AllKeys; @@ -249,11 +250,7 @@ namespace Saxonite.Net.Core.Web.Base.Controllers // Serialise parameters as if in a URL query string - so that they can be deserialised in DecryptParameters() below. string queryString = String.Join("&", paramKeys.Select(a => a + "=" + HttpUtility.UrlEncode(parametersToEncrypt[a]))); String encrypted = SacsEncryptionHelper.Encrypt(queryString, base64IV, base64Key); - if (SacsSystem.DebugMode) - { - SaLogger.Debug(fn + " Encrypted: " + encrypted); - NameValueCollection decryptedParams = DecryptParameters(encrypted, base64IV, base64Key); - } + if (SacsSystem.DebugMode) SaLogger.Debug(fn + "\n\tData: " + queryString + " \n\tEncrypted: " + encrypted); return encrypted; } catch (Exception exc) { SaLogger.Warn(fn + " " + ExceptionUtil.GetErrorStateMessage(exc)); } @@ -262,10 +259,10 @@ namespace Saxonite.Net.Core.Web.Base.Controllers public static NameValueCollection DecryptParameters(String encrypted, String base64IV, String base64Key) { String fn = nameof(ControllerBase) + ".DecryptParameters"; - if (SacsSystem.DebugMode) SaLogger.Debug(fn + " \n\tEncrypted: " + encrypted + "\n\tIV: " + base64IV + "\n\tKey: " + base64Key); try { String queryString = SacsEncryptionHelper.Decrypt(encrypted, base64IV, base64Key); + if (SacsSystem.DebugMode) SaLogger.Debug(fn + " \n\tEncrypted: " + encrypted + "\n\tData: " + queryString); return HttpUtility.ParseQueryString(queryString); } catch (Exception exc) { SaLogger.Warn(fn + " " + ExceptionUtil.GetErrorStateMessage(exc)); } @@ -300,10 +297,12 @@ namespace Saxonite.Net.Core.Web.Base.Controllers // Session. //------------------------------------------------------------------- public bool ValidUserSession { get { return SessionData?.ValidUserSession ?? false; } } + public SysId UserAccountId { get { return SessionData?.User?.UserAccountId ?? null; } } public DbUpdateInfo DbUpdateInfo { get { return SessionData?.DbUpdateInfo ?? new DbUpdateInfo(null, "", SaxSystem.ComputerName); } } // Referrer. public String Referer { get { return Request.Headers["Referer"].ToString(); } } public bool ValidReferer { get { return !StringUtil.IsEmpty(Referer); } } + /// Store session data, eg. to start a new user session on sign-in. protected bool SetSessionData(SaxSessionData sessionData) { diff --git a/SaxoniteCoreWeb/Base/Models/SaxModel_Base.cs b/SaxoniteCoreWeb/Base/Models/SaxModel_Base.cs index ecb2bba..c41294b 100644 --- a/SaxoniteCoreWeb/Base/Models/SaxModel_Base.cs +++ b/SaxoniteCoreWeb/Base/Models/SaxModel_Base.cs @@ -65,10 +65,10 @@ namespace Saxonite.Net.Core.Web.Base.Models protected SaxDataCacheConsole DataCacheConsole { get { return Internals.DataCacheConsole; } } protected SaxActivityConsole ActivityConsole { get { return Internals.ActivityConsole; } } // Managers. - protected SaxReferenceMgr ReferenceMgr { get { return Internals.ReferenceMgr; } } - protected SaxAccountMgr AccountMgr { get { return Internals.AccountMgr; } } - protected SaxActivityMgr ActivityMgr { get { return Internals.ActivityMgr; } } - protected SaxItemDataMgr ItemDataMgr { get { return Internals.ItemDataMgr; } } + public SaxReferenceMgr ReferenceMgr { get { return Internals.ReferenceMgr; } } + public SaxAccountMgr AccountMgr { get { return Internals.AccountMgr; } } + public SaxActivityMgr ActivityMgr { get { return Internals.ActivityMgr; } } + public SaxItemDataMgr ItemDataMgr { get { return Internals.ItemDataMgr; } } // System codes. public List DataItemTypeCodes { get { return Internals.DataItemTypeCodes; } } public List YesNoCodes { get { return Internals.YesNoCodes; } } @@ -81,6 +81,7 @@ namespace Saxonite.Net.Core.Web.Base.Models public List OrganisationCategoryCodes { get { return Internals.OrganisationCategoryCodes; } } public List OrganisationRoleCodes { get { return Internals.OrganisationRoleCodes; } } public List AddressTypeCodes { get { return Internals.AddressTypeCodes; } } + public List EventTypeCodes { get { return Internals.EventTypeCodes; } } public List OpportunityTypeCodes { get { return Internals.OpportunityTypeCodes; } } public List ActivityReactionCodes { get { return Internals.ActivityReactionCodes; } } diff --git a/SaxoniteCoreWebAdmin/Admin/Models/SaxModel_Admin.cs b/SaxoniteCoreWebAdmin/Admin/Models/SaxModel_Admin.cs index f97412d..2d04aeb 100644 --- a/SaxoniteCoreWebAdmin/Admin/Models/SaxModel_Admin.cs +++ b/SaxoniteCoreWebAdmin/Admin/Models/SaxModel_Admin.cs @@ -1,4 +1,6 @@ -using Saxonite.Net.Core.Web.Base.App; +using Sarand.Net.Standard.Base.Bus; +using Saxonite.Net.Core.Web.Admin.App; +using Saxonite.Net.Core.Web.Base.App; using Saxonite.Net.Core.Web.Base.Models; using System; using System.Collections.Generic; @@ -17,6 +19,13 @@ namespace Saxonite.Net.Core.Web.Admin.Models { } + //------------------------------------------------------------------- + // Properties. + //------------------------------------------------------------------- + // Session. + public SaxSessionData_Admin SessionData_Admin { get { return SessionData as SaxSessionData_Admin; } } + public SysId UserAccountId { get { return SessionData_Admin?.User?.UserAccountId ?? null; } } + //------------------------------------------------------------------- } //======================================================================= diff --git a/SaxoniteCoreWebOnline/Localisation/SaxOnlineProperties.resx b/SaxoniteCoreWebOnline/Localisation/SaxOnlineProperties.resx index 28c5598..01a4a9b 100644 --- a/SaxoniteCoreWebOnline/Localisation/SaxOnlineProperties.resx +++ b/SaxoniteCoreWebOnline/Localisation/SaxOnlineProperties.resx @@ -617,6 +617,12 @@ You will then be able to publicise your sporting activities. Value must not exceed {0} characters + + Event + + + Events + Add Member diff --git a/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-Contact.cs b/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-Contact.cs index e4b5602..653c2ad 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-Contact.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-Contact.cs @@ -74,7 +74,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers // Utilites. private ItemId GetUserItemId(SysId userAccountId) { - return new ItemId((short)Sax.DataItemType.UserAccount, SessionData.User.UserAccountId); + return new ItemId((short)Sax.DataItemType.UserAccount, UserAccountId); } //------------------------------------------------------------------- @@ -114,10 +114,10 @@ namespace Saxonite.Net.Core.Web.Online.Controllers responseData.Months.Add(month.ToString(), DateUtil.Format(new DateTime(DateTime.Today.Year, month, 1), "MMMM", SessionCulture)); // Retrieve user details. - SaxUserAccount userAccount = AccountMgr.GetUserAccountById(SessionData.User.UserAccountId); + SaxUserAccount userAccount = AccountMgr.GetUserAccountById(UserAccountId); if (userAccount == null) { - SaLogger.Warn(fn + " Failed to retrieve user account for Id: " + SysId.ToString(SessionData.User.UserAccountId)); + SaLogger.Warn(fn + " Failed to retrieve user account for Id: " + SysId.ToString(UserAccountId)); return Json(responseData.SetGoHome(messageTitle, Localiser["msg.something.gone.wrong"])); } @@ -191,7 +191,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers return Json(responseData.SetControlError("AccountContactImage", Localiser["msg.upload.image.invalid"])); // Image belongs to the user's account. - ItemId userItemId = GetUserItemId(SessionData.User.UserAccountId); + ItemId userItemId = GetUserItemId(UserAccountId); // Store uploaded image as 'Upload' Avatar - awaiting confirmation that the contact details are to be saved. SaxItemImage itemImage = ItemDataMgr.GetItemImage(userItemId, Sax.ImageType.AvatarUpload, SaxItemImage.StatusCat.Any); @@ -258,10 +258,10 @@ namespace Saxonite.Net.Core.Web.Online.Controllers return Json(responseData); // Retrieve user details. - SaxUserAccount userAccount = AccountMgr.GetUserAccountById(SessionData.User.UserAccountId); + SaxUserAccount userAccount = AccountMgr.GetUserAccountById(UserAccountId); if (userAccount == null) { - SaLogger.Warn(fn + " Failed to retrieve user account for Id: " + SysId.ToString(SessionData.User.UserAccountId)); + SaLogger.Warn(fn + " Failed to retrieve user account for Id: " + SysId.ToString(UserAccountId)); return Json(responseData.SetGoHome(messageTitle, Localiser["msg.something.gone.wrong"])); } if (!userAccount.EmailAddress.EqualsCI(SessionData.User.EmailAddress)) diff --git a/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-Organisations.cs b/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-Organisations.cs index 31c1d75..73376d9 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-Organisations.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-Organisations.cs @@ -24,16 +24,14 @@ namespace Saxonite.Net.Core.Web.Online.Controllers partial class AccountController { //------------------------------------------------------------------- - // Account - Get Organisations. - //------------------------------------------------------------------- - private class ProfileOrganisationData + /// Organisation properteis for list population. + private class ProfileOrganisationData_List : AjaxResponse_Data.ItemData_Base { - public long Id { get; set; } public String Name { get; set; } - public long SportId { get; set; } + public String CategoryDesc { get; set; } + public String TypeDesc { get; set; } public String SportName { get; set; } - public long RegionId { get; set; } - public String RegionName { get; set; } + public String RegionNameCountry { get; set; } public long MemberCount { get; set; } public long OpportunityCount { get; set; } public bool? Admin { get; set; } = null; @@ -42,20 +40,96 @@ namespace Saxonite.Net.Core.Web.Online.Controllers public bool? ScheduleAdmin { get; set; } = null; public bool? ArticleAdmin { get; set; } = null; } - private class AjaxResponse_ProfileOrganisationsData : AjaxResponse_Data + /// Address properties. + private class AddressData : AjaxResponse_Data.ItemData_Base + { + public String Line1 { get; set; } + public String Line2 { get; set; } + public String Line3 { get; set; } + public String Town { get; set; } + public String Province { get; set; } + public String RegionIdProvince { get; set; } + public String Country { get; set; } + public String PostalCode { get; set; } + } + /// Organisation properties for popup dialog and form. + private class ProfileOrganisationData : ProfileOrganisationData_List + { + public String CategoryCode { get; set; } + public String TypeCode { get; set; } + public String SportId { get; set; } + public String RegionIdCountry { get; set; } + public AddressData Address { get; set; } + } + /// Populate organisation properties for list. + private void PopulateOrganisationResponseData(SaxModel_Online model, SaxOrganisation organisation, SaxUserOrganisation userOrganisation, ProfileOrganisationData_List data) + { + data.Id = model.EncryptId(organisation.Id); + data.Name = organisation.Name; + data.SportName = model.GetSportCaption(organisation.SportIdPrimary); + data.RegionNameCountry = model.GetRegionCaption(organisation.RegionIdPrimary); + if (userOrganisation != null) + { + List roleCodes = userOrganisation.GetOrganisationRoleCodes(); + if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.Admin))) + data.Admin = true; + if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.MemberAdmin))) + data.MemberAdmin = true; + if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.OpportunityAdmin))) + data.OpportunitiyAdmin = true; + if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.ScheduleAdmin))) + data.ScheduleAdmin = true; + if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.ArticleAdmin))) + data.ArticleAdmin = true; + } + // NB Member and Opportunity counts are only populated for the Organisation list. + data.CreatedOnFmt = Localiser.FormatDate(organisation.CreateStamp.On); + data.UpdatedOnFmt = Localiser.FormatDate(organisation.UpdateStamp.On); + data.StatusCode = organisation.StatusCode; + data.StatusDesc = organisation.StatusDesc; + } + /// Populate organisation properties for popup dialog and form. + private void PopulateOrganisationResponseData(SaxModel_Online model, SaxOrganisation organisation, SaxUserOrganisation userOrganisation, SaxItemAddress address, ProfileOrganisationData data) + { + PopulateOrganisationResponseData(model, organisation, userOrganisation, (ProfileOrganisationData_List)data); + data.CategoryCode = OrganisationCategoryCodes.GetCodeForType(organisation.OrganisationCategory); + data.CategoryDesc = Localiser.GetOrganisationCategoryCaption(organisation.OrganisationCategory); + data.TypeCode = OrganisationTypeCodes.GetCodeForType(organisation.OrganisationType); + data.TypeDesc = Localiser.GetOrganisationTypeCaption(organisation.OrganisationType); + data.SportId = model.GetEncryptedSportId(organisation.SportIdPrimary); + data.RegionIdCountry = model.GetEncryptedRegionId(organisation.RegionIdPrimary); + if (address != null) + { + data.Address = new AddressData(); + data.Address.Id = model.EncryptId(address.Id); + data.Address.Line1 = address.Line1; + data.Address.Line2 = address.Line2; + data.Address.Line3 = address.Line3; + data.Address.Town = address.Town; + data.Address.Province = address.Province; + data.Address.Country = address.Country; + data.Address.PostalCode = address.PostalCode; + } + } + + //------------------------------------------------------------------- + // Account - Get Profile Organisations. + //------------------------------------------------------------------- + private class AjaxResponse_ProfileOrganisationList : AjaxResponse_Data { // Construction. - public AjaxResponse_ProfileOrganisationsData(SaxModel_Online model) : base(model) { } + public AjaxResponse_ProfileOrganisationList(SaxModel_Online model) : base(model) { } // Organisation list. - public List Organisations { get; } = new List(); + public List Organisations { get; } = new List(); } // Ajax request. [HttpPost] [Route("Account/Ajax/GetProfileOrganisations")] - public IActionResult GetProfileOrganisations(Model_Account model) + [Route("Account/Ajax/GetProfileOrganisationList")] + public IActionResult GetProfileOrganisationList(Model_Account model) { - String fn = GetType().Name + ".GetProfileOrganisations"; - AjaxResponse_ProfileOrganisationsData responseData = new AjaxResponse_ProfileOrganisationsData(model); + String fn = GetType().Name + ".GetProfileOrganisationList"; + AjaxResponse_ProfileOrganisationList responseData = new AjaxResponse_ProfileOrganisationList(model); String messageTitle = Localiser["account.caption.profile.organisations"]; // Validate session and referrer. @@ -63,71 +137,80 @@ namespace Saxonite.Net.Core.Web.Online.Controllers if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData); RefreshModel(model); - // Query organisations that user is a member of. - SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params(); - prmUserOrganisation.UserAccountIdsIncluded.Add(SessionData.User.UserAccountId); - prmUserOrganisation.OrganisationStatusCat = SaxOrganisation.StatusCat.ActiveOnly; - prmUserOrganisation.OrganisationMembersOnly = true; - prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly; - List userOrganisations = AccountMgr.GetUserOrganisationList(prmUserOrganisation); - List organisationIds = userOrganisations.GetOrganisationIds(); - - // Item columns. - ColumnDfn colId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Id); - ColumnDfn colOrganisationId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.OrganisationId); - ColumnDfn colOrganisationName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Name); - ColumnDfn colOrganisationSportId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_SportId); - ColumnDfn colOrganisationSportName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Sport_Name); - ColumnDfn colOrganisationRegionId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_RegionId); - ColumnDfn colOrganisationRegionName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Region_Name); - ColumnDfn colMemberCount = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Member_Count); - ColumnDfn colOpportunityCount = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Opportunity_Count); - ColumnDfn colStatus = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Status); - ColumnDfn colCreatedOn = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.CreateOn_Date); - ColumnDfn colRoleCodes = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.OrganisationRoleCodes); - List columns = new List() + // Record disposable items as they are created so all can be disposed when needed. + using (DisposableCollection disposableItems = new DisposableCollection()) { - colId, colOrganisationId , colOrganisationName, - colOrganisationSportId, colOrganisationSportName, - colOrganisationRegionId, colOrganisationRegionName, - colMemberCount, colOpportunityCount, - colStatus, colStatus, colCreatedOn, - colRoleCodes - }; - // Sort columns. - colCreatedOn.SortAscending = false; - prmUserOrganisation.SortColumns.Add(colOrganisationName); + // Query organisations that user is a member of. + SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params(); + prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId); + prmUserOrganisation.OrganisationStatusCat = SaxOrganisation.StatusCat.ActiveOnly; + prmUserOrganisation.OrganisationMembersOnly = true; + prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly; + List userOrganisations = AccountMgr.GetUserOrganisationList(prmUserOrganisation); + List organisationIds = userOrganisations.GetOrganisationIds(); - // Query items. - using (DbResultSet resultSet = AccountMgr.ExecuteUserOrganisationQuery(columns, prmUserOrganisation)) - { - while (resultSet != null && resultSet.HasRows && resultSet.NextRecord()) + // Item columns. + // NB Although UserOrgansiation data is queried, the response data is a list of Organisations. + ColumnDfn colId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.OrganisationId); + ColumnDfn colOrganisationName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Name); + ColumnDfn colOrganisationCategory = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Category); + ColumnDfn colOrganisationType = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Type); + ColumnDfn colOrganisationSportName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Sport_Name); + ColumnDfn colOrganisationRegionName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Region_Name); + ColumnDfn colMemberCount = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Member_Count); + ColumnDfn colOpportunityCount = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Opportunity_Count); + ColumnDfn colStatus = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Status); + ColumnDfn colCreatedOn = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.CreateOn_Date); + ColumnDfn colRoleCodes = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.OrganisationRoleCodes); + List columns = new List() { - NamedValue.Map values = resultSet.GetRecordValues(); - List roleCodes = StringListUtil.Split(values.GetString(colRoleCodes.DataName), ","); - ProfileOrganisationData organisationData = new ProfileOrganisationData() + colId, colOrganisationName, colOrganisationCategory, colOrganisationType, + colOrganisationSportName, colOrganisationRegionName, + colMemberCount, colOpportunityCount, + colStatus, colStatus, colCreatedOn, + colRoleCodes + }; + + // Sort columns. + colCreatedOn.SortAscending = false; + prmUserOrganisation.SortColumns.Add(colOrganisationName); + + // Query items. + using (DbResultSet resultSet = AccountMgr.ExecuteUserOrganisationQuery(columns, prmUserOrganisation)) + { + while (resultSet != null && resultSet.HasRows && resultSet.NextRecord()) { - Id = values.GetLong(colId.DataName), - Name = values.GetString(colOrganisationName.DataName), - SportId = values.GetLong(colOrganisationSportId.DataName), - SportName = values.GetString(colOrganisationSportName.DataName), - RegionId = values.GetLong(colOrganisationRegionId.DataName), - RegionName = values.GetString(colOrganisationRegionName.DataName), - MemberCount = values.GetLong(colMemberCount.DataName), - OpportunityCount = values.GetLong(colOpportunityCount.DataName) - }; - if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.Admin))) - organisationData.Admin = true; - if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.MemberAdmin))) - organisationData.MemberAdmin = true; - if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.OpportunityAdmin))) - organisationData.OpportunitiyAdmin = true; - if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.ScheduleAdmin))) - organisationData.ScheduleAdmin = true; - if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.ArticleAdmin))) - organisationData.ArticleAdmin = true; - responseData.Organisations.Add(organisationData); + NamedValue.Map values = resultSet.GetRecordValues(); + Sax.OrganisationCategory organisationCategory = (Sax.OrganisationCategory)OrganisationCategoryCodes.GetTypeForCode(values.GetString(colOrganisationCategory.DataName)); + Sax.OrganisationType organisationType = (Sax.OrganisationType)OrganisationTypeCodes.GetTypeForCode(values.GetString(colOrganisationType.DataName)); + ProfileOrganisationData_List organisationData = new ProfileOrganisationData_List() + { + Id = model.EncryptId(new SysId(values.GetLong(colId.DataName))), + Name = values.GetString(colOrganisationName.DataName), + CategoryDesc = Localiser.GetOrganisationCategoryCaption(organisationCategory), + TypeDesc = Localiser.GetOrganisationTypeCaption(organisationType), + //SportId = model.EncryptId(new SysId(values.GetLong(colOrganisationSportId.DataName))), + SportName = values.GetString(colOrganisationSportName.DataName), + //RegionId = model.EncryptId(new SysId(values.GetLong(colOrganisationRegionId.DataName))), + RegionNameCountry = values.GetString(colOrganisationRegionName.DataName), + MemberCount = values.GetLong(colMemberCount.DataName), + OpportunityCount = values.GetLong(colOpportunityCount.DataName) + }; + // Roles. + List roleCodes = StringListUtil.Split(values.GetString(colRoleCodes.DataName), SaxUserOrganisation.UserOrgnisationRoleDelim); + if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.Admin))) + organisationData.Admin = true; + if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.MemberAdmin))) + organisationData.MemberAdmin = true; + if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.OpportunityAdmin))) + organisationData.OpportunitiyAdmin = true; + if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.ScheduleAdmin))) + organisationData.ScheduleAdmin = true; + if (roleCodes.ContainsCI(OrganisationRoleCodes.GetCodeForType(Sax.OrganisationRole.ArticleAdmin))) + organisationData.ArticleAdmin = true; + responseData.Organisations.Add(organisationData); + } } } if (model.Paging.IsPaged) @@ -139,6 +222,260 @@ namespace Saxonite.Net.Core.Web.Online.Controllers return Json(responseData); } + //------------------------------------------------------------------- + // Account - Get Profile Organisation. + //------------------------------------------------------------------- + private class AjaxResponse_ProfileOrganisation : AjaxResponse_Data + { + // Construction. + public AjaxResponse_ProfileOrganisation(SaxModel_Online model) : base(model) { } + // Organisation list. + public ProfileOrganisationData Organisation { get; set; } + } + // Ajax request. + [HttpPost] + [Route("Account/Ajax/GetProfileOrganisation")] + public IActionResult GetProfileOrganisation(Model_Account model) + { + String fn = GetType().Name + ".GetProfileOrganisation"; + AjaxResponse_ProfileOrganisation responseData = new AjaxResponse_ProfileOrganisation(model); + String messageTitle = Localiser["label.organisation"]; + + // 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 disposableItems = new DisposableCollection()) + { + + // Identify item. + SysId organisationId = model.ExtractSysId(model.Organisation.Id); + if (!SysId.IsValid(organisationId)) + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"])); + + // Retrieve item. + SaxOrganisation organisation = AccountMgr.GetOrganisationById(organisationId); + disposableItems.Add(organisation); + if (organisation == null) + { + SaLogger.Warn(fn + " Failed to retrieve Organisation for Id: " + organisationId.ToString()); + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"])); + } + + // Organisation address. + SaxItemAddress address = ItemDataMgr.GetFirstItemAddressByItemAndType(organisation.GetItemId()); + disposableItems.Add(address); + + // Check whether user is a member of this organisation. + SaxUserOrganisation userOrganisation = AccountMgr.GetUserOrganisationByUserOrganisation(UserAccountId, organisationId); + disposableItems.Add(userOrganisation); + if (userOrganisation != null) + { + // Make a note of the selected Organisation. + SessionData_Online.Filter.SetMemberOrganisation(organisation); + } + + // Construct response. + responseData.Organisation = new ProfileOrganisationData(); + PopulateOrganisationResponseData(model, organisation, userOrganisation, address, responseData.Organisation); + } + + // Complete response. + responseData.Success = true; + return Json(responseData); + } + + //------------------------------------------------------------------- + // Account - Store Profile Organisation. + //------------------------------------------------------------------- + private class AjaxResponse_StoreProfileOrganisation : AjaxResponse_Data + { + // Construction. + public AjaxResponse_StoreProfileOrganisation(SaxModel_Online model) : base(model) { } + // Organisation list. + public ProfileOrganisationData Organisation { get; set; } + } + // Ajax request. + [HttpPost] + [Route("Account/Ajax/StoreProfileOrganisation")] + public IActionResult StoreProfileOrganisation(Model_Account model) + { + String fn = GetType().Name + ".StoreProfileOrganisation"; + AjaxResponse_StoreProfileOrganisation responseData = new AjaxResponse_StoreProfileOrganisation(model); + String messageTitle = Localiser["label.organisation"]; + + // 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 disposableItems = new DisposableCollection()) + { + + // Retrieve organisation. + SysId organisationId = model.ExtractSysId(model.Organisation.Id); + if (!SysId.IsValid(organisationId)) + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"])); + SaxOrganisation organisation = AccountMgr.GetOrganisationById(organisationId); + disposableItems.Add(organisation); + if (organisation == null) + { + SaLogger.Warn(fn + " Failed to retrieve Organisation for Id: " + organisationId.ToString() + ". " + GetLogSuffix()); + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"])); + } + + // Organisation address. + SaxItemAddress organisationAddress = ItemDataMgr.GetFirstItemAddressByItemAndType(organisation.GetItemId()); + disposableItems.Add(organisationAddress); + if (!StringUtil.IsEmpty(model.Organisation.Address.Id)) + { + // Validate supplied Address Id. + SysId organisationAddressId = model.ExtractSysId(model.Organisation.Address.Id); + if (organisationAddress != null) + { + if (!organisationAddress.Id.Equals(organisationAddressId)) + { + SaLogger.Warn(fn + " Organisation Address Id mismatch. Supplied: " + organisationAddressId + ". Found: " + organisationAddress.Id + ". " + GetLogSuffix()); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + } + else + { + SaLogger.Warn(fn + " Organisation Address Id supplied (" + organisationAddressId + ") but no address found for Organisation. " + GetLogSuffix()); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + } + else + { + // Address Id not supplied. + if (organisationAddress == null) + { + organisationAddress = ItemDataMgr.CreateItemAddress(organisation.GetItemId(), SaxItemAddress.DefaultOrganisationAddressType); + disposableItems.Add(organisationAddress); + } + else + { + SaLogger.Warn(fn + " Organisation Address Id not supplied but no address found for Organisation. Id: " + organisationAddress.Id + ". " + GetLogSuffix()); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + } + + // Check whether user is a member of this organisation. + SaxUserOrganisation userOrganisation = AccountMgr.GetUserOrganisationByUserOrganisation(UserAccountId, organisationId); + disposableItems.Add(userOrganisation); + if (userOrganisation == null) + { + SaLogger.Warn(fn + " Account: " + SessionData.User.EmailAddress + ". OrganisationId: " + organisationId.ToString() + ". User Organisation not found. " + GetLogSuffix()); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + if (!userOrganisation.GetOrganisationRoles().Contains(Sax.OrganisationRole.Admin)) + { + SaLogger.Warn(fn + " Account: " + SessionData.User.EmailAddress + ". OrganisationId: " + organisationId.ToString() + ". User does not have Admin role to update organisation. " + GetLogSuffix()); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + + // Validate organisation data. + model.ValidateProfileOrganisationData(responseData); + if (responseData.HasControlErrors()) + return Json(responseData); + + // Regions. + SysId regionIdCountry = model.ExtractSysId(model.Organisation.RegionIdCountry); + SaxRegion.Data regionCountry = Internals.GetRegion(regionIdCountry); + if (SysId.IsValid(regionIdCountry) && regionCountry == null) + { + SaLogger.Warn(fn + " Country region not found. Id: " + model.Organisation.RegionIdCountry + ". " + GetLogSuffix()); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + SysId regionIdAddressProvince = model.ExtractSysId(model.Organisation.Address.RegionIdProvince); + SaxRegion.Data regionProvince = Internals.GetRegion(regionIdAddressProvince); + if (SysId.IsValid(regionIdAddressProvince) && regionProvince == null) + { + SaLogger.Warn(fn + " Province region not found. Id: " + model.Organisation.Address.RegionIdProvince + ". " + GetLogSuffix()); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + + // Update organisation. + if (model.Organisation.Name != null) + organisation.Name = model.Organisation.Name; + if (model.Organisation.Type != null) + organisation.OrganisationType = model.Organisation.GetOrganisationType(); + if (model.Organisation.Category != null) + organisation.OrganisationCategory = model.Organisation.GetOrganisationCategory(); + if (model.Organisation.SportId != null) + organisation.SportIdPrimary = model.ExtractSysId(model.Organisation.SportId); + if (model.Organisation.RegionIdCountry != null) + organisation.RegionIdPrimary = model.ExtractSysId(model.Organisation.RegionIdCountry); + if (model.Organisation.PhoneMain != null) + organisation.PhoneMain = model.Organisation.PhoneMain; + if (!AccountMgr.UpdateOrganisation(organisation, DbUpdateInfo)) + { + SaLogger.Warn(fn + " Failed to update organisation - " + AccountMgr.ErrorStateMessage); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + + // Store address. + if (model.Organisation.Address.Line1 != null) + organisationAddress.Line1 = model.Organisation.Address.Line1; + if (model.Organisation.Address.Line2 != null) + organisationAddress.Line2 = model.Organisation.Address.Line2; + if (model.Organisation.Address.Line3 != null) + organisationAddress.Line3 = model.Organisation.Address.Line3; + if (model.Organisation.Address.Town != null) + organisationAddress.Town = model.Organisation.Address.Town; + if (regionProvince != null) + { + organisationAddress.Province = regionProvince.Name; + organisationAddress.RegionIdProvince = regionProvince.Id; + } + else + { + if (model.Organisation.Address.Province != null) + organisationAddress.Province = model.Organisation.Address.Province; + } + if (regionCountry != null) + { + organisationAddress.Country = regionCountry.Name; + organisationAddress.RegionIdCountry = regionCountry.Id; + } + else + { + if (model.Organisation.Address.Country != null) + organisationAddress.Country = model.Organisation.Address.Country; + } + organisationAddress.PostalCode = model.Organisation.Address.PostalCode; + if (!SysId.IsValid(organisationAddress.Id)) + { + // Create new address. + if (!ItemDataMgr.InsertItemAddress(organisationAddress, DbUpdateInfo)) + { + SaLogger.Warn(fn + " Failed to insert organisation address - " + ItemDataMgr.ErrorStateMessage); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + } + else + { + // Update existing address. + if (!ItemDataMgr.UpdateItemAddress(organisationAddress, DbUpdateInfo)) + { + SaLogger.Warn(fn + " Failed to update organisation address - " + ItemDataMgr.ErrorStateMessage); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + } + + // Construct response. + responseData.Organisation = new ProfileOrganisationData(); + PopulateOrganisationResponseData(model, organisation, userOrganisation, organisationAddress, responseData.Organisation); + } + + // Complete response. + responseData.Success = true; + return Json(responseData); + } + //------------------------------------------------------------------- } //======================================================================= diff --git a/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-Sports.cs b/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-Sports.cs index e111e7f..8132e8d 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-Sports.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-Sports.cs @@ -81,7 +81,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers // Item filter. SaxUserSport.Params prmUserSport = new SaxUserSport.Params(); - prmUserSport.UserAccountIdsIncluded.Add(SessionData.User.UserAccountId); + prmUserSport.UserAccountIdsIncluded.Add(UserAccountId); prmUserSport.StatusCat = SaxUserSport.StatusCat.NotDeleted; model.Paging.ItemTotal = (ulong)AccountMgr.GetUserSportCount(prmUserSport); model.PopulatePagingTo(prmUserSport.ResultsPaging); @@ -250,7 +250,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers if (userSport == null) { SaxUserSport.Params prmUserSport = new SaxUserSport.Params(); - prmUserSport.UserAccountIdsIncluded.Add(SessionData.User.UserAccountId); + prmUserSport.UserAccountIdsIncluded.Add(UserAccountId); prmUserSport.SportIdsIncluded.Add(sportId); prmUserSport.StatusCat = SaxUserSport.StatusCat.Any; userSport = AccountMgr.GetUserSport(prmUserSport); @@ -268,7 +268,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers } } else - userSport = AccountMgr.CreateUserSport(SessionData.User.UserAccountId, sportId); + userSport = AccountMgr.CreateUserSport(UserAccountId, sportId); } // Populate item properties. diff --git a/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-UserSportExperience.cs b/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-UserSportExperience.cs index 579f2dd..ac76037 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-UserSportExperience.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/AccountController-Ajax-UserSportExperience.cs @@ -123,7 +123,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers SysId userSportId = model.ExtractSysId(model.UserSportId); SaxUserSport userSport = AccountMgr.GetUserSportById(userSportId); disposableItems.Add(userSport); - if (userSport == null || !userSport.UserAccountId.Equals(SessionData.User.UserAccountId)) + if (userSport == null || !userSport.UserAccountId.Equals(UserAccountId)) return Json(responseData.SetGoHome(messageTitle, Localiser["msg.something.gone.wrong"])); // Sport details. @@ -220,7 +220,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers disposableItems.Add(userSportExperience); SaxUserSport userSport = AccountMgr.GetUserSportById(userSportExperience?.UserSportId ?? null); disposableItems.Add(userSport); - if (userSportExperience == null || userSport == null || !userSport.UserAccountId.Equals(SessionData.User.UserAccountId)) + if (userSportExperience == null || userSport == null || !userSport.UserAccountId.Equals(UserAccountId)) return Json(responseData.SetGoHome(messageTitle, Localiser["msg.something.gone.wrong"])); // Populate data to response. @@ -279,7 +279,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers disposableItems.Add(userSportExperience); userSport = AccountMgr.GetUserSportById(userSportExperience?.UserSportId ?? null); disposableItems.Add(userSport); - if (userSportExperience == null || userSport == null || !userSport.UserAccountId.Equals(SessionData.User.UserAccountId)) + if (userSportExperience == null || userSport == null || !userSport.UserAccountId.Equals(UserAccountId)) return Json(responseData.SetGoHome(messageTitle, Localiser["msg.something.gone.wrong"])); } else @@ -289,7 +289,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers SysId userSportId = model.ExtractSysId(model.UserSportId); userSport = AccountMgr.GetUserSportById(userSportId); disposableItems.Add(userSport); - if (userSport == null || !userSport.UserAccountId.Equals(SessionData.User.UserAccountId)) + if (userSport == null || !userSport.UserAccountId.Equals(UserAccountId)) return Json(responseData.SetGoHome(messageTitle, Localiser["msg.something.gone.wrong"])); // Create User Sport Experience. userSportExperience = AccountMgr.CreateUserSportExperience(userSport.Id); diff --git a/SaxoniteCoreWebOnline/Online/Controllers/ActivityController-Ajax.cs b/SaxoniteCoreWebOnline/Online/Controllers/ActivityController-Ajax.cs index 42281a9..b5807fd 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/ActivityController-Ajax.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/ActivityController-Ajax.cs @@ -148,7 +148,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers SaxSessionData_Online sessionData = SessionData_Online; // User context. - SysId userAccountId = SessionData.User.UserAccountId; + SysId userAccountId = UserAccountId; SaxActivityConsole.IndexContext indexContext = new SaxActivityConsole.IndexContext(userAccountId); // Regions. @@ -261,7 +261,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers } // Record activty viewing. - if (!ActivityConsole.RecordUserActivityViewed(SessionData.User.UserAccountId, new ItemId((short)itemType, itemId), DbUpdateInfo)) + if (!ActivityConsole.RecordUserActivityViewed(UserAccountId, new ItemId((short)itemType, itemId), DbUpdateInfo)) { SaLogger.Warn(fn + " Failed to record Activity Viewing: " + ActivityConsole.ErrorStateMessage + "." + GetLogSuffix()); return Json(responseData); @@ -306,7 +306,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers } // Record activity reaction. - if (!ActivityConsole.RecordUserActivityReaction(SessionData.User.UserAccountId, new ItemId((short)itemType, itemId), model.GetActivityReaction(), DbUpdateInfo)) + if (!ActivityConsole.RecordUserActivityReaction(UserAccountId, new ItemId((short)itemType, itemId), model.GetActivityReaction(), DbUpdateInfo)) { SaLogger.Warn(fn + " Failed to record Activity Reaction: " + ActivityConsole.ErrorStateMessage + "." + GetLogSuffix()); return Json(responseData); diff --git a/SaxoniteCoreWebOnline/Online/Controllers/ArticleController-Ajax.cs b/SaxoniteCoreWebOnline/Online/Controllers/ArticleController-Ajax.cs index 270f1ef..6066df2 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/ArticleController-Ajax.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/ArticleController-Ajax.cs @@ -141,7 +141,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers if (!ValidReferer) return Forbid(); if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData); SaxSessionData_Online sessionData = SessionData_Online; - SysId userAccountId = SessionData.User.UserAccountId; + SysId userAccountId = UserAccountId; RefreshModel(model); // Organisations that the user has rights to author articles for. @@ -257,7 +257,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers // Validate session and referrer. if (!ValidReferer) return Forbid(); if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData); - SysId userAccountId = SessionData.User.UserAccountId; + SysId userAccountId = UserAccountId; RefreshModel(model); // Identify item. @@ -445,7 +445,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers return Json(responseData); // Validate User & Organisation. - SysId userAccountId = SessionData.User.UserAccountId; + SysId userAccountId = UserAccountId; SysId organisationId = model.ExtractSysId(model.ArticleOrganisationId); if (SysId.IsValid(organisationId)) { diff --git a/SaxoniteCoreWebOnline/Online/Controllers/ArticleController.cs b/SaxoniteCoreWebOnline/Online/Controllers/ArticleController.cs index 547bf72..48ff84f 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/ArticleController.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/ArticleController.cs @@ -34,7 +34,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers return RedirectToAction("", ""); // User must either be a Journalist or have Article Admin rights with at least one organisation. - List organisations = AccountMgr.GetOrganisationsForAnyUserRole(SessionData.User.UserAccountId, new [] { Sax.OrganisationRole.Admin, Sax.OrganisationRole.ArticleAdmin }); + List organisations = AccountMgr.GetOrganisationsForAnyUserRole(UserAccountId, new [] { Sax.OrganisationRole.Admin, Sax.OrganisationRole.ArticleAdmin }); if (organisations.Count < 1 && !UserIsJournalist) return RedirectToAction("", ""); diff --git a/SaxoniteCoreWebOnline/Online/Controllers/ImageController.cs b/SaxoniteCoreWebOnline/Online/Controllers/ImageController.cs index ed75166..eb861f7 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/ImageController.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/ImageController.cs @@ -55,7 +55,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers String userAccountIdParam = "";// ToDo Decrypt from uaie value. SysId userAccountId = userAccountIdParam.ToSysId(); if (!SysId.IsValid(userAccountId)) - userAccountId = SessionData.User.UserAccountId; + userAccountId = UserAccountId; return GetAccountContactImage(userAccountId, Sax.ImageType.Avatar); } @@ -77,7 +77,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers // Response should not be cached. Response.Headers[HeaderNames.CacheControl] = "no-cache, no-store, must-revalidate, max-age=0"; Response.Headers[HeaderNames.Expires] = "-1"; - SysId userAccountId = SessionData.User.UserAccountId; + SysId userAccountId = UserAccountId; return GetAccountContactImage(userAccountId, Sax.ImageType.AvatarUpload); } @@ -137,7 +137,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers // Validate session and referrer. if (!ValidReferer) return Forbid(); if (!ValidUserSession) return Forbid(); - ItemId userItemId = new ItemId((short)Sax.DataItemType.UserAccount, SessionData.User.UserAccountId); + ItemId userItemId = new ItemId((short)Sax.DataItemType.UserAccount, UserAccountId); // Extract encrypted parameters. NameValueCollection parameters = ExtractOnlineParams(aie); diff --git a/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Events.cs b/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Events.cs new file mode 100644 index 0000000..482197f --- /dev/null +++ b/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Events.cs @@ -0,0 +1,431 @@ +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.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 - Events - Ajax actions. + //======================================================================= + partial class OrganisationController + { + //------------------------------------------------------------------- + // Organisation Event data. + private class EventData_List : AjaxResponse_Data.ItemData_Base + { + public String EventDateFmt { get; set; } + public String EventTimeFmt { get; set; } + public String TypeCode { get; set; } + public String TypeDesc { get; set; } + public String About { get; set; } + public String RegionCaption { get; set; } + public String SportCaption { get; set; } + public String PublishedOnFmt { get; set; } + public String ExpiresOnFmt { get; set; } + } + private class EventData_Detail : EventData_List + { + public String EventAt_YYYYMMDD { get; set; } + public String EventAt_HHMM { get; set; } + public String RegionIdCountry { get; set; } + public String SportIdPrimary { get; set; } + public String PublishedOn_YYYYMMDD { get; set; } + public String ExpiresOn_YYYYMMDD { get; set; } + } + private void PopulateEventResponseData(Model_Organisation_Events model, SaxOrganisationEvent organisationEvent, EventData_List data) + { + data.Id = SysId.ToString(organisationEvent.Id); + data.EventDateFmt = Localiser.FormatDate(organisationEvent.EventAt); + data.EventTimeFmt = DateUtil.Format(organisationEvent.EventAt, "HH:mm"); + data.TypeCode = EventTypeCodes.GetCodeForType(organisationEvent.EventType); + data.TypeDesc = Localiser.GetEventTypeCaption(organisationEvent.EventType); + data.About = organisationEvent.About; + data.RegionCaption = model.GetRegionCaption(organisationEvent.RegionIdCountry); + data.SportCaption = model.GetSportCaption(organisationEvent.SportIdPrimary); + data.CreatedOnFmt = Localiser.FormatDate(organisationEvent.CreateStamp.On); + data.PublishedOnFmt = Localiser.FormatDate(organisationEvent.PublishedAt); + data.ExpiresOnFmt = Localiser.FormatDate(organisationEvent.ExpiresAt); + data.StatusCode = organisationEvent.StatusCode; + data.StatusDesc = organisationEvent.StatusDesc; + } + private void PopulateEventResponseData(Model_Organisation_Events model, SaxOrganisationEvent organisationEvent, EventData_Detail data) + { + PopulateEventResponseData(model, organisationEvent, data as EventData_List); + data.EventAt_YYYYMMDD = DateUtil.Format(organisationEvent.EventAt, "yyyyMMdd"); + data.EventAt_HHMM = DateUtil.Format(organisationEvent.EventAt, "HH:mm"); + data.RegionIdCountry = model.GetEncryptedRegionId(organisationEvent.RegionIdCountry); + data.SportIdPrimary = model.GetEncryptedSportId(organisationEvent.SportIdPrimary); + data.PublishedOn_YYYYMMDD = DateUtil.Format(organisationEvent.PublishedAt, "yyyyMMdd"); + data.ExpiresOn_YYYYMMDD = DateUtil.Format(organisationEvent.ExpiresAt, "yyyyMMdd"); + } + + //------------------------------------------------------------------- + // Get Event List ajax request. + //------------------------------------------------------------------- + private class AjaxResponse_EventList : AjaxResponse_Data + { + // Construction. + public AjaxResponse_EventList(SaxModel_Online model) : base(model) { } + // Event list. + public List Events { get; } = new List(); + // User profile. + public class UserData + { + public bool CanManage { get; set; } + } + public UserData User { get; } = new UserData(); + // Organisation. + public class OrganisationData + { + public String Id { get; set; } + public String Name { get; set; } + public String SportId { get; set; } + public String SportName { get; set; } + public String RegionId { get; set; } + public String RegionName { get; set; } + } + public OrganisationData Organisation { get; } = new OrganisationData(); + // Reference data. + public List EventTypes { get; } = new List(); + } + //------------------------------------------------------------------- + [HttpPost] + [Route("Organisation/Ajax/GetEventList")] + [Route("Organisation/Ajax/GetEvents")] + public IActionResult Ajax_GetEventList(Model_Organisation_Events model) + { + String fn = GetType().Name + ".Ajax_GetEventList"; + String messageTitle = Localiser["organisation.caption.events"]; + AjaxResponse_EventList responseData = new AjaxResponse_EventList(model); + + // Validate session and referrer. + if (!ValidReferer) return Forbid(); + if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData); + RefreshModel(model); + SysId userAccountId = UserAccountId; + + // Record disposable items as they are created so all can be disposed when needed. + using (DisposableCollection disposableItems = new DisposableCollection()) + { + + // Organisation. + SysId organisationId = model.ExtractSysId(model.Filter.OrganisationId); + SaxOrganisation organisation = AccountMgr.GetOrganisationById(organisationId); + disposableItems.Add(organisation); + if (organisation == null || !organisation.IsStatusActive) + { + SaLogger.Warn(fn + " " + (organisation == null ? "Invalid" : "Inactive") + " organisation for Event list. OrganisationId: '" + model.Filter.OrganisationId + "'"); + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"])); + } + + if (organisation != null) + { + // Store filter data. + SessionData_Online.Filter.SetMemberOrganisation(organisation); + + // Reference data - organisationEvent types. + foreach (TypeCodeDesc eventType in EventTypeCodes) + responseData.EventTypes.Add(eventType.Code, Localiser.GetEventTypeCaption((Sax.EventType)eventType.Type)); + + // User organisation. + SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params(); + prmUserOrganisation.UserAccountIdsIncluded.Add(userAccountId); + prmUserOrganisation.OrganisationIdsIncluded.Add(organisationId); + prmUserOrganisation.UserAccountStatusCat = SaxUserAccount.StatusCat.ActiveOnly; + prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly; + SaxUserOrganisation userOrganisation = AccountMgr.GetUserOrganisation(prmUserOrganisation); + disposableItems.Add(userOrganisation); + if (userOrganisation == null) + { + SaLogger.Warn(fn + " Invalid/inactive user organisation for Event list. UserAccountId: " + SysId.ToString(userAccountId) + ". OrganisationId: " + model.Filter.OrganisationId + "."); + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"])); + } + + // Organisation. + responseData.Organisation.Id = SysId.ToString(organisation.Id); + responseData.Organisation.Name = organisation.Name; + responseData.Organisation.SportId = model.GetEncryptedSportId(organisation.SportIdPrimary); + responseData.Organisation.SportName = model.GetSportCaption(organisation.SportIdPrimary); + responseData.Organisation.RegionId = model.GetEncryptedRegionId(organisation.RegionIdPrimary); + responseData.Organisation.RegionName = model.GetRegionCaption(organisation.RegionIdPrimary); + + // User details. + responseData.User.CanManage = userOrganisation.CanManageSchedule; + + // Item filter. + SaxOrganisationEvent.Params prmEvent = new SaxOrganisationEvent.Params(); + prmEvent.UserAccountIdsIncluded.Add(userAccountId); + prmEvent.OrganisationIdsIncluded.Add(organisationId); + prmEvent.EventFilter = model.Filter.Event; + prmEvent.StatusCat = SaxOrganisationEvent.StatusCat.NotDeleted; + model.Paging.ItemTotal = (ulong)ActivityMgr.GetOrganisationEventCount(prmEvent); + model.PopulatePagingTo(prmEvent.ResultsPaging); + + // Item columns. + ColumnDfn colId = ActivityMgr.GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column.Id); + ColumnDfn colEventAt = ActivityMgr.GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column.EventAt_DateTime); + ColumnDfn colEventTypeCode = ActivityMgr.GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column.EventTypeCode); + ColumnDfn colAbout = ActivityMgr.GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column.About); + ColumnDfn colRegionId = ActivityMgr.GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column.RegionIdCountry); + ColumnDfn colRegionName = ActivityMgr.GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column.Region_Name); + ColumnDfn colSportId = ActivityMgr.GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column.SportIdPrimary); + ColumnDfn colSportName = ActivityMgr.GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column.Sport_Name); + ColumnDfn colPublishedOn = ActivityMgr.GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column.PublishedAt_Date); + ColumnDfn colExpiresOn = ActivityMgr.GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column.ExpiresAt_Date); + ColumnDfn colStatus = ActivityMgr.GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column.Status); + ColumnDfn colCreatedOn = ActivityMgr.GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column.CreateOn_Date); + List columns = new List() + { + colId, colEventAt, colEventTypeCode, colAbout, + colRegionId, colRegionName, colSportId, colSportName, + colPublishedOn, colExpiresOn, + colStatus, colCreatedOn + }; + + // Sort columns. + colCreatedOn.SortAscending = false; + prmEvent.SortColumns.Add(colCreatedOn); + + // Query items. + using (DbResultSet resultSet = ActivityMgr.ExecuteOrganisationEventQuery(columns, prmEvent)) + { + while (resultSet != null && resultSet.HasRows && resultSet.NextRecord()) + { + NamedValue.Map values = resultSet.GetRecordValues(); + EventData_List eventData = new EventData_List() + { + Id = values.GetLong(colId.DataName).ToString(), + EventDateFmt = Localiser.FormatDate(values.GetDateTime(colEventAt.DataName)), + EventTimeFmt = DateUtil.Format(values.GetDateTime(colEventAt.DataName), "HH:mm"), + TypeCode = values.GetString(colEventTypeCode.DataName), + TypeDesc = Localiser.GetEventTypeCaption((Sax.EventType)EventTypeCodes.GetTypeForCode(values.GetString(colEventTypeCode.DataName))), + About = values.GetString(colAbout.DataName), + RegionCaption = model.GetRegionCaption(values.GetString(colRegionId.DataName).ToSysId()), + SportCaption = model.GetSportCaption(values.GetString(colSportId.DataName).ToSysId()), + CreatedOnFmt = Localiser.FormatDate(values.GetDateTime(colCreatedOn.DataName)), + PublishedOnFmt = Localiser.FormatDate(values.GetDateTime(colPublishedOn.DataName)), + ExpiresOnFmt = Localiser.FormatDate(values.GetDateTime(colExpiresOn.DataName)), + StatusCode = values.GetString(colStatus.DataName), + StatusDesc = SacsSystem.GetStatusDescForCode(values.GetString(colStatus.DataName)) + }; + responseData.Events.Add(eventData); + } + } + } + } + if (model.Paging.IsPaged) + model.Paging.ItemCount = (ushort)responseData.Events.Count; + + // Complete response. + responseData.SetPaging(model); + responseData.Success = true; + return Json(responseData); + } + + //------------------------------------------------------------------- + // Get Event ajax request. + //------------------------------------------------------------------- + private class AjaxResponse_Event : AjaxResponse_Data + { + // Construction. + public AjaxResponse_Event(SaxModel_Online model) : base(model) { } + // Event details. + public EventData_Detail Event { get; } = new EventData_Detail(); + } + //------------------------------------------------------------------- + [HttpPost] + [Route("Organisation/Ajax/GetEvent")] + public IActionResult Ajax_GetEvent(Model_Organisation_Events model) + { + String fn = GetType().Name + ".Ajax_GetEvent"; + String messageTitle = Localiser["organisation.caption.organisationEvent"]; + AjaxResponse_Event responseData = new AjaxResponse_Event(model); + + // 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 disposableItems = new DisposableCollection()) + { + + // Identify item. + SysId eventId = model.ExtractSysId(model.EventId); + if (!SysId.IsValid(eventId)) + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"])); + + // Retrieve item. + SaxOrganisationEvent organisationEvent = ActivityMgr.GetOrganisationEventById(eventId); + disposableItems.Add(organisationEvent); + if (organisationEvent == null) + { + SaLogger.Warn(fn + " Failed to retrieve Organisation Event for Id: '" + model.EventId + "'"); + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"])); + } + + // Validate organisation. + SaxOrganisation organisation = AccountMgr.GetOrganisationById(organisationEvent.OrganisationId); + disposableItems.Add(organisation); + if (organisation == null || !organisation.IsStatusActive) + { + SaLogger.Warn(fn + " " + (organisation == null ? "Invalid" : "Inactive") + " organisation for Event. OrganisationId: '" + organisationEvent.OrganisationId + "'"); + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"])); + } + + // Make a note of the selected Organisation. + SessionData_Online.Filter.SetMemberOrganisation(organisation); + + // Construct response. + PopulateEventResponseData(model, organisationEvent, responseData.Event); + } + + // Complete response. + responseData.Success = true; + return Json(responseData); + } + + //------------------------------------------------------------------- + // Store Event ajax request. + //------------------------------------------------------------------- + [HttpPost] + [Route("Organisation/Ajax/StoreEvent")] + public IActionResult Ajax_StoreEvent(Model_Organisation_Events model) + { + String fn = GetType().Name + ".Ajax_StoreEvent"; + String messageTitle = Localiser["organisation.caption.organisationEvent"]; + AjaxResponse_Event responseData = new AjaxResponse_Event(model); + + // 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 disposableItems = new DisposableCollection()) + { + + // Validate item properties. + model.ValidateEventData(responseData); + if (responseData.HasControlErrors()) + return Json(responseData); + + // Validate Event against Id against 'Exists' flag. + SysId eventId = model.ExtractSysId(model.EventId); + bool eventExists = StringUtil.ToBool(model.EventExists); + if (eventExists && !SysId.IsValid(eventId)) + { + SaLogger.Warn(fn + " Id not specified for existing Event."); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + if (!eventExists && SysId.IsValid(eventId)) + { + SaLogger.Warn(fn + " Id specified for new Event: '" + model.EventId + "'"); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + + // Retrieve existing item. + SaxOrganisationEvent organisationEvent = ActivityMgr.GetOrganisationEventById(eventId); + disposableItems.Add(organisationEvent); + if (organisationEvent == null && SysId.IsValid(eventId)) + { + SaLogger.Warn(fn + " Failed to retrieve organisationEvent for Id: '" + model.EventId + "'"); + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"])); + } + + // Validate the Organisation. + SysId organisationId = model.ExtractSysId(model.EventOrganisationId); + if (!SysId.IsValid(organisationId)) + { + SaLogger.Warn(fn + " Organisation Id not specified for Event."); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + SaxOrganisation organisation = AccountMgr.GetOrganisationById(organisationId); + disposableItems.Add(organisation); + if (organisation == null || !organisation.IsStatusActive) + { + SaLogger.Warn(fn + " " + (organisation == null ? "Invalid" : "Inactive") + " organisation for Event. OrganisationId: '" + model.EventOrganisationId + "'"); + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"])); + } + if (organisationEvent != null && !organisationEvent.OrganisationId.Equals(organisationId)) + { + SaLogger.Warn(fn + " Inconsistent Organisation Id specified for Event. Expected: " + organisationEvent.OrganisationId + ". Found: " + organisationId); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + + // Ensure that the user has the correct role to update Events for this organisation. + if (!AccountMgr.UserHasAnyOrganisationRole(UserAccountId, organisationId, new[] { Sax.OrganisationRole.Admin, Sax.OrganisationRole.ScheduleAdmin })) + { + SaLogger.Warn(fn + " User doesn't have 'Event Admin' role for Organisation Id: " + organisationId); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + + // Create new item if required. + if (organisationEvent == null) + { + organisationEvent = ActivityMgr.CreateOrganisationEvent(organisationId); + disposableItems.Add(organisationEvent); + } + + // Populate item properties. + if (model.EventSportIdPrimary != null) + organisationEvent.SportIdPrimary = model.ExtractSysId(model.EventSportIdPrimary); + if (model.EventRegionIdCountry != null) + organisationEvent.RegionIdCountry = model.ExtractSysId(model.EventRegionIdCountry); + if (model.EventDate != null) + { + organisationEvent.EventAt = model.ParseDateFromForm(model.EventDate); + if (!StringUtil.IsEmpty(model.EventTime)) + organisationEvent.EventAt = DateUtil.SetTime(organisationEvent.EventAt, DateUtil.ParseExact(model.EventTime, "HH:mm")); + } + if (model.EventTypeCode != null) + organisationEvent.EventType = (Sax.EventType)EventTypeCodes.GetTypeForCode(model.EventTypeCode); + if (model.EventAbout != null) + organisationEvent.About = model.EventAbout; + if (model.EventStatusCode != null) + organisationEvent.Status = model.EventStatus; + + // Store item. + if (!SysId.IsValid(organisationEvent.Id)) + { + if (!ActivityMgr.InsertOrganisationEvent(organisationEvent, DbUpdateInfo)) + { + SaLogger.Warn(fn + " Failed to insert organisationEvent: " + ActivityMgr.ErrorStateMessage); + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.insert.failed"])); + } + } + else + { + if (!ActivityMgr.UpdateOrganisationEvent(organisationEvent, DbUpdateInfo)) + { + SaLogger.Warn(fn + " Failed to update organisationEvent [Id:" + SysId.ToString(organisationEvent.Id) + "]: " + ActivityMgr.ErrorStateMessage); + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.update.failed"])); + } + } + + // Store Event Activity Index data. +// ToDo ActivityConsole.StoreActivityIndex(organisationEvent, DbUpdateInfo); + + // Construct response. + PopulateEventResponseData(model, organisationEvent, responseData.Event); + } + + // Complete response. + responseData.Success = true; + return Json(responseData); + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Members.cs b/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Members.cs index d5fee26..ea3837c 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Members.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Members.cs @@ -43,7 +43,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers { data.Id = SysId.ToString(userOrganisation.Id); data.UserAccountId = SysId.ToString(userOrganisation.UserAccountId); - if (userOrganisation.UserAccountId.Equals(SessionData.User.UserAccountId)) data.CurrentUser = true; + if (userOrganisation.UserAccountId.Equals(UserAccountId)) data.CurrentUser = true; data.EmailAddress = userAccount.EmailAddress; data.DisplayName = userAccount.GetDisplayName(); data.RoleCodes.Clear(); @@ -131,7 +131,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers responseData.MemberRoles.Add(memberRole.Code, Localiser.GetOrganisationRoleCaption((Sax.OrganisationRole)memberRole.Type)); // Session User roles. - responseData.User.CanManage = AccountMgr.UserHasAnyOrganisationRole(SessionData.User.UserAccountId, organisation.Id, new List { Sax.OrganisationRole.Admin, Sax.OrganisationRole.MemberAdmin }); + responseData.User.CanManage = AccountMgr.UserHasAnyOrganisationRole(UserAccountId, organisation.Id, new List { Sax.OrganisationRole.Admin, Sax.OrganisationRole.MemberAdmin }); // Item filter. SaxUserOrganisation.Params prmMember = new SaxUserOrganisation.Params(); @@ -181,7 +181,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers StatusCode = values.GetString(colUserStatus.DataName), StatusDesc = SacsSystem.GetStatusDescForCode(values.GetString(colUserStatus.DataName)) }; - if (model.ExtractSysId(memberData.UserAccountId).Equals(SessionData.User.UserAccountId)) memberData.CurrentUser = true; + if (model.ExtractSysId(memberData.UserAccountId).Equals(UserAccountId)) memberData.CurrentUser = true; String memberRoleCodes = values.GetString(colOrganisationRoleCodes.DataName); foreach (String memberRoleCode in StringListUtil.Split(memberRoleCodes, SaxUserOrganisation.UserOrgnisationRoleDelim)) { @@ -256,7 +256,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers } // Session User roles. - bool userCanManageMembers = AccountMgr.UserHasAnyOrganisationRole(SessionData.User.UserAccountId, organisation.Id, new List { Sax.OrganisationRole.Admin, Sax.OrganisationRole.MemberAdmin }); + bool userCanManageMembers = AccountMgr.UserHasAnyOrganisationRole(UserAccountId, organisation.Id, new List { Sax.OrganisationRole.Admin, Sax.OrganisationRole.MemberAdmin }); // Validate user account. SaxUserAccount userAccount = AccountMgr.GetUserAccountById(userOrganisation.UserAccountId); @@ -366,7 +366,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers } // Ensure that the user has the correct role to update Members for this organisation. - bool userCanManageMembers = AccountMgr.UserHasAnyOrganisationRole(SessionData.User.UserAccountId, organisationId, new List { Sax.OrganisationRole.Admin, Sax.OrganisationRole.MemberAdmin }); + bool userCanManageMembers = AccountMgr.UserHasAnyOrganisationRole(UserAccountId, organisationId, new List { Sax.OrganisationRole.Admin, Sax.OrganisationRole.MemberAdmin }); if (!userCanManageMembers) { SaLogger.Warn(fn + " User doesn't have 'Member Admin' role for Organisation Id: " + organisationId); @@ -392,7 +392,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers } // Validate roles for current user. - if (userOrganisation.UserAccountId.Equals(SessionData.User.UserAccountId)) + if (userOrganisation.UserAccountId.Equals(UserAccountId)) { // User is modifying their own organisation member. if (userOrganisation.CanManageOrganisation && !model.OrganisationRoleCodes.Any(item => item.Type == (int)Sax.OrganisationRole.Admin)) @@ -559,7 +559,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers } // Ensure that the user has the correct role to update Members for this organisation. - bool userCanManageMembers = AccountMgr.UserHasAnyOrganisationRole(SessionData.User.UserAccountId, organisation.Id, new List { Sax.OrganisationRole.Admin, Sax.OrganisationRole.MemberAdmin }); + bool userCanManageMembers = AccountMgr.UserHasAnyOrganisationRole(UserAccountId, organisation.Id, new List { Sax.OrganisationRole.Admin, Sax.OrganisationRole.MemberAdmin }); if (!userCanManageMembers) { SaLogger.Warn(fn + " User doesn't have 'Member Admin' role for Organisation Id: " + organisation.Id); @@ -675,7 +675,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers } // Ensure that the user has the correct role to update Members for this organisation. - bool userCanManageMembers = AccountMgr.UserHasAnyOrganisationRole(SessionData.User.UserAccountId, organisation.Id, new List { Sax.OrganisationRole.Admin, Sax.OrganisationRole.MemberAdmin }); + bool userCanManageMembers = AccountMgr.UserHasAnyOrganisationRole(UserAccountId, organisation.Id, new List { Sax.OrganisationRole.Admin, Sax.OrganisationRole.MemberAdmin }); if (!userCanManageMembers) { SaLogger.Warn(fn + " User doesn't have 'Member Admin' role for Organisation Id: " + organisation.Id); diff --git a/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Opportunities.cs b/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Opportunities.cs index 0a1e7bb..56a0444 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Opportunities.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Opportunities.cs @@ -106,7 +106,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers if (!ValidReferer) return Forbid(); if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData); RefreshModel(model); - SysId userAccountId = SessionData.User.UserAccountId; + SysId userAccountId = UserAccountId; // Record disposable items as they are created so all can be disposed when needed. using (DisposableCollection disposableItems = new DisposableCollection()) @@ -249,14 +249,18 @@ namespace Saxonite.Net.Core.Web.Online.Controllers if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData); RefreshModel(model); - // Identify item. - SysId opportunityId = model.ExtractSysId(model.OpportunityId); - if (!SysId.IsValid(opportunityId)) - return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"])); - - // Retrieve item. - using (SaxOrganisationOpportunity opportunity = ActivityMgr.GetOrganisationOpportunityById(opportunityId)) + // Record disposable items as they are created so all can be disposed when needed. + using (DisposableCollection disposableItems = new DisposableCollection()) { + + // Identify item. + SysId opportunityId = model.ExtractSysId(model.OpportunityId); + if (!SysId.IsValid(opportunityId)) + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"])); + + // Retrieve item. + SaxOrganisationOpportunity opportunity = ActivityMgr.GetOrganisationOpportunityById(opportunityId); + disposableItems.Add(opportunity); if (opportunity == null) { SaLogger.Warn(fn + " Failed to retrieve Organisation Opportunity for Id: '" + model.OpportunityId + "'"); @@ -264,20 +268,19 @@ namespace Saxonite.Net.Core.Web.Online.Controllers } // Validate organisation. - using (SaxOrganisation organisation = AccountMgr.GetOrganisationById(opportunity.OrganisationId)) + SaxOrganisation organisation = AccountMgr.GetOrganisationById(opportunity.OrganisationId); + disposableItems.Add(organisation); + if (organisation == null || !organisation.IsStatusActive) { - if (organisation == null || !organisation.IsStatusActive) - { - SaLogger.Warn(fn + " " + (organisation == null ? "Invalid" : "Inactive") + " organisation for Opportunity. OrganisationId: '" + opportunity.OrganisationId + "'"); - return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"])); - } - - // Make a note of the selected Organisation. - SessionData_Online.Filter.SetMemberOrganisation(organisation); - - // Construct response. - PopulateOpportunityResponseData(model, opportunity, responseData.Opportunity); + SaLogger.Warn(fn + " " + (organisation == null ? "Invalid" : "Inactive") + " organisation for Opportunity. OrganisationId: '" + opportunity.OrganisationId + "'"); + return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"])); } + + // Make a note of the selected Organisation. + SessionData_Online.Filter.SetMemberOrganisation(organisation); + + // Construct response. + PopulateOpportunityResponseData(model, opportunity, responseData.Opportunity); } // Complete response. @@ -301,29 +304,29 @@ namespace Saxonite.Net.Core.Web.Online.Controllers if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData); RefreshModel(model); - // Validate item properties. - model.ValidateOpportunityData(responseData); - if (responseData.HasControlErrors()) - return Json(responseData); - - // Validate Opportunity against Id against 'Exists' flag. - SysId opportunityId = model.ExtractSysId(model.OpportunityId); - bool opportunityExists = StringUtil.ToBool(model.OpportunityExists); - if (opportunityExists && !SysId.IsValid(opportunityId)) - { - SaLogger.Warn(fn + " Id not specified for existing Opportunity."); - return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); - } - if (!opportunityExists && SysId.IsValid(opportunityId)) - { - SaLogger.Warn(fn + " Id specified for new Opportunity: '" + model.OpportunityId + "'"); - return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); - } - // Record disposable items as they are created so all can be disposed when needed. using (DisposableCollection disposableItems = new DisposableCollection()) { + // Validate item properties. + model.ValidateOpportunityData(responseData); + if (responseData.HasControlErrors()) + return Json(responseData); + + // Validate Opportunity against Id against 'Exists' flag. + SysId opportunityId = model.ExtractSysId(model.OpportunityId); + bool opportunityExists = StringUtil.ToBool(model.OpportunityExists); + if (opportunityExists && !SysId.IsValid(opportunityId)) + { + SaLogger.Warn(fn + " Id not specified for existing Opportunity."); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + if (!opportunityExists && SysId.IsValid(opportunityId)) + { + SaLogger.Warn(fn + " Id specified for new Opportunity: '" + model.OpportunityId + "'"); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + // Retrieve existing item. SaxOrganisationOpportunity opportunity = ActivityMgr.GetOrganisationOpportunityById(opportunityId); disposableItems.Add(opportunity); @@ -354,7 +357,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers } // Ensure that the user has the correct role to update Opportunities for this organisation. - if (!AccountMgr.UserHasAnyOrganisationRole(SessionData.User.UserAccountId, organisationId, new [] { Sax.OrganisationRole.Admin, Sax.OrganisationRole.OpportunityAdmin })) + if (!AccountMgr.UserHasAnyOrganisationRole(UserAccountId, organisationId, new[] { Sax.OrganisationRole.Admin, Sax.OrganisationRole.OpportunityAdmin })) { SaLogger.Warn(fn + " User doesn't have 'Opportunity Admin' role for Organisation Id: " + organisationId); return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); diff --git a/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Request.cs b/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Request.cs index 71a5b40..1fdff8c 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Request.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax-Request.cs @@ -44,140 +44,163 @@ namespace Saxonite.Net.Core.Web.Online.Controllers if (!ValidReferer) return Forbid(); SaxSessionData_Online sessionData = SessionData_Online; - if (!model.ValidateOrganisationRequestData(responseData)) - return Json(responseData); + // Record disposable items as they are created so all can be disposed when needed. + using (DisposableCollection disposableItems = new DisposableCollection()) + { - // Check Regions. - SysId regionIdCountry = model.ExtractSysId(model.OrganisationRegionIdCountry); - SaxRegion.Data regionCountry = Internals.GetRegion(regionIdCountry); - if (SysId.IsValid(regionIdCountry) && regionCountry == null) - { - SaLogger.Warn(fn + " Country region not found. Id: " + model.OrganisationRegionIdCountry + ". " + GetLogSuffix()); - return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); - } - SysId regionIdAddressProvince= model.ExtractSysId(model.OrganisationAddressRegionIdProvince); - SaxRegion.Data regionProvince = Internals.GetRegion(regionIdAddressProvince); - if (SysId.IsValid(regionIdAddressProvince) && regionProvince == null) - { - SaLogger.Warn(fn + " Province region not found. Id: " + model.OrganisationAddressRegionIdProvince + ". " + GetLogSuffix()); - return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); - } + if (!model.ValidateOrganisationRequestData(responseData)) + return Json(responseData); - // User does not need to be logged in, but user details must be supplied if not. - SaxUserAccount userAccount = null; - if (ValidUserSession) - { - // Check that an email address hasn't been supplied. - // NB Shouldn't happen as contact controls aren't displayed if user is logged in, - // hence 'System' error response and nothing more specific. - if (!StringUtil.IsEmpty(model.ContactEmailAddress)) + // Check Regions. + SysId regionIdCountry = model.ExtractSysId(model.Organisation.RegionIdCountry); + SaxRegion.Data regionCountry = Internals.GetRegion(regionIdCountry); + if (SysId.IsValid(regionIdCountry) && regionCountry == null) { - SaLogger.Warn(fn + " Contact Email supplied when user logged in. " + GetLogSuffix()); + SaLogger.Warn(fn + " Country region not found. Id: " + model.Organisation.RegionIdCountry + ". " + GetLogSuffix()); return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); } - // Retrieve user account. - userAccount = AccountMgr.GetUserAccountById(sessionData.User.UserAccountId); - if (userAccount == null) - return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); - } - else - { - // Double check that contact details have been supplied - validated by model above. - if (StringUtil.IsEmpty(model.ContactEmailAddress) || StringUtil.IsEmpty(model.ContactFirstName) || StringUtil.IsEmpty(model.ContactLastName)) + SysId regionIdAddressProvince = model.ExtractSysId(model.Organisation.Address.RegionIdProvince); + SaxRegion.Data regionProvince = Internals.GetRegion(regionIdAddressProvince); + if (SysId.IsValid(regionIdAddressProvince) && regionProvince == null) { - SaLogger.Warn(fn + " Incomplete contact details supplied."); + SaLogger.Warn(fn + " Province region not found. Id: " + model.Organisation.Address.RegionIdProvince + ". " + GetLogSuffix()); return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); } - // Check that the email doesn't exist. - // NB This is validated by the model and shouldn't be required here. - userAccount = AccountMgr.GetUserAccountByEmailAddress(model.ContactEmailAddress); - if (userAccount != null) - return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); - userAccount = AccountMgr.CreateUserAccount(); - userAccount.EmailAddress = model.ContactEmailAddress; - userAccount.FirstName = model.ContactFirstName; - userAccount.LastName = model.ContactLastName; - if (!AccountMgr.InsertUserAccount(userAccount, DbUpdateInfo)) - { - SaLogger.Warn(fn + " Failed to insert user contact - " + AccountMgr.ErrorStateMessage); - return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); - } - } - SysId organisationSportId = model.ExtractSysId(model.OrganisationSportId); - if (SysId.IsValid(organisationSportId)) - { - // Add User Sport if not already present. - // NB This will also reactivate an inactive or deleted User Sport. - SaxUserSport.Params prmUserSport = new SaxUserSport.Params(); - prmUserSport.UserAccountIdsIncluded.Add(userAccount.Id); - prmUserSport.SportIdsIncluded.Add(organisationSportId); - prmUserSport.StatusCat = SaxUserSport.StatusCat.Any; - SaxUserSport userSport = AccountMgr.GetUserSport(prmUserSport); - if (userSport == null) - userSport = AccountMgr.CreateUserSport(userAccount.Id, organisationSportId); - userSport.Status = SaxUserSport.DefaultStatus; - if (!SysId.IsValid(userSport.Id)) + // User does not need to be logged in, but user details must be supplied if not. + SaxUserAccount userAccount = null; + if (ValidUserSession) { - if (!AccountMgr.InsertUserSport(userSport, DbUpdateInfo)) + // Check that an email address hasn't been supplied. + // NB Shouldn't happen as contact controls aren't displayed if user is logged in, + // hence 'System' error response and nothing more specific. + if (!StringUtil.IsEmpty(model.ContactEmailAddress)) { - // Logg error but don't abort the request. - SaLogger.Warn(fn + " Failed to insert User Sport: " + AccountMgr.ErrorStateMessage); + SaLogger.Warn(fn + " Contact Email supplied when user logged in. " + GetLogSuffix()); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); } + // Retrieve user account. + userAccount = AccountMgr.GetUserAccountById(sessionData.User.UserAccountId); + disposableItems.Add(userAccount); + if (userAccount == null) + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); } else { - if (!AccountMgr.UpdateUserSport(userSport, DbUpdateInfo)) + // Double check that contact details have been supplied - validated by model above. + if (StringUtil.IsEmpty(model.ContactEmailAddress) || StringUtil.IsEmpty(model.ContactFirstName) || StringUtil.IsEmpty(model.ContactLastName)) { - // Logg error but don't abort the request. - SaLogger.Warn(fn + " Failed to update User Sport: " + AccountMgr.ErrorStateMessage); + SaLogger.Warn(fn + " Incomplete contact details supplied."); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + // Check that the email doesn't exist. + // NB This is validated by the model and shouldn't be required here. + userAccount = AccountMgr.GetUserAccountByEmailAddress(model.ContactEmailAddress); + disposableItems.Add(userAccount); + if (userAccount != null) + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + userAccount = AccountMgr.CreateUserAccount(); + userAccount.EmailAddress = model.ContactEmailAddress; + userAccount.FirstName = model.ContactFirstName; + userAccount.LastName = model.ContactLastName; + if (!AccountMgr.InsertUserAccount(userAccount, DbUpdateInfo)) + { + SaLogger.Warn(fn + " Failed to insert user contact - " + AccountMgr.ErrorStateMessage); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); } } - } - // Create Organisation. - SaxOrganisation organisation = AccountMgr.CreateOrganisation(); - organisation.Name = model.OrganisationName; - organisation.OrganisationType = model.GetOrganisationType(); - organisation.OrganisationCategory = model.GetOrganisationCategory(); - organisation.SportIdPrimary = organisationSportId; - organisation.RegionIdPrimary = model.ExtractSysId(model.OrganisationRegionIdCountry); - organisation.PhoneMain = model.OrganisationPhoneMain; - organisation.Status = SaStatus.Awaiting; - if (!AccountMgr.InsertOrganisation(organisation, DbUpdateInfo)) - { - SaLogger.Warn(fn + " Failed to insert organisation - " + AccountMgr.ErrorStateMessage); - return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); - } + SysId organisationSportId = model.ExtractSysId(model.Organisation.SportId); + if (SysId.IsValid(organisationSportId)) + { + // Add User Sport if not already present. + // NB This will also reactivate an inactive or deleted User Sport. + SaxUserSport.Params prmUserSport = new SaxUserSport.Params(); + prmUserSport.UserAccountIdsIncluded.Add(userAccount.Id); + prmUserSport.SportIdsIncluded.Add(organisationSportId); + prmUserSport.StatusCat = SaxUserSport.StatusCat.Any; + SaxUserSport userSport = AccountMgr.GetUserSport(prmUserSport); + if (userSport == null) + userSport = AccountMgr.CreateUserSport(userAccount.Id, organisationSportId); + disposableItems.Add(userSport); + userSport.Status = SaxUserSport.DefaultStatus; + if (!SysId.IsValid(userSport.Id)) + { + if (!AccountMgr.InsertUserSport(userSport, DbUpdateInfo)) + { + // Logg error but don't abort the request. + SaLogger.Warn(fn + " Failed to insert User Sport: " + AccountMgr.ErrorStateMessage); + } + } + else + { + if (!AccountMgr.UpdateUserSport(userSport, DbUpdateInfo)) + { + // Logg error but don't abort the request. + SaLogger.Warn(fn + " Failed to update User Sport: " + AccountMgr.ErrorStateMessage); + } + } + } - // Add user as member of organisation. - SaxUserOrganisation userOrganisation = AccountMgr.CreateUserOrganisation(userAccount.Id, organisation.Id); - userOrganisation.OrganisationRoles = new [] { Sax.OrganisationRole.Member, Sax.OrganisationRole.Admin }; - if (!AccountMgr.InsertUserOrganisation(userOrganisation, DbUpdateInfo)) - { - SaLogger.Warn(fn + " Failed to insert user organisation - " + AccountMgr.ErrorStateMessage); - return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); - } + // Create Organisation. + SaxOrganisation organisation = AccountMgr.CreateOrganisation(); + disposableItems.Add(organisation); + organisation.Name = model.Organisation.Name; + organisation.OrganisationType = model.Organisation.GetOrganisationType(); + organisation.OrganisationCategory = model.Organisation.GetOrganisationCategory(); + organisation.SportIdPrimary = organisationSportId; + organisation.RegionIdPrimary = regionIdCountry; + organisation.PhoneMain = model.Organisation.PhoneMain; + organisation.Status = SaStatus.Awaiting; + if (!AccountMgr.InsertOrganisation(organisation, DbUpdateInfo)) + { + SaLogger.Warn(fn + " Failed to insert organisation - " + AccountMgr.ErrorStateMessage); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } - // Create Organisation address. - SaxItemAddress organisationAddress = ItemDataMgr.CreateItemAddress(organisation.GetItemId(), Sax.AddressType.Office); - organisationAddress.Line1 = model.OrganisationAddressLine1; - organisationAddress.Line2 = model.OrganisationAddressLine2; - organisationAddress.Line3 = model.OrganisationAddressLine3; - organisationAddress.Town = model.OrganisationAddressTown; - organisationAddress.Province = model.OrganisationAddressProvince; - organisationAddress.RegionIdProvince = model.ExtractSysId(model.OrganisationAddressRegionIdProvince); - if (SysId.IsValid(regionCountry.Id)) - { - organisationAddress.Country = regionCountry.Name; - organisationAddress.RegionIdCountry = regionCountry.Id; - } - else organisationAddress.Country = model.OrganisationAddressCountry; - organisationAddress.PostalCode = model.OrganisationAddressPostalCode; - if (!ItemDataMgr.InsertItemAddress(organisationAddress, DbUpdateInfo)) - { - SaLogger.Warn(fn + " Failed to insert organisation address - " + ItemDataMgr.ErrorStateMessage); - return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + // Add user as member of organisation. + SaxUserOrganisation userOrganisation = AccountMgr.CreateUserOrganisation(userAccount.Id, organisation.Id); + disposableItems.Add(userOrganisation); + userOrganisation.OrganisationRoles = new[] { Sax.OrganisationRole.Member, Sax.OrganisationRole.Admin }; + if (!AccountMgr.InsertUserOrganisation(userOrganisation, DbUpdateInfo)) + { + SaLogger.Warn(fn + " Failed to insert user organisation - " + AccountMgr.ErrorStateMessage); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } + + // Create Organisation address. + SaxItemAddress organisationAddress = ItemDataMgr.CreateItemAddress(organisation.GetItemId(), SaxItemAddress.DefaultOrganisationAddressType); + disposableItems.Add(organisationAddress); + organisationAddress.Line1 = model.Organisation.Address.Line1; + organisationAddress.Line2 = model.Organisation.Address.Line2; + organisationAddress.Line3 = model.Organisation.Address.Line3; + organisationAddress.Town = model.Organisation.Address.Town; + if (regionProvince != null) + { + organisationAddress.Province = regionProvince.Name; + organisationAddress.RegionIdProvince = regionProvince.Id; + } + else + { + if (model.Organisation.Address.Province != null) + organisationAddress.Province = model.Organisation.Address.Province; + } + if (regionCountry != null) + { + organisationAddress.Country = regionCountry.Name; + organisationAddress.RegionIdCountry = regionCountry.Id; + } + else + { + if (model.Organisation.Address.Country != null) + organisationAddress.Country = model.Organisation.Address.Country; + } + organisationAddress.PostalCode = model.Organisation.Address.PostalCode; + if (!ItemDataMgr.InsertItemAddress(organisationAddress, DbUpdateInfo)) + { + SaLogger.Warn(fn + " Failed to insert organisation address - " + ItemDataMgr.ErrorStateMessage); + return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"])); + } } // Complete response. diff --git a/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax.cs b/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax.cs index c218bcc..4f50e37 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController-Ajax.cs @@ -145,7 +145,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers // Organisation filter SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params(); - prmUserOrganisation.UserAccountIdsIncluded.Add(SessionData.User.UserAccountId); + prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId); prmUserOrganisation.OrganisationMembersOnly = true; prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly; prmUserOrganisation.SortColumns.Add(colOrganisationName); diff --git a/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController.cs b/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController.cs index 3a9c4ff..9730536 100644 --- a/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController.cs +++ b/SaxoniteCoreWebOnline/Online/Controllers/OrganisationController.cs @@ -34,8 +34,35 @@ namespace Saxonite.Net.Core.Web.Online.Controllers if (!ValidUserSession) return RedirectToAction("", ""); - // No 'Index' view as yet - default to 'Opportunities' view. - return RedirectToAction("Opportunities", "Organisation"); + // No 'Index' view as yet - default to home page. + return RedirectToAction("", ""); + } + + //------------------------------------------------------------------- + [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); + if (organisationData == null) + return RedirectToAction("", ""); + + // Make a note of the filter values. + model.Filter.OrganisationId = SysId.ToString(organisationData.Id); + model.Filter.OrganisationCaption = organisationData.Caption; + SessionData_Online.Filter.OrganisationIdMember = organisationData.Id; + SessionData_Online.Filter.OrganisationCaptionMember = organisationData.Caption; + + return View(model); } //------------------------------------------------------------------- @@ -103,7 +130,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers { // Check that user is associated with organisations. SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params(); - prmUserOrganisation.UserAccountIdsIncluded.Add(SessionData.User.UserAccountId); + prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId); prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly; if (AccountMgr.GetUserOrganisationCount(prmUserOrganisation) < 1) return null; @@ -117,7 +144,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers ColumnDfn colOrganisationId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.OrganisationId); ColumnDfn colOrganisationName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Name); prmUserOrganisation = new SaxUserOrganisation.Params(); - prmUserOrganisation.UserAccountIdsIncluded.Add(SessionData.User.UserAccountId); + prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId); if (SysId.IsValid(filterOrganisationId)) prmUserOrganisation.OrganisationIdsIncluded.Add(filterOrganisationId); prmUserOrganisation.OrganisationMembersOnly = true; diff --git a/SaxoniteCoreWebOnline/Online/Models/ModelData_Address.cs b/SaxoniteCoreWebOnline/Online/Models/ModelData_Address.cs new file mode 100644 index 0000000..50f9d63 --- /dev/null +++ b/SaxoniteCoreWebOnline/Online/Models/ModelData_Address.cs @@ -0,0 +1,127 @@ +using Sarand.Net.Standard.Base.App; +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.Base.App; +using Saxonite.Net.Core.Web.Base.App; +using Saxonite.Net.Core.Web.Base.Controllers; +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.Models +{ + //======================================================================= + /// + /// Address model data properties. + /// + public class ModelData_Address : ModelData_Online + { + //------------------------------------------------------------------- + // Construction. + public ModelData_Address(SaxModel_Online model, String controlNameSuffix) : base(model) + { + this.ControlNameSuffix = StringUtil.EmptyOnNull(controlNameSuffix) + "Address"; + } + + //------------------------------------------------------------------- + // Properties. + private String ControlNameSuffix { get; } + // Address properties. + public String Id { get; set; } + public String Line1 { get; set; } + public String Line2 { get; set; } + public String Line3 { get; set; } + public String Town { get; set; } + public String Province { get; set; } + public String RegionIdProvince { get; set; } + public String Country { get; set; } + public String PostalCode { get; set; } + + //------------------------------------------------------------------- + // Validation. + //------------------------------------------------------------------- + // Address. + public bool ValidateAddressData(SaxController_Base.AjaxResponse_Data responseData) + { + + // Address Line 1 - mandatory. + responseData.SetControlValue(ControlNameSuffix + "Line1", Line1); + if (StringUtil.IsEmpty(Line1)) + responseData.SetControlError(ControlNameSuffix + "Line1", Model.Localiser["msg.validation.mandatory.value"]); + else if (StringUtil.GetLength(Line1) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line1)) + responseData.SetControlError(ControlNameSuffix + "Line1", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line1)]); + + // Address Line 2 - optional. + if (Line2 != null) + { + responseData.SetControlValue(ControlNameSuffix + "Line2", Line2); + if (!StringUtil.IsEmpty(Line2)) + { + if (StringUtil.GetLength(Line2) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line2)) + responseData.SetControlError(ControlNameSuffix + "Line2", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line2)]); + } + } + + // Address Line 3 - optional. + if (Line3 != null) + { + responseData.SetControlValue(ControlNameSuffix + "Line3", Line3); + if (!StringUtil.IsEmpty(Line3)) + { + if (StringUtil.GetLength(Line3) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line3)) + responseData.SetControlError(ControlNameSuffix + "Line3", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line3)]); + } + } + + // Address Town - mandatory. + responseData.SetControlValue(ControlNameSuffix + "Town", Town); + if (StringUtil.IsEmpty(Town)) + responseData.SetControlError(ControlNameSuffix + "Town", Model.Localiser["msg.validation.mandatory.value"]); + else if (StringUtil.GetLength(Town) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Town)) + responseData.SetControlError(ControlNameSuffix + "Town", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Town)]); + + // Address Province - optional. + if (Province != null) + { + responseData.SetControlValue(ControlNameSuffix + "Province", Province); + if (!StringUtil.IsEmpty(Province)) + { + if (StringUtil.GetLength(Province) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Province)) + responseData.SetControlError(ControlNameSuffix + "Province", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Province)]); + } + } + + // Address Country - optional. + if (Country != null) + { + responseData.SetControlValue(ControlNameSuffix + "Country", Country); + if (!StringUtil.IsEmpty(Country)) + { + if (StringUtil.GetLength(Country) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Country)) + responseData.SetControlError(ControlNameSuffix + "Country", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Country)]); + } + } + + // Address PostalCode - optional. + if (PostalCode != null) + { + responseData.SetControlValue(ControlNameSuffix + "PostalCode", PostalCode); + if (!StringUtil.IsEmpty(PostalCode)) + { + if (StringUtil.GetLength(PostalCode) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_PostalCode)) + responseData.SetControlError(ControlNameSuffix + "PostalCode", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_PostalCode)]); + } + } + + return !responseData.HasControlErrors(); + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SaxoniteCoreWebOnline/Online/Models/ModelData_Online.cs b/SaxoniteCoreWebOnline/Online/Models/ModelData_Online.cs new file mode 100644 index 0000000..06e67d0 --- /dev/null +++ b/SaxoniteCoreWebOnline/Online/Models/ModelData_Online.cs @@ -0,0 +1,38 @@ +using Sarand.Net.Standard.Base.App; +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.Base.App; +using Saxonite.Net.Core.Web.Base.App; +using Saxonite.Net.Core.Web.Base.Controllers; +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.Models +{ + //======================================================================= + /// + /// Online model data. + /// + public class ModelData_Online + { + //------------------------------------------------------------------- + // Construction. + public ModelData_Online(SaxModel_Online model) + { + this.Model = model; + } + + //------------------------------------------------------------------- + // Properties. + public SaxModel_Online Model { get; } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SaxoniteCoreWebOnline/Online/Models/ModelData_Organisation.cs b/SaxoniteCoreWebOnline/Online/Models/ModelData_Organisation.cs new file mode 100644 index 0000000..28daabf --- /dev/null +++ b/SaxoniteCoreWebOnline/Online/Models/ModelData_Organisation.cs @@ -0,0 +1,116 @@ +using Sarand.Net.Standard.Base.App; +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.Base.App; +using Saxonite.Net.Core.Web.Base.App; +using Saxonite.Net.Core.Web.Base.Controllers; +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.Models +{ + //======================================================================= + /// + /// Organisation model data properties. + /// + public class ModelData_Organisation : ModelData_Online + { + //------------------------------------------------------------------- + // Construction. + public ModelData_Organisation(SaxModel_Online model, String controlNameSuffix = "Organisation") : base(model) + { + this.ControlNameSuffix = StringUtil.EmptyOnNull(controlNameSuffix); + Address = new ModelData_Address(model, ControlNameSuffix); + } + + //------------------------------------------------------------------- + // Properties. + private String ControlNameSuffix { get; } + // Organisation properties. + public String Id { get; set; } + public String Name { get; set; } + public String Type { get; set; } + public Sax.OrganisationType GetOrganisationType() { return (Sax.OrganisationType)Model.OrganisationTypeCodes.GetTypeForCode(Type); } + public String Category { get; set; } + public Sax.OrganisationCategory GetOrganisationCategory() { return (Sax.OrganisationCategory)Model.OrganisationCategoryCodes.GetTypeForCode(Category); } + public String SportId { get; set; } + public String RegionIdCountry { get; set; } + public String PhoneMain { get; set; } + // Address. + public ModelData_Address Address { get; } + + //------------------------------------------------------------------- + // Validation. + //------------------------------------------------------------------- + // Organisation. + public bool ValidateOrganisationData(SaxController_Base.AjaxResponse_Data responseData) + { + + // Name - mandatory. + responseData.SetControlValue(ControlNameSuffix + "Name", Name); + if (StringUtil.IsEmpty(Name)) + responseData.SetControlError(ControlNameSuffix + "Name", Model.Localiser["msg.validation.mandatory.value"]); + else if (StringUtil.GetLength(Name) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_Name)) + responseData.SetControlError(ControlNameSuffix + "Name", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_Name)]); + else if (SysId.IsValid(Model.ExtractSysId(RegionIdCountry))) + { + // Ensure that the organisation name is unique within the country. + SaxOrganisation.Params prmOrganisation = new SaxOrganisation.Params(); + if (SysId.IsValid(Model.ExtractSysId(Id))) + prmOrganisation.IdsExcluded.Add(Model.ExtractSysId(Id)); + prmOrganisation.NameFull = Name; + prmOrganisation.RegionIdsIncluded.Add(Model.ExtractSysId(RegionIdCountry)); + prmOrganisation.StatusCat = SaxOrganisation.StatusCat.Any; + if (Model.AccountMgr.GetOrganisationCount(prmOrganisation) > 0) + responseData.SetControlError(ControlNameSuffix + "Name", Model.Localiser["msg.validation.duplicate.value"]); + } + + // Organisation Category - mandatory. + if (StringUtil.IsEmpty(Category)) + responseData.SetControlError(ControlNameSuffix + "Category", Model.Localiser["msg.validation.mandatory.value"]); + + // Organisation Type - mandatory. + if (StringUtil.IsEmpty(Type)) + responseData.SetControlError(ControlNameSuffix + "Type", Model.Localiser["msg.validation.mandatory.value"]); + + // Sport - mandatory for certain organisation categories. + if (StringUtil.IsEmpty(SportId) && SaxOrganisation.IsSportMandatory(GetOrganisationCategory())) + responseData.SetControlError(ControlNameSuffix + "SportId", Model.Localiser["msg.validation.mandatory.value"]); + else if (!StringUtil.IsEmpty(SportId) && !SysId.IsValid(Model.ExtractSysId(SportId))) + responseData.SetControlError(ControlNameSuffix + "SportId", Model.Localiser["msg.validation.invalid.value"]); + + // Region Country - mandatory. + if (StringUtil.IsEmpty(RegionIdCountry)) + responseData.SetControlError(ControlNameSuffix + "RegionIdCountry", Model.Localiser["msg.validation.mandatory.value"]); + else if (!SysId.IsValid(Model.ExtractSysId(RegionIdCountry))) + responseData.SetControlError(ControlNameSuffix + "RegionIdCountry", Model.Localiser["msg.validation.invalid.value"]); + + // Phone Main - optional. + if (PhoneMain != null) + { + responseData.SetControlValue(ControlNameSuffix + "PhoneMain", PhoneMain); + if (!StringUtil.IsEmpty(PhoneMain)) + { + if (!SacsDataValidationHelper.IsValidPhone(PhoneMain)) + responseData.SetControlError(ControlNameSuffix + "PhoneMain", Model.Localiser["msg.validation.invalid.value"]); + else if (StringUtil.GetLength(PhoneMain) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_PhoneMain)) + responseData.SetControlError(ControlNameSuffix + "PhoneMain", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_PhoneMain)]); + } + } + + // Address. + Address.ValidateAddressData(responseData); + + return !responseData.HasControlErrors(); + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SaxoniteCoreWebOnline/Online/Models/Model_Account.cs b/SaxoniteCoreWebOnline/Online/Models/Model_Account.cs index f32070e..6260857 100644 --- a/SaxoniteCoreWebOnline/Online/Models/Model_Account.cs +++ b/SaxoniteCoreWebOnline/Online/Models/Model_Account.cs @@ -23,6 +23,10 @@ namespace Saxonite.Net.Core.Web.Online.Models public Model_Account(SaxLocaliser localiser) : base(localiser) { + // Model data. + Organisation = new ModelData_Organisation(this); + + // Page includes. AdditionalFiles_CSS.Add("css/sax-account.css"); AdditionalFiles_JS.Add("js/sax-account.js"); AdditionalFiles_JS.Add("js/sax-usr-pro.js"); @@ -74,7 +78,13 @@ namespace Saxonite.Net.Core.Web.Online.Models public String ProfileSportAbout { get; set; } //------------------------------------------------------------------- - // Validate users's contact details. + // Organisation properties. + public ModelData_Organisation Organisation { get; } + + //------------------------------------------------------------------- + // Validate modela data. + //------------------------------------------------------------------- + // Validate contact details. public bool ValidateContactDetails(SaxController_Base.AjaxResponse_Data responseData) { //--------------------------------------------------------------- @@ -166,6 +176,7 @@ namespace Saxonite.Net.Core.Web.Online.Models } //------------------------------------------------------------------- + // Validate Sport data. public bool ValidateProfileSportData(SaxController_Base.AjaxResponse_Data responseData) { // Sport. @@ -190,6 +201,15 @@ namespace Saxonite.Net.Core.Web.Online.Models return !responseData.HasControlErrors(); } + //------------------------------------------------------------------- + // Validate Organisation data. + public bool ValidateProfileOrganisationData(SaxController_Base.AjaxResponse_Data responseData) + { + Organisation.ValidateOrganisationData(responseData); + + return !responseData.HasControlErrors(); + } + //------------------------------------------------------------------- } //======================================================================= diff --git a/SaxoniteCoreWebOnline/Online/Models/Model_Organisation.cs b/SaxoniteCoreWebOnline/Online/Models/Model_Organisation.cs index 5e37684..8b7574d 100644 --- a/SaxoniteCoreWebOnline/Online/Models/Model_Organisation.cs +++ b/SaxoniteCoreWebOnline/Online/Models/Model_Organisation.cs @@ -23,6 +23,10 @@ namespace Saxonite.Net.Core.Web.Online.Models public Model_Organisation(SaxLocaliser localiser) : base(localiser) { + // Model data. + Organisation = new ModelData_Organisation(this); + + // Page includes. //AdditionalFiles_CSS.Add("css/sax-org.css"); AdditionalFiles_JS.Add("js/sax-org.js"); } @@ -39,23 +43,7 @@ namespace Saxonite.Net.Core.Web.Online.Models //------------------------------------------------------------------- // Organisation properties. - public String OrganisationName { get; set; } - public String OrganisationType { get; set; } - public Sax.OrganisationType GetOrganisationType() { return (Sax.OrganisationType)OrganisationTypeCodes.GetTypeForCode(OrganisationType); } - public String OrganisationCategory { get; set; } - public Sax.OrganisationCategory GetOrganisationCategory() { return (Sax.OrganisationCategory)OrganisationCategoryCodes.GetTypeForCode(OrganisationCategory); } - public String OrganisationSportId { get; set; } - public String OrganisationRegionIdCountry { get; set; } - public String OrganisationPhoneMain { get; set; } - // Organisation address - public String OrganisationAddressLine1 { get; set; } - public String OrganisationAddressLine2 { get; set; } - public String OrganisationAddressLine3 { get; set; } - public String OrganisationAddressTown { get; set; } - public String OrganisationAddressProvince { get; set; } - public String OrganisationAddressRegionIdProvince { get; set; } - public String OrganisationAddressCountry { get; set; } - public String OrganisationAddressPostalCode { get; set; } + public ModelData_Organisation Organisation { get; set; } // User - for organisation request. public String ContactEmailAddress { get; set; } public String ContactFirstName { get; set; } @@ -101,124 +89,8 @@ namespace Saxonite.Net.Core.Web.Online.Models responseData.SetControlError(nameof(ContactLastName), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName)]); } - // Organisation Name - mandatory. - responseData.SetControlValue(nameof(OrganisationName), OrganisationName); - if (StringUtil.IsEmpty(OrganisationName)) - responseData.SetControlError(nameof(OrganisationName), Localiser["msg.validation.mandatory.value"]); - else if (StringUtil.GetLength(OrganisationName) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_Name)) - responseData.SetControlError(nameof(OrganisationName), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_Name)]); - else if (SysId.IsValid(ExtractSysId(OrganisationRegionIdCountry))) - { - // Ensure that the organisation name is unique within the country. - SaxOrganisation.Params prmOrganisation = new SaxOrganisation.Params(); - prmOrganisation.NameFull = OrganisationName; - prmOrganisation.RegionIdsIncluded.Add(ExtractSysId(OrganisationRegionIdCountry)); - prmOrganisation.StatusCat = SaxOrganisation.StatusCat.Any; - if (AccountMgr.GetOrganisationCount(prmOrganisation) > 0) - responseData.SetControlError(nameof(OrganisationName), Localiser["msg.validation.duplicate.value"]); - } - - // Organisation Category - mandatory. - if (StringUtil.IsEmpty(OrganisationCategory)) - responseData.SetControlError(nameof(OrganisationCategory), Localiser["msg.validation.mandatory.value"]); - - // Organisation Type - mandatory. - if (StringUtil.IsEmpty(OrganisationType)) - responseData.SetControlError(nameof(OrganisationType), Localiser["msg.validation.mandatory.value"]); - - // Organisation Sport - mandatory for certain organisation categories. - if (StringUtil.IsEmpty(OrganisationSportId) && SaxOrganisation.IsSportMandatory(GetOrganisationCategory())) - responseData.SetControlError(nameof(OrganisationSportId), Localiser["msg.validation.mandatory.value"]); - else if (!StringUtil.IsEmpty(OrganisationSportId) && !SysId.IsValid(ExtractSysId(OrganisationSportId))) - responseData.SetControlError(nameof(OrganisationSportId), Localiser["msg.validation.invalid.value"]); - - // Organisation Region Country - mandatory. - if (StringUtil.IsEmpty(OrganisationRegionIdCountry)) - responseData.SetControlError(nameof(OrganisationRegionIdCountry), Localiser["msg.validation.mandatory.value"]); - else if (!SysId.IsValid(ExtractSysId(OrganisationRegionIdCountry))) - responseData.SetControlError(nameof(OrganisationRegionIdCountry), Localiser["msg.validation.invalid.value"]); - - // Organisation Address Line 1 - mandatory. - responseData.SetControlValue(nameof(OrganisationAddressLine1), OrganisationAddressLine1); - if (StringUtil.IsEmpty(OrganisationAddressLine1)) - responseData.SetControlError(nameof(OrganisationAddressLine1), Localiser["msg.validation.mandatory.value"]); - else if (StringUtil.GetLength(OrganisationAddressLine1) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line1)) - responseData.SetControlError(nameof(OrganisationAddressLine1), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line1)]); - - // Organisation Address Line 2 - optional. - if (OrganisationAddressLine2 != null) - { - responseData.SetControlValue(nameof(OrganisationAddressLine2), OrganisationAddressLine2); - if (!StringUtil.IsEmpty(OrganisationAddressLine2)) - { - if (StringUtil.GetLength(OrganisationAddressLine2) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line2)) - responseData.SetControlError(nameof(OrganisationAddressLine2), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line2)]); - } - } - - // Organisation Address Line 3 - optional. - if (OrganisationAddressLine3 != null) - { - responseData.SetControlValue(nameof(OrganisationAddressLine3), OrganisationAddressLine3); - if (!StringUtil.IsEmpty(OrganisationAddressLine3)) - { - if (StringUtil.GetLength(OrganisationAddressLine3) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line3)) - responseData.SetControlError(nameof(OrganisationAddressLine3), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line3)]); - } - } - - // Organisation Address Town - mandatory. - responseData.SetControlValue(nameof(OrganisationAddressTown), OrganisationAddressTown); - if (StringUtil.IsEmpty(OrganisationAddressTown)) - responseData.SetControlError(nameof(OrganisationAddressTown), Localiser["msg.validation.mandatory.value"]); - else if (StringUtil.GetLength(OrganisationAddressTown) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Town)) - responseData.SetControlError(nameof(OrganisationAddressTown), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Town)]); - - // Organisation Address Province - optional. - if (OrganisationAddressProvince != null) - { - responseData.SetControlValue(nameof(OrganisationAddressProvince), OrganisationAddressProvince); - if (!StringUtil.IsEmpty(OrganisationAddressProvince)) - { - if (StringUtil.GetLength(OrganisationAddressProvince) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Province)) - responseData.SetControlError(nameof(OrganisationAddressProvince), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Province)]); - } - } - - // Organisation Address Country - optional. - if (OrganisationAddressCountry != null) - { - responseData.SetControlValue(nameof(OrganisationAddressCountry), OrganisationAddressCountry); - if (!StringUtil.IsEmpty(OrganisationAddressCountry)) - { - if (StringUtil.GetLength(OrganisationAddressCountry) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Country)) - responseData.SetControlError(nameof(OrganisationAddressCountry), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Country)]); - } - } - - // Organisation Address PostalCode - optional. - if (OrganisationAddressPostalCode != null) - { - responseData.SetControlValue(nameof(OrganisationAddressPostalCode), OrganisationAddressPostalCode); - if (!StringUtil.IsEmpty(OrganisationAddressPostalCode)) - { - if (StringUtil.GetLength(OrganisationAddressPostalCode) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_PostalCode)) - responseData.SetControlError(nameof(OrganisationAddressPostalCode), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_PostalCode)]); - } - } - - // Organisation Phone Main - optional. - if (OrganisationPhoneMain != null) - { - responseData.SetControlValue(nameof(OrganisationPhoneMain), OrganisationPhoneMain); - if (!StringUtil.IsEmpty(OrganisationPhoneMain)) - { - if (!SacsDataValidationHelper.IsValidPhone(OrganisationPhoneMain)) - responseData.SetControlError(nameof(OrganisationPhoneMain), Localiser["msg.validation.invalid.value"]); - else if (StringUtil.GetLength(OrganisationPhoneMain) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_PhoneMain)) - responseData.SetControlError(nameof(OrganisationPhoneMain), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_PhoneMain)]); - } - } + // Organisation properties. + Organisation.ValidateOrganisationData(responseData); return !responseData.HasControlErrors(); } diff --git a/SaxoniteCoreWebOnline/Online/Models/Model_Organisation_Events.cs b/SaxoniteCoreWebOnline/Online/Models/Model_Organisation_Events.cs new file mode 100644 index 0000000..5a29361 --- /dev/null +++ b/SaxoniteCoreWebOnline/Online/Models/Model_Organisation_Events.cs @@ -0,0 +1,120 @@ +using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Utils; +using Saxonite.Base.App; +using Saxonite.Net.Core.Web.Base.App; +using Saxonite.Net.Core.Web.Base.Controllers; +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.Models +{ + //======================================================================= + public class Model_Organisation_Events : SaxModel_Online + { + //------------------------------------------------------------------- + // Construction. + public Model_Organisation_Events(SaxLocaliser localiser) : + base(localiser) + { + //AdditionalFiles_CSS.Add("css/sax-org-evt.css"); + AdditionalFiles_JS.Add("js/sax-org-evt.js"); + } + + //------------------------------------------------------------------- + // List configuration. + public class EventFilterData + { + public String OrganisationId { get; set; } + public String OrganisationCaption { get; set; } + public String Event { get; set; } + } + public EventFilterData Filter { get; } = new EventFilterData(); + + //------------------------------------------------------------------- + // Event properties. + public String EventId { get; set; } + public String EventExists { get; set; } + // Event properties. + public String EventOrganisationId { get; set; } + // Sport. + public String EventSportIdPrimary { get; set; } + // Region. + public String EventRegionIdCountry { get; set; } + // Event Content. + public String EventDate { get; set; } + public String EventTime { get; set; } + public String EventTypeCode { get; set; } + public String EventAbout { get; set; } + public String EventStatusCode { get; set; } + public SaStatus EventStatus { get { return SacsSystem.GetStatusForCode(EventStatusCode); } } + + //------------------------------------------------------------------- + // Validation. + //------------------------------------------------------------------- + // Event. + public bool ValidateEventData(SaxController_Base.AjaxResponse_Data responseData) + { + // Event type. + if (EventTypeCode != null) + { + if (StringUtil.IsEmpty(EventTypeCode)) + responseData.SetControlError(nameof(EventTypeCode), Localiser["msg.validation.mandatory.value"]); + } + + // Event date. + if (EventDate != null) + { + } + + // Event time. + if (EventTime != null) + { + } + + // Event about. + if (EventAbout != null) + { + responseData.SetControlValue(nameof(EventAbout), EventAbout); + if (StringUtil.IsEmpty(EventAbout)) + responseData.SetControlError(nameof(EventAbout), Localiser["msg.validation.mandatory.value"]); + else if (StringUtil.GetLength(EventAbout) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_About)) + responseData.SetControlError(nameof(EventAbout), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_About)]); + } + + // Event sport. + if (EventSportIdPrimary != null) + { + SysId articleSportId = ExtractSysId(EventSportIdPrimary); + if (!SysId.IsValid(articleSportId)) + responseData.SetControlError(nameof(EventSportIdPrimary), Localiser["msg.validation.mandatory.value"]); + } + + // Event region. + if (EventRegionIdCountry != null) + { + SysId articleRegionId = ExtractSysId(EventRegionIdCountry); + if (!SysId.IsValid(articleRegionId)) + responseData.SetControlError(nameof(EventRegionIdCountry), Localiser["msg.validation.mandatory.value"]); + } + + // Event status. + if (EventStatusCode != null) + { + if (StringUtil.IsEmpty(EventStatusCode)) + responseData.SetControlError(nameof(EventStatusCode), Localiser["msg.validation.mandatory.value"]); + else if (!SaxOrganisationEvent.ValidStatuses.Contains(EventStatus)) + responseData.SetControlError(nameof(EventStatusCode), Localiser["msg.validation.invalid.value"]); + } + + return !responseData.HasControlErrors(); + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SaxoniteCoreWebOnline/Online/Models/SaxModel_Online.cs b/SaxoniteCoreWebOnline/Online/Models/SaxModel_Online.cs index c64afb2..9854741 100644 --- a/SaxoniteCoreWebOnline/Online/Models/SaxModel_Online.cs +++ b/SaxoniteCoreWebOnline/Online/Models/SaxModel_Online.cs @@ -34,13 +34,19 @@ namespace Saxonite.Net.Core.Web.Online.Models } //------------------------------------------------------------------- - // Session. + // Properties. //------------------------------------------------------------------- + // Session. public SaxSessionData_Online SessionData_Online { get { return SessionData as SaxSessionData_Online; } } + public SysId UserAccountId { get { return SessionData_Online?.User?.UserAccountId ?? null; } } + + //------------------------------------------------------------------- // Menu options. public bool MembersAllowed { get { return UserCanManageOrganisationMembers; } } public bool ArticlesAllowed { get { return UserIsJournalist || UserCanManageOrganisationArticles; } } public bool OpportunitiesAllowed { get { return UserCanManageOrganisationOpportunities; } } + + //------------------------------------------------------------------- // Security profile. public bool UserIsJournalist { get { return SessionData != null && SessionData.User != null && SessionData.User.IsJournalist; } } public bool UserCanManageOrganisationMembers @@ -50,7 +56,7 @@ namespace Saxonite.Net.Core.Web.Online.Models if (userCanManageOrganisationMembers == null && ValidUserSession) { SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params(); - prmUserOrganisation.UserAccountIdsIncluded.Add(SessionData.User.UserAccountId); + prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId); prmUserOrganisation.OrganisationMembersOnly = true; prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.Admin); prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.MemberAdmin); @@ -67,7 +73,7 @@ namespace Saxonite.Net.Core.Web.Online.Models if (userCanManageOrganisationOpportunities == null && ValidUserSession) { SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params(); - prmUserOrganisation.UserAccountIdsIncluded.Add(SessionData.User.UserAccountId); + prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId); prmUserOrganisation.OrganisationMembersOnly = true; prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.Admin); prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.OpportunityAdmin); @@ -84,7 +90,7 @@ namespace Saxonite.Net.Core.Web.Online.Models if (userCanManageOrganisationSchedule == null && ValidUserSession) { SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params(); - prmUserOrganisation.UserAccountIdsIncluded.Add(SessionData.User.UserAccountId); + prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId); prmUserOrganisation.OrganisationMembersOnly = true; prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.Admin); prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.ScheduleAdmin); @@ -101,7 +107,7 @@ namespace Saxonite.Net.Core.Web.Online.Models if (userCanManageOrganisationArticles == null && ValidUserSession) { SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params(); - prmUserOrganisation.UserAccountIdsIncluded.Add(SessionData.User.UserAccountId); + prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId); prmUserOrganisation.OrganisationMembersOnly = true; prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.Admin); prmUserOrganisation.OrganisationRolesAny.Add(Sax.OrganisationRole.ArticleAdmin); diff --git a/SaxoniteCoreWebOnline/Views/Account/Profile-Organisations.cshtml b/SaxoniteCoreWebOnline/Views/Account/Profile-Organisations.cshtml index 113fc2e..3f1e120 100644 --- a/SaxoniteCoreWebOnline/Views/Account/Profile-Organisations.cshtml +++ b/SaxoniteCoreWebOnline/Views/Account/Profile-Organisations.cshtml @@ -1,14 +1,17 @@ @model Model_Account @inject SaxLocaliser Localiser +@* Profile Organisations *@
+ @* Panel caption and burger menu *@
@Localiser["account.caption.profile.organisations"]
+ @* Burger menu *@ + @* Filter item templates *@ +
+ @* Filter Burger dropdown template - ul is ignored *@ +
    +
  • ...
  • +
+
-
-
+ @* Profile Organisations list *@ +
+ @* Item templates *@
+ @* Organisation template *@
-
-
+
+
+
+ @* Burger menu *@ + +
-
+
@Localiser["label.members"]: 
@@ -42,30 +64,34 @@
+ @* Organisation Burger dropdown template - ul is ignored *@ +
    +
  • ...
  • +
-
- -
-
-
@Localiser["account.caption.profile.organisations"]
-
-
-
-
- -
- - @using (@Html.BeginForm(FormMethod.Post, new { @id = "frmProfileOrganisations", @class = "sax-form", @onSubmit = "return false;" })) - { - } - -
- -
+ @* Profile Organisation Id form *@ + @using (Html.BeginForm(FormMethod.Post, new { @id = "frmProfileOrganisationId", @class = "sax-form", @onSubmit = "return false;" })) + { + @Html.HiddenFor(model => model.Organisation.Id, new { @id = "", @class = "OrganisationId" }) + }
+@* Profile Organisation dialog *@ +
+
+ @using (Html.BeginForm(FormMethod.Post, new { @id = "frmProfileOrganisation", @class = "sax-form", @onSubmit = "return false;" })) + { + @Html.HiddenFor(model => model.Organisation.Id, new { @id = "", @class = "OrganisationId" }) + @Html.HiddenFor(model => model.Organisation.Address.Id, new { @id = "", @class = "OrganisationAddressId" }) + + + + } +
+
+ diff --git a/SaxoniteCoreWebOnline/Views/Common/OrganisationControls.cshtml b/SaxoniteCoreWebOnline/Views/Common/OrganisationControls.cshtml new file mode 100644 index 0000000..db34736 --- /dev/null +++ b/SaxoniteCoreWebOnline/Views/Common/OrganisationControls.cshtml @@ -0,0 +1,208 @@ +@model SaxModel_Online +@inject SaxLocaliser Localiser + +
+
+ +
+
+ +@* Organisation name *@ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+
+ + @* Organisation category *@ +
+
+
+ +
+
+ @Html.DropDownList("", Model.OrganisationCategoriesForSelect, Localiser["label.select"], new { @id = "", @name = "Organisation.Category", @class = "OrganisationCategory sax-select" }) +
+
+
+
+ + @* Organisation type *@ +
+
+
+ +
+
+ @Html.DropDownList("", Model.OrganisationTypesForSelect, Localiser["label.select"], new { @id = "", @name = "Organisation.Type", @class = "OrganisationType sax-select" }) +
+
+
+
+ +
+
+ +@* Organisation sport *@ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+ +@* Organisation country *@ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+ +@* Organisation PhoneMain *@ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ +@* Organisation address - Line 1 *@ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ +@* Organisation address - Line 2 *@ +
+
+
+
+
+
+
+
+
+
+
+ +@* Organisation address - Line 3 *@ +
+
+
+
+
+
+
+
+
+
+
+ +@* Organisation address - Town *@ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ +@* Organisation address - Province *@ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ +@* Organisation address - PostalCode *@ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ diff --git a/SaxoniteCoreWebOnline/Views/Common/OrganisationRequest.cshtml b/SaxoniteCoreWebOnline/Views/Common/OrganisationRequest.cshtml index 4a3083e..8ad5be8 100644 --- a/SaxoniteCoreWebOnline/Views/Common/OrganisationRequest.cshtml +++ b/SaxoniteCoreWebOnline/Views/Common/OrganisationRequest.cshtml @@ -1,7 +1,7 @@ @model SaxModel_Online @inject SaxLocaliser Localiser @{ - String regionIdCountry = Model.ValidUserSession ? Model.SessionData.User.RegionIdCountry.ToString() : ""; + Microsoft.AspNetCore.Html.HtmlString regionIdCountry = new Microsoft.AspNetCore.Html.HtmlString(Model.ValidUserSession ? Model.GetEncryptedRegionId(Model.SessionData.User.RegionIdCountry) : ""); String regionNameCountry = Model.ValidUserSession ? Localiser.EscapeJavascriptText(Model.GetRegionCaption(Model.SessionData.User.RegionIdCountry)) : ""; } + diff --git a/SaxoniteCoreWebOnline/wwwroot/js/sax-org-req.js b/SaxoniteCoreWebOnline/wwwroot/js/sax-org-req.js index 441baa7..4aa170c 100644 --- a/SaxoniteCoreWebOnline/wwwroot/js/sax-org-req.js +++ b/SaxoniteCoreWebOnline/wwwroot/js/sax-org-req.js @@ -20,13 +20,13 @@ } or.fn.storeOrganisation = function () { - //sax.debug('refreshResults'); + //sax.debug('storeOrganisation'); or.ajax.registerOrg = or.ajax.registerOrg || { url: sax.url.base + 'Organisation/Ajax/Request', formId: 'frmOrganisationRequest', callbackFn: or.fn.handleRequestOrganisationResponse }; sax.doAjaxRequest(or.ajax.registerOrg, 50); } or.fn.handleRequestOrganisationResponse = function (response) { - //sax.debug('or.handleRequestOrganisationResponse', response); + //sax.debug('handleRequestOrganisationResponse', response); if (!response) return; sax.refreshControlValues(response.controlValues, or.$frm); if (!response.success) return; @@ -38,22 +38,23 @@ } //-------------------------------------------------------------- - sax.selectOrgSport = function () + or.selectOrgSport = function () { - sax.mdl.selectSport.fn.selectSport({ caption: sax.dlg.title.selectSport, sportId: $('.OrganisationSportId', or.$frm).val(), fnCallback: sax.onSelectOrgSport }) + sax.mdl.selectSport.fn.selectSport({ caption: sax.dlg.title.selectSport, sportId: $('.OrganisationSportId', or.$frm).val(), fnCallback: or.onSelectOrgSport }) } - sax.onSelectOrgSport = function (sport) + or.onSelectOrgSport = function (sport) { sax.clearControlError($('.OrganisationSportId', or.$frm).val(sport.id)); $('.OrganisationSportCaption', or.$frm).val(sport ? sport.name : ''); } //-------------------------------------------------------------- - sax.selectOrgRegion = function () + or.selectOrgRegionCountry = function () { - sax.mdl.selectRegion.fn.selectRegion({ caption: sax.dlg.title.selectRegion, regionId: $('.OrganisationRegionIdCountry', or.$frm).val(), typesInc:[30], fnCallback: sax.onSelectOrgRegion }) + sax.debug($('.OrganisationRegionIdCountry', or.$frm).val()); + sax.mdl.selectRegion.fn.selectRegion({ caption: sax.dlg.title.selectRegion, regionId: $('.OrganisationRegionIdCountry', or.$frm).val(), typesInc: [30], fnCallback: or.onSelectOrgRegionCountry }) } - sax.onSelectOrgRegion = function (region) + or.onSelectOrgRegionCountry = function (region) { sax.clearControlError($('.OrganisationRegionIdCountry', or.$frm).val(region.id)); $('.OrganisationRegionCaptionCountry', or.$frm).val(region ? region.name : ''); @@ -69,6 +70,8 @@ opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); or.fn.cleanUp(); }; or.$dlg = $('#dlgOrganisationRequest').dialog(opt); or.$frm = $('#frmOrganisationRequest', or.$dlg); + or.$frm.on('dblclick', 'input.OrganisationSportCaption', or.selectOrgSport).on('click', 'button.SelectSport', or.selectOrgSport); + or.$frm.on('dblclick', 'input.OrganisationRegionCaptionCountry', or.selectOrgRegionCountry).on('click', 'button.SelectRegionCountry', or.selectOrgRegionCountry); $('.sax-input, .sax-textarea', or.$frm).on('input', function () { sax.clearControlError(this); }); $('.sax-select', or.$frm).on('change', function () { sax.clearControlError(this); }); } diff --git a/SaxoniteCoreWebOnline/wwwroot/js/sax-resultsPaging.js b/SaxoniteCoreWebOnline/wwwroot/js/sax-res-pag.js similarity index 100% rename from SaxoniteCoreWebOnline/wwwroot/js/sax-resultsPaging.js rename to SaxoniteCoreWebOnline/wwwroot/js/sax-res-pag.js diff --git a/SaxoniteCoreWebOnline/wwwroot/js/sax-usr-org.js b/SaxoniteCoreWebOnline/wwwroot/js/sax-usr-org.js index 624cb07..ba8524b 100644 --- a/SaxoniteCoreWebOnline/wwwroot/js/sax-usr-org.js +++ b/SaxoniteCoreWebOnline/wwwroot/js/sax-usr-org.js @@ -26,36 +26,156 @@ } po.onRefreshProfileOrganisationsInfo = function (response) { - sax.debug('onRefreshProfileOrganisationsInfo', response); + //sax.debug('onRefreshProfileOrganisationsInfo', response); if (!response || !response.success) return; $('.sax-message', $pnl.section).stop(true, false).fadeOut(200).empty(); let items = response.organisations; if (!items) return; let $items = $('.sax-panel-results.Organisations', $pnl.section).empty(); - let $tmpl = $('.sax-panel-item-template .sax-panel-item.Organisation', $pnl.section); for (let itemIdx = 0; itemIdx < items.length; itemIdx++) - { - let item = items[itemIdx]; - let $item = $tmpl.clone().prop('id', 'ProOrg_' + item.id); - $('.OrganisationName', $item).text(item.name); - $('.OrganisationSport', $item).text(item.sportName); - $('.OrganisationRegion', $item).text(item.regionName); - $('.OrganisationMemberCount', $item).toggle(!!item.memberCount).find('.MemberCount').text(item.memberCount); - $('.OrganisationOpportunityCount', $item).toggle(!!item.opportunityCount).find('.MemberCount').text(item.opportunityCount); - $items.append($item); - } - $items.show(); + $items.append(po.populateItem(po.getItemTemplate(), items[itemIdx])); + $items.fadeIn(50); sax.showNoInfoMsg($pnl.section); $pnl.section.removeClass('sax-populating'); } + po.populateItem = function ($item, item) + { + if (!item) return; + $('.OrganisationName', $item).text(item.name); + $('.OrganisationSport', $item).text(item.sportName); + $('.OrganisationRegionCountry', $item).text(item.regionNameCountry); + $('.OrganisationMemberCount', $item).toggle(!!item.memberCount).find('.MemberCount').text(item.memberCount); + $('.OrganisationOpportunityCount', $item).toggle(!!item.opportunityCount).find('.MemberCount').text(item.opportunityCount); + + let $bgr = $('.sax-burger', $item); + let $mnu = $('ul.sax-dropdown-menu', $bgr).empty(); + if (item.admin) + { + let fnUpd = function () { po.updateOrganisation($item, item); }; + $mnu.append(po.getItemMenuOption(sax.lbl.edit, fnUpd, 'sax-edit')); + $('.sax-caption .sax-action', $item).off('click').on('click', fnUpd); + $item.off('dblclick').on('dblclick', fnUpd); + } + else $('.sax-caption .sax-action', $item).removeClass('sax-action'); + $bgr.toggle(!!$('.sax-dropdown-menu .sax-dropdown-item', $item).length); + + return $item; + } //-------------------------------------------------------------- + po.getHeaderDropdownTemplate = function () + { + return $('.sax-panel-item-template .sax-dropdown-menu.ProfileOrganisations li.sax-dropdown-item', $pnl.section).clone(); + } + po.getItemTemplate = function () + { + return $('.sax-panel-item-template .sax-panel-item.Organisation', $pnl.section).clone(); + } + po.getItemDropdownTemplate = function () + { + return $('.sax-panel-item-template .sax-dropdown-menu.ProfileOrganisation li.sax-dropdown-item', $pnl.section).clone(); + } + po.getHeaderMenuOption = function (lbl, fn, cls) + { + return po.getMenuOption(po.getHeaderDropdownTemplate(), lbl, fn, cls); + } + po.getItemMenuOption = function (lbl, fn, cls) + { + return po.getMenuOption(po.getItemDropdownTemplate(), lbl, fn, cls); + } + po.getMenuOption = function ($opt, lbl, fn, cls) + { + return $opt.find('div.sax-label').text(lbl).end().on('click', fn).addClass(cls); + } + + //-------------------------------------------------------------- + po.updateOrganisation = function ($item, item) + { + //sax.debug('po.updateOrganisation', $item, item); + $('.OrganisationId', $frm.orgId).val(item.id); + + sax.ajax.profileOrganisation = sax.ajax.profileOrganisation || { url: sax.url.base + 'Account/Ajax/GetProfileOrganisation', formId: 'frmProfileOrganisationId', callbackFn: po.doUpdateOrganisation }; + sax.doAjaxRequest(sax.ajax.profileOrganisation, 50); + } + po.doUpdateOrganisation = function (response) + { + //sax.debug('doUpdateOrganisation', response); + if (!response || !response.success) return; + let item = response.organisation; + if (!item) return; + $('.OrganisationId', $frm.org).val(item.id); + $('.OrganisationName', $frm.org).val(item.name); + $('.OrganisationCategory', $frm.org).val(item.categoryCode); + $('.OrganisationType', $frm.org).val(item.typeCode); + $('.OrganisationSportId', $frm.org).val(item.sportId); + $('.OrganisationSportCaption', $frm.org).val(item.sportName); + $('.OrganisationRegionIdCountry', $frm.org).val(item.regionIdCountry); + $('.OrganisationRegionCaptionCountry', $frm.org).val(item.regionNameCountry); + let address = item.address || {}; + $('input.OrganisationAddressId', $frm.org).val(address.id); + $('input.OrganisationAddressLine1', $frm.org).val(address.line1); + $('input.OrganisationAddressLine2', $frm.org).val(address.line2); + $('input.OrganisationAddressLine3', $frm.org).val(address.line3); + $('input.OrganisationAddressTown', $frm.org).val(address.town); + $('input.OrganisationAddressProvince', $frm.org).val(address.province); + $('input.OrganisationAddressCountry', $frm.org).val(address.country); + $('input.OrganisationAddressPostalCode', $frm.org).val(address.postalCode); + sax.openDialog($dlg.org, 600, 600); + } + po.storeOrganisation = function () + { + let fn = function (response) + { + //sax.debug('handleStoreOrganisationResponse', response); + if (!response) return; + sax.refreshControlValues(response.controlValues, $frm.org); + if (!response.success) return; + $dlg.org.dialog('close'); + po.cleanUp(); + } + or.ajax.storeOrg = or.ajax.storeOrg || { url: sax.url.base + 'Account/Ajax/StoreProfileOrganisation', formId: 'frmProfileOrganisation', callbackFn: fn }; + sax.doAjaxRequest(or.ajax.storeOrg, 50); + } + po.cleanUp = function () + { + } + + //-------------------------------------------------------------- + po.selectOrgSport = function () + { + sax.mdl.selectSport.fn.selectSport({ caption: sax.dlg.title.selectSport, sportId: $('.OrganisationSportId', $frm.org).val(), fnCallback: po.onSelectOrgSport }) + } + po.onSelectOrgSport = function (sport) + { + sax.clearControlError($('.OrganisationSportId', $frm.org).val(sport.id)); + $('.OrganisationSportCaption', $frm.org).val(sport ? sport.name : ''); + } + + //-------------------------------------------------------------- + po.selectOrgRegionCountry = function () + { + sax.mdl.selectRegion.fn.selectRegion({ caption: sax.dlg.title.selectRegion, regionId: $('.OrganisationRegionIdCountry', $frm.org).val(), typesInc: [30], fnCallback: po.onSelectOrgRegionCountry }) + } + po.onSelectOrgRegionCountry = function (region) + { + sax.clearControlError($('.OrganisationRegionIdCountry', $frm.org).val(region.id)); + $('.OrganisationRegionCaptionCountry', $frm.org).val(region ? region.name : ''); + } //-------------------------------------------------------------- $(function () { $pnl.section = $('.sax-panel-section.ProfileOrganisations'); + $frm.orgId = $('#frmProfileOrganisationId', $pnl.section); + + var opt = sax.dlgOpts(); + opt.buttons[sax.dlg.btn.ok] = function () { po.storeOrganisation(); }; + opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); }; + $dlg.org = $('#dlgProfileOrganisation').dialog(opt); + $frm.org = $('#frmProfileOrganisation', $dlg.org); + $frm.org.on('dblclick', 'input.OrganisationSportCaption', po.selectOrgSport).on('click', 'button.SelectSport', po.selectOrgSport); + $frm.org.on('dblclick', 'input.OrganisationRegionCaptionCountry', po.selectOrgRegionCountry).on('click', 'button.SelectRegionCountry', po.selectOrgRegionCountry); }); //-------------------------------------------------------------- diff --git a/SaxoniteStandardBase/Base/App/Sax-Version.cs b/SaxoniteStandardBase/Base/App/Sax-Version.cs index cb07fcd..26c097e 100644 --- a/SaxoniteStandardBase/Base/App/Sax-Version.cs +++ b/SaxoniteStandardBase/Base/App/Sax-Version.cs @@ -18,7 +18,7 @@ namespace Saxonite.Net.Standard.Base.App //------------------------------------------------------------------- public static class Version { - private static String version { get; } = "1.2.0.0"; + private static String version { get; } = "1.2.1.1"; // Retrieve version. public static String GetFullVersion () { return version; } public static String GetAppVersion () @@ -40,6 +40,8 @@ namespace Saxonite.Net.Standard.Base.App //------------------------------------------------------------------- // Version history. //------------------------------------------------------------------- + // 1.2.1 20-Nov-2021 Online Profile. + // - Online Organisation edit. // 1.2.0 1-Nov-2021 'Admin' Organisation role // - 'Admin' Organisation role // - Azure App Service configuration. diff --git a/SaxoniteStandardBase/Base/App/Sax.cs b/SaxoniteStandardBase/Base/App/Sax.cs index d9f4138..2199350 100644 --- a/SaxoniteStandardBase/Base/App/Sax.cs +++ b/SaxoniteStandardBase/Base/App/Sax.cs @@ -30,6 +30,7 @@ namespace Saxonite.Net.Standard.Base.App OrganisationCategory, OrganisationRole, AddressType, + EventType, OpportunityType, ActivityReaction, }; @@ -250,6 +251,17 @@ namespace Saxonite.Net.Standard.Base.App Delivery = 60, } + //------------------------------------------------------------------- + /// Event Type + public enum EventType + { + Unknown = 0, + /* Do not change the values or codes - tied to database. */ + Playing, + Training, + Social, + } + //------------------------------------------------------------------- /// Opportunity Type public enum OpportunityType diff --git a/SaxoniteStandardBase/Base/App/SaxDbDfn_Core.cs b/SaxoniteStandardBase/Base/App/SaxDbDfn_Core.cs index 49ff79b..246be11 100644 --- a/SaxoniteStandardBase/Base/App/SaxDbDfn_Core.cs +++ b/SaxoniteStandardBase/Base/App/SaxDbDfn_Core.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Base.App { @@ -23,6 +23,7 @@ namespace Saxonite.Base.App ItemImage, ItemSport, Organisation, + OrganisationEvent, OrganisationOpportunity, Region, Sport, @@ -158,6 +159,25 @@ namespace Saxonite.Base.App Organisation_UpdateOn, Organisation_UpdateBy, Organisation_UpdateHost, + OrganisationEvent_Id, + OrganisationEvent_OrganisationId, + OrganisationEvent_SportIdPrimary, + OrganisationEvent_RegionIdCountry, + OrganisationEvent_EventAt, + OrganisationEvent_EventTypeCode, + OrganisationEvent_About, + OrganisationEvent_EventData, + OrganisationEvent_PublishedAt, + OrganisationEvent_ExpiresAt, + OrganisationEvent_Notes, + OrganisationEvent_Flags, + OrganisationEvent_Status, + OrganisationEvent_CreateOn, + OrganisationEvent_CreateBy, + OrganisationEvent_CreateHost, + OrganisationEvent_UpdateOn, + OrganisationEvent_UpdateBy, + OrganisationEvent_UpdateHost, OrganisationOpportunity_Id, OrganisationOpportunity_OrganisationId, OrganisationOpportunity_SportIdPrimary, @@ -335,8 +355,8 @@ namespace Saxonite.Base.App //------------------------------------------------------------------- // Data members. - private static readonly int tableCount = 16; - private static readonly int columnCount = 291; + private static readonly int tableCount = 17; + private static readonly int columnCount = 310; private static ulong maxTextLen = 0; //------------------------------------------------------------------- @@ -488,6 +508,7 @@ namespace Saxonite.Base.App "ItemImage", "ItemSport", "Organisation", + "OrganisationEvent", "OrganisationOpportunity", "Region", "Sport", @@ -645,11 +666,11 @@ namespace Saxonite.Base.App new ColumnDfn(7,"Id",4,4,true,10), new ColumnDfn(7,"OrganisationId",4,4,false,10), new ColumnDfn(7,"SportIdPrimary",4,4,false,10), - new ColumnDfn(7,"RegionIdPrimary",4,4,false,10), - new ColumnDfn(7,"OpportunityTypeCode",0,12,false,3), - new ColumnDfn(7,"Position",0,-9,false,200), - new ColumnDfn(7,"Outline",0,-9,false,2000), - new ColumnDfn(7,"OpportunityData",0,-9,false,0), + new ColumnDfn(7,"RegionIdCountry",4,4,false,10), + new ColumnDfn(7,"EventAt",9,93,false,16), + new ColumnDfn(7,"EventTypeCode",0,12,false,3), + new ColumnDfn(7,"About",0,-9,false,2000), + new ColumnDfn(7,"EventData",0,-9,false,0), new ColumnDfn(7,"PublishedAt",9,93,false,16), new ColumnDfn(7,"ExpiresAt",9,93,false,16), new ColumnDfn(7,"Notes",0,-9,false,2000), @@ -662,12 +683,15 @@ namespace Saxonite.Base.App new ColumnDfn(7,"UpdateBy",4,4,false,10), new ColumnDfn(7,"UpdateHost",0,12,false,100), new ColumnDfn(8,"Id",4,4,true,10), - new ColumnDfn(8,"RegionType",3,5,false,5), - new ColumnDfn(8,"CountryIso2Code",0,12,false,2), - new ColumnDfn(8,"Name",0,-9,false,100), - new ColumnDfn(8,"Latitude",8,3,false,9), - new ColumnDfn(8,"Longitude",8,3,false,9), - new ColumnDfn(8,"RegionIdParent",4,4,false,10), + new ColumnDfn(8,"OrganisationId",4,4,false,10), + new ColumnDfn(8,"SportIdPrimary",4,4,false,10), + new ColumnDfn(8,"RegionIdPrimary",4,4,false,10), + new ColumnDfn(8,"OpportunityTypeCode",0,12,false,3), + new ColumnDfn(8,"Position",0,-9,false,200), + new ColumnDfn(8,"Outline",0,-9,false,2000), + new ColumnDfn(8,"OpportunityData",0,-9,false,0), + new ColumnDfn(8,"PublishedAt",9,93,false,16), + new ColumnDfn(8,"ExpiresAt",9,93,false,16), new ColumnDfn(8,"Notes",0,-9,false,2000), new ColumnDfn(8,"Flags",3,5,false,5), new ColumnDfn(8,"Status",0,12,false,3), @@ -678,8 +702,12 @@ namespace Saxonite.Base.App new ColumnDfn(8,"UpdateBy",4,4,false,10), new ColumnDfn(8,"UpdateHost",0,12,false,100), new ColumnDfn(9,"Id",4,4,true,10), + new ColumnDfn(9,"RegionType",3,5,false,5), + new ColumnDfn(9,"CountryIso2Code",0,12,false,2), new ColumnDfn(9,"Name",0,-9,false,100), - new ColumnDfn(9,"SpecialityLabel",3,5,false,5), + new ColumnDfn(9,"Latitude",8,3,false,9), + new ColumnDfn(9,"Longitude",8,3,false,9), + new ColumnDfn(9,"RegionIdParent",4,4,false,10), new ColumnDfn(9,"Notes",0,-9,false,2000), new ColumnDfn(9,"Flags",3,5,false,5), new ColumnDfn(9,"Status",0,12,false,3), @@ -690,28 +718,8 @@ namespace Saxonite.Base.App new ColumnDfn(9,"UpdateBy",4,4,false,10), new ColumnDfn(9,"UpdateHost",0,12,false,100), new ColumnDfn(10,"Id",4,4,true,10), - new ColumnDfn(10,"EmailAddress",0,-9,false,200), - new ColumnDfn(10,"Title",0,-9,false,20), - new ColumnDfn(10,"FirstName",0,-9,false,100), - new ColumnDfn(10,"Initials",0,-9,false,10), - new ColumnDfn(10,"LastName",0,-9,false,100), - new ColumnDfn(10,"About",0,-9,false,2000), - new ColumnDfn(10,"PhoneMain",0,-9,false,50), - new ColumnDfn(10,"PhoneMobile",0,-9,false,50), - new ColumnDfn(10,"PhoneAlt",0,-9,false,50), - new ColumnDfn(10,"Gender",2,-6,false,3), - new ColumnDfn(10,"DateOfBirthDay",2,-6,false,3), - new ColumnDfn(10,"DateOfBirthMonth",2,-6,false,3), - new ColumnDfn(10,"DateOfBirthYear",3,5,false,5), - new ColumnDfn(10,"RegionIdCountry",4,4,false,10), - new ColumnDfn(10,"RegionIdProvince",4,4,false,10), - new ColumnDfn(10,"PasswordToken",0,12,false,32), - new ColumnDfn(10,"PasswordHashed",0,-9,false,100), - new ColumnDfn(10,"PasswordHistory",0,-9,false,0), - new ColumnDfn(10,"PasswordChangedAt",9,93,false,16), - new ColumnDfn(10,"LastLoginAt",9,93,false,16), - new ColumnDfn(10,"LastInvalidLoginAt",9,93,false,16), - new ColumnDfn(10,"InvalidLoginCount",3,5,false,5), + new ColumnDfn(10,"Name",0,-9,false,100), + new ColumnDfn(10,"SpecialityLabel",3,5,false,5), new ColumnDfn(10,"Notes",0,-9,false,2000), new ColumnDfn(10,"Flags",3,5,false,5), new ColumnDfn(10,"Status",0,12,false,3), @@ -721,19 +729,29 @@ namespace Saxonite.Base.App new ColumnDfn(10,"UpdateOn",9,93,false,23), new ColumnDfn(10,"UpdateBy",4,4,false,10), new ColumnDfn(10,"UpdateHost",0,12,false,100), - new ColumnDfn(11,"Id",5,-5,true,19), - new ColumnDfn(11,"UserAccountId",4,4,false,10), - new ColumnDfn(11,"ItemType",3,5,false,5), - new ColumnDfn(11,"ItemId",5,-5,false,19), - new ColumnDfn(11,"CurrentlyListed",1,-7,false,1), - new ColumnDfn(11,"ListedAtFirst",9,93,false,16), - new ColumnDfn(11,"ListedAtLast",9,93,false,16), - new ColumnDfn(11,"ViewedAtFirst",9,93,false,16), - new ColumnDfn(11,"ViewedAtLast",9,93,false,16), - new ColumnDfn(11,"Reaction",3,5,false,5), - new ColumnDfn(11,"ReactedAtFirst",9,93,false,16), - new ColumnDfn(11,"ReactedAtLast",9,93,false,16), - new ColumnDfn(11,"UserActivityData",0,-9,false,0), + new ColumnDfn(11,"Id",4,4,true,10), + new ColumnDfn(11,"EmailAddress",0,-9,false,200), + new ColumnDfn(11,"Title",0,-9,false,20), + new ColumnDfn(11,"FirstName",0,-9,false,100), + new ColumnDfn(11,"Initials",0,-9,false,10), + new ColumnDfn(11,"LastName",0,-9,false,100), + new ColumnDfn(11,"About",0,-9,false,2000), + new ColumnDfn(11,"PhoneMain",0,-9,false,50), + new ColumnDfn(11,"PhoneMobile",0,-9,false,50), + new ColumnDfn(11,"PhoneAlt",0,-9,false,50), + new ColumnDfn(11,"Gender",2,-6,false,3), + new ColumnDfn(11,"DateOfBirthDay",2,-6,false,3), + new ColumnDfn(11,"DateOfBirthMonth",2,-6,false,3), + new ColumnDfn(11,"DateOfBirthYear",3,5,false,5), + new ColumnDfn(11,"RegionIdCountry",4,4,false,10), + new ColumnDfn(11,"RegionIdProvince",4,4,false,10), + new ColumnDfn(11,"PasswordToken",0,12,false,32), + new ColumnDfn(11,"PasswordHashed",0,-9,false,100), + new ColumnDfn(11,"PasswordHistory",0,-9,false,0), + new ColumnDfn(11,"PasswordChangedAt",9,93,false,16), + new ColumnDfn(11,"LastLoginAt",9,93,false,16), + new ColumnDfn(11,"LastInvalidLoginAt",9,93,false,16), + new ColumnDfn(11,"InvalidLoginCount",3,5,false,5), new ColumnDfn(11,"Notes",0,-9,false,2000), new ColumnDfn(11,"Flags",3,5,false,5), new ColumnDfn(11,"Status",0,12,false,3), @@ -745,10 +763,17 @@ namespace Saxonite.Base.App new ColumnDfn(11,"UpdateHost",0,12,false,100), new ColumnDfn(12,"Id",5,-5,true,19), new ColumnDfn(12,"UserAccountId",4,4,false,10), - new ColumnDfn(12,"OrganisationId",4,4,false,10), - new ColumnDfn(12,"OrganisationRoleCodes",0,12,false,256), - new ColumnDfn(12,"OrganisationRoleCount",2,-6,false,3), - new ColumnDfn(12,"AdminComment",0,-9,false,2000), + new ColumnDfn(12,"ItemType",3,5,false,5), + new ColumnDfn(12,"ItemId",5,-5,false,19), + new ColumnDfn(12,"CurrentlyListed",1,-7,false,1), + new ColumnDfn(12,"ListedAtFirst",9,93,false,16), + new ColumnDfn(12,"ListedAtLast",9,93,false,16), + new ColumnDfn(12,"ViewedAtFirst",9,93,false,16), + new ColumnDfn(12,"ViewedAtLast",9,93,false,16), + new ColumnDfn(12,"Reaction",3,5,false,5), + new ColumnDfn(12,"ReactedAtFirst",9,93,false,16), + new ColumnDfn(12,"ReactedAtLast",9,93,false,16), + new ColumnDfn(12,"UserActivityData",0,-9,false,0), new ColumnDfn(12,"Notes",0,-9,false,2000), new ColumnDfn(12,"Flags",3,5,false,5), new ColumnDfn(12,"Status",0,12,false,3), @@ -760,7 +785,10 @@ namespace Saxonite.Base.App new ColumnDfn(12,"UpdateHost",0,12,false,100), new ColumnDfn(13,"Id",5,-5,true,19), new ColumnDfn(13,"UserAccountId",4,4,false,10), - new ColumnDfn(13,"UserRoleCode",0,12,false,16), + new ColumnDfn(13,"OrganisationId",4,4,false,10), + new ColumnDfn(13,"OrganisationRoleCodes",0,12,false,256), + new ColumnDfn(13,"OrganisationRoleCount",2,-6,false,3), + new ColumnDfn(13,"AdminComment",0,-9,false,2000), new ColumnDfn(13,"Notes",0,-9,false,2000), new ColumnDfn(13,"Flags",3,5,false,5), new ColumnDfn(13,"Status",0,12,false,3), @@ -770,42 +798,31 @@ namespace Saxonite.Base.App new ColumnDfn(13,"UpdateOn",9,93,false,23), new ColumnDfn(13,"UpdateBy",4,4,false,10), new ColumnDfn(13,"UpdateHost",0,12,false,100), + new ColumnDfn(14,"Id",5,-5,true,19), new ColumnDfn(14,"UserAccountId",4,4,false,10), - new ColumnDfn(14,"ActivityIndexIds",0,-9,false,0), - new ColumnDfn(14,"UserSessionData",0,-9,false,0), + new ColumnDfn(14,"UserRoleCode",0,12,false,16), + new ColumnDfn(14,"Notes",0,-9,false,2000), new ColumnDfn(14,"Flags",3,5,false,5), + new ColumnDfn(14,"Status",0,12,false,3), new ColumnDfn(14,"CreateOn",9,93,false,23), + new ColumnDfn(14,"CreateBy",4,4,false,10), + new ColumnDfn(14,"CreateHost",0,12,false,100), new ColumnDfn(14,"UpdateOn",9,93,false,23), - new ColumnDfn(15,"Id",5,-5,true,19), + new ColumnDfn(14,"UpdateBy",4,4,false,10), + new ColumnDfn(14,"UpdateHost",0,12,false,100), new ColumnDfn(15,"UserAccountId",4,4,false,10), - new ColumnDfn(15,"SportId",4,4,false,10), - new ColumnDfn(15,"About",0,-9,false,2000), - new ColumnDfn(15,"Participation",3,5,false,5), - new ColumnDfn(15,"Officiating",3,5,false,5), - new ColumnDfn(15,"UserSportData",0,-9,false,0), - new ColumnDfn(15,"Notes",0,-9,false,2000), + new ColumnDfn(15,"ActivityIndexIds",0,-9,false,0), + new ColumnDfn(15,"UserSessionData",0,-9,false,0), new ColumnDfn(15,"Flags",3,5,false,5), - new ColumnDfn(15,"Status",0,12,false,3), new ColumnDfn(15,"CreateOn",9,93,false,23), - new ColumnDfn(15,"CreateBy",4,4,false,10), - new ColumnDfn(15,"CreateHost",0,12,false,100), new ColumnDfn(15,"UpdateOn",9,93,false,23), - new ColumnDfn(15,"UpdateBy",4,4,false,10), - new ColumnDfn(15,"UpdateHost",0,12,false,100), new ColumnDfn(16,"Id",5,-5,true,19), - new ColumnDfn(16,"UserSportId",5,-5,false,19), - new ColumnDfn(16,"PeriodFrom",9,93,false,16), - new ColumnDfn(16,"PeriodTo",9,93,false,16), - new ColumnDfn(16,"OrganisationId",4,4,false,10), - new ColumnDfn(16,"OrganisationName",0,-9,false,200), - new ColumnDfn(16,"Summary",0,-9,false,2000), - new ColumnDfn(16,"Team",0,-9,false,64), - new ColumnDfn(16,"League",0,-9,false,64), - new ColumnDfn(16,"Speciality",0,-9,false,64), - new ColumnDfn(16,"SpecialitiesOther",0,-9,false,1000), - new ColumnDfn(16,"RegionIdNation",4,4,false,10), - new ColumnDfn(16,"RegionIdProvince",4,4,false,10), - new ColumnDfn(16,"UserSportExperienceData",0,-9,false,0), + new ColumnDfn(16,"UserAccountId",4,4,false,10), + new ColumnDfn(16,"SportId",4,4,false,10), + new ColumnDfn(16,"About",0,-9,false,2000), + new ColumnDfn(16,"Participation",3,5,false,5), + new ColumnDfn(16,"Officiating",3,5,false,5), + new ColumnDfn(16,"UserSportData",0,-9,false,0), new ColumnDfn(16,"Notes",0,-9,false,2000), new ColumnDfn(16,"Flags",3,5,false,5), new ColumnDfn(16,"Status",0,12,false,3), @@ -815,6 +832,29 @@ namespace Saxonite.Base.App new ColumnDfn(16,"UpdateOn",9,93,false,23), new ColumnDfn(16,"UpdateBy",4,4,false,10), new ColumnDfn(16,"UpdateHost",0,12,false,100), + new ColumnDfn(17,"Id",5,-5,true,19), + new ColumnDfn(17,"UserSportId",5,-5,false,19), + new ColumnDfn(17,"PeriodFrom",9,93,false,16), + new ColumnDfn(17,"PeriodTo",9,93,false,16), + new ColumnDfn(17,"OrganisationId",4,4,false,10), + new ColumnDfn(17,"OrganisationName",0,-9,false,200), + new ColumnDfn(17,"Summary",0,-9,false,2000), + new ColumnDfn(17,"Team",0,-9,false,64), + new ColumnDfn(17,"League",0,-9,false,64), + new ColumnDfn(17,"Speciality",0,-9,false,64), + new ColumnDfn(17,"SpecialitiesOther",0,-9,false,1000), + new ColumnDfn(17,"RegionIdNation",4,4,false,10), + new ColumnDfn(17,"RegionIdProvince",4,4,false,10), + new ColumnDfn(17,"UserSportExperienceData",0,-9,false,0), + new ColumnDfn(17,"Notes",0,-9,false,2000), + new ColumnDfn(17,"Flags",3,5,false,5), + new ColumnDfn(17,"Status",0,12,false,3), + new ColumnDfn(17,"CreateOn",9,93,false,23), + new ColumnDfn(17,"CreateBy",4,4,false,10), + new ColumnDfn(17,"CreateHost",0,12,false,100), + new ColumnDfn(17,"UpdateOn",9,93,false,23), + new ColumnDfn(17,"UpdateBy",4,4,false,10), + new ColumnDfn(17,"UpdateHost",0,12,false,100), }; //------------------------------------------------------------------- diff --git a/SaxoniteStandardBase/Base/App/SaxInternals.cs b/SaxoniteStandardBase/Base/App/SaxInternals.cs index 8b9bd17..edc9db9 100644 --- a/SaxoniteStandardBase/Base/App/SaxInternals.cs +++ b/SaxoniteStandardBase/Base/App/SaxInternals.cs @@ -99,6 +99,7 @@ namespace Saxonite.Net.Standard.Base.App public List OrganisationCategoryCodes { get { return GetCodesOfType(Sax.CodeType.OrganisationCategory); } } public List OrganisationRoleCodes { get { return GetCodesOfType(Sax.CodeType.OrganisationRole); } } public List AddressTypeCodes { get { return GetCodesOfType(Sax.CodeType.AddressType); } } + public List EventTypeCodes { get { return GetCodesOfType(Sax.CodeType.EventType); } } public List OpportunityTypeCodes { get { return GetCodesOfType(Sax.CodeType.OpportunityType); } } public List ActivityReactionCodes { get { return GetCodesOfType(Sax.CodeType.ActivityReaction); } } public List GetCodesOfType(Sax.CodeType codeType) diff --git a/SaxoniteStandardBase/Base/App/SaxSystem-Statics.cs b/SaxoniteStandardBase/Base/App/SaxSystem-Statics.cs index a4b94d9..92734b8 100644 --- a/SaxoniteStandardBase/Base/App/SaxSystem-Statics.cs +++ b/SaxoniteStandardBase/Base/App/SaxSystem-Statics.cs @@ -28,6 +28,7 @@ namespace Saxonite.Net.Standard.Base.App private static readonly List organisationCategoryCodes = new List(); private static readonly List organisationRoleCodes = new List(); private static readonly List addressTypeCodes = new List(); + private static readonly List eventTypeCodes = new List(); private static readonly List opportunityTypeCodes = new List(); private static readonly List activityReactionCodes = new List(); @@ -150,6 +151,12 @@ namespace Saxonite.Net.Standard.Base.App organisationRoleCodes.Add(Sax.OrganisationRole.OpportunityAdmin, "OPA", "Opportunities"); organisationRoleCodes.Add(Sax.OrganisationRole.ArticleAdmin, "ARA", "Articles"); + //--------------------------------------------------------------- + // Event types. + eventTypeCodes.Add(Sax.EventType.Playing, "PLG", "Playing"); + eventTypeCodes.Add(Sax.EventType.Playing, "TRN", "Training"); + eventTypeCodes.Add(Sax.EventType.Playing, "SCL", "Social"); + //--------------------------------------------------------------- // Opportunity types. opportunityTypeCodes.Add(Sax.OpportunityType.Playing, "PLG", "Playing"); diff --git a/SaxoniteStandardBase/Base/App/SaxSystem.cs b/SaxoniteStandardBase/Base/App/SaxSystem.cs index 9c352f7..63fed77 100644 --- a/SaxoniteStandardBase/Base/App/SaxSystem.cs +++ b/SaxoniteStandardBase/Base/App/SaxSystem.cs @@ -64,6 +64,8 @@ namespace Saxonite.Net.Standard.Base.App return new List(organisationRoleCodes); case Sax.CodeType.AddressType: return new List(addressTypeCodes); + case Sax.CodeType.EventType: + return new List(eventTypeCodes); case Sax.CodeType.OpportunityType: return new List(opportunityTypeCodes); case Sax.CodeType.ActivityReaction: diff --git a/SaxoniteStandardBase/Base/Bus/SaxItemAddress.cs b/SaxoniteStandardBase/Base/Bus/SaxItemAddress.cs index cf36876..9d264aa 100644 --- a/SaxoniteStandardBase/Base/Bus/SaxItemAddress.cs +++ b/SaxoniteStandardBase/Base/Bus/SaxItemAddress.cs @@ -303,6 +303,8 @@ namespace Saxonite.Net.Standard.Base.Bus { return new ItemId((short)Sax.DataItemType.ItemAddress, Id); } + // Address types. + public static Sax.AddressType DefaultOrganisationAddressType { get { return Sax.AddressType.Office; } } //------------------------------------------------------------------- // Properties. diff --git a/SaxoniteStandardBase/Base/Bus/SaxOrganisationEvent.cs b/SaxoniteStandardBase/Base/Bus/SaxOrganisationEvent.cs new file mode 100644 index 0000000..88100c6 --- /dev/null +++ b/SaxoniteStandardBase/Base/Bus/SaxOrganisationEvent.cs @@ -0,0 +1,312 @@ +using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Core; +using Saxonite.Net.Standard.Base.App; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Saxonite.Net.Standard.Base.Bus +{ + //======================================================================= + // Organisation Event. + //======================================================================= + public abstract class SaxOrganisationEvent : SacsHierarchyItem + { + //------------------------------------------------------------------- + // Columns. + public enum Column + { + Pos, + Id, + // Organisation. + OrganisationId, + Organisation_Name, + // Sport. + SportIdPrimary, + Sport_Name, + // Region. + RegionIdCountry, + Region_Name, + // Event. + EventAt_Date, + EventAt_DateTime, + EventTypeCode, + EventType_Desc, + About, + PublishedAt_Date, + PublishedAt_DateTime, + ExpiresAt_Date, + ExpiresAt_DateTime, + // Associated data. + // Common. + Notes, + Flags, + Status, + Status_Desc, + Status_Ind, + CreateOn_Date, + UpdateOn_Date, + } + + //------------------------------------------------------------------- + /// Properties other than common. + public class DataProperties + { + public SysId OrganisationId { get; set; } + public SysId SportIdPrimary { get; set; } + public SysId RegionIdCountry { get; set; } + public DateTime EventAt { get; set; } + public Sax.EventType EventType { get; set; } + public String About { get; set; } = String.Empty; + public String EventData { get; set; } = String.Empty; + public DateTime PublishedAt { get; set; } + public DateTime ExpiresAt { get; set; } + } + + //------------------------------------------------------------------- + // Data. + public new class Data : SacsHierarchyItem.Data + { + // Data members. + private readonly DataProperties data = new DataProperties(); + // Construction. + public Data() + { + Status = DefaultStatus; + } + // Properties. + public SysId OrganisationId + { + get { return data.OrganisationId; } + set { CheckChanged(data.OrganisationId, value); data.OrganisationId = value; } + } + public SysId SportIdPrimary + { + get { return data.SportIdPrimary; } + set { CheckChanged(data.SportIdPrimary, value); data.SportIdPrimary = value; } + } + public SysId RegionIdCountry + { + get { return data.RegionIdCountry; } + set { CheckChanged(data.RegionIdCountry, value); data.RegionIdCountry = value; } + } + public DateTime EventAt + { + get { return data.EventAt; } + set { CheckChanged(data.EventAt, value); data.EventAt = value; } + } + public Sax.EventType EventType + { + get { return data.EventType; } + set { CheckChanged((int)data.EventType, (int)value); data.EventType = value; } + } + public String About + { + get { return data.About; } + set { CheckChanged(data.About, value); data.About = value; } + } + public String EventData + { + get { return data.EventData; } + set { CheckChanged(data.EventData, value); data.EventData = value; } + } + public DateTime PublishedAt + { + get { return data.PublishedAt; } + set { CheckChanged(data.PublishedAt, value); data.PublishedAt = value; } + } + public DateTime ExpiresAt + { + get { return data.ExpiresAt; } + set { CheckChanged(data.ExpiresAt, value); data.ExpiresAt = value; } + } + // Population. + internal void PopulateFrom(Data data) + { + OrganisationId = data.OrganisationId; + SportIdPrimary = data.SportIdPrimary; + RegionIdCountry = data.RegionIdCountry; + EventAt = data.EventAt; + EventType = data.EventType; + About = data.About; + EventData = data.EventData; + PublishedAt = data.PublishedAt; + ExpiresAt = data.ExpiresAt; + base.PopulateFrom(data); + } + public Data Clone() + { + Data data = new Data(); + data.PopulateFrom(this); + return data; + } + } + + //------------------------------------------------------------------- + // Error field - identify properties with validation error. + public new class ErrField : SacsHierarchyItem.ErrField + { + // Identifies the field that has invalid data. + public ValidValue OrganisationId { get; set; } = ValidValue.Valid; + public ValidValue SportIdPrimary { get; set; } = ValidValue.Valid; + public ValidValue RegionIdCountry { get; set; } = ValidValue.Valid; + public ValidValue EventAt { get; set; } = ValidValue.Valid; + public ValidValue EventType { get; set; } = ValidValue.Valid; + public ValidValue About { get; set; } = ValidValue.Valid; + public ValidValue EventData { get; set; } = ValidValue.Valid; + public ValidValue PublishedAt { get; set; } = ValidValue.Valid; + public ValidValue ExpiresAt { get; set; } = ValidValue.Valid; + } + + //------------------------------------------------------------------- + // Data members. + private readonly Data data = new Data(); + + //------------------------------------------------------------------- + // Construction. + protected SaxOrganisationEvent(SysId id, SysId OrganisationId) : base(id) + { + base.SetData(data); + this.OrganisationId = OrganisationId; + Status = DefaultStatus; + } + + //------------------------------------------------------------------- + // Status. + private static readonly List validStatuses = new List() + { + SaStatus.Active, + SaStatus.Inactive, + SaStatus.Deleted, + }; + public static SaStatus DefaultStatus { get { return SaStatus.Active; } } + public static List ValidStatuses { get { return new List(validStatuses); } } + public static DataValue.TriStateType GetStatusTriState(SaStatus status) + { + if (status == SaStatus.Active) return DataValue.TriStateType.Green; + if (status == SaStatus.Inactive) return DataValue.TriStateType.Red; + if (status == SaStatus.Deleted) return DataValue.TriStateType.Purple; + return DataValue.TriStateType.Unknown; + } + + //------------------------------------------------------------------- + // Utilities. + public ItemId GetItemId() + { + return new ItemId((short)Sax.DataItemType.OrganisationEvent, Id); + } + + //------------------------------------------------------------------- + // Properties. + public Data GetData() { return data.Clone(); } + public void SetData(Data data) + { + String fn = GetType().Name + ".SetData"; + // Properties that cannot be changed if previously specified. + if (SysId.IsValid(Id) && SysId.ToInt(Id) != SysId.ToInt(data.Id)) + throw new NotSupportedException(fn + " Id cannot be changed"); + if (SysId.IsValid(OrganisationId) && SysId.ToInt(OrganisationId) != SysId.ToInt(data.OrganisationId)) + throw new NotSupportedException(fn + " Organisation Id cannot be changed"); + this.data.PopulateFrom(data); + } + public SysId OrganisationId + { + get { return data.OrganisationId; } + protected set { data.OrganisationId = value; } + } + public SysId SportIdPrimary + { + get { return data.SportIdPrimary; } + set { data.SportIdPrimary = value; } + } + public SysId RegionIdCountry + { + get { return data.RegionIdCountry; } + set { data.RegionIdCountry = value; } + } + public DateTime EventAt + { + get { return data.EventAt; } + set { data.EventAt = value; } + } + public Sax.EventType EventType + { + get { return data.EventType; } + set { data.EventType = value; } + } + public String About + { + get { return data.About; } + set { data.About = value; } + } + public String EventData + { + get { return data.EventData; } + set { data.EventData = value; } + } + public DateTime PublishedAt + { + get { return data.PublishedAt; } + set { data.PublishedAt = value; } + } + public DateTime ExpiresAt + { + get { return data.ExpiresAt; } + set { data.ExpiresAt = value; } + } + + //------------------------------------------------------------------- + // Flags - positions 1-16 available. + + //------------------------------------------------------------------- + // A s s o c i a t e d D a t a + //------------------------------------------------------------------- + + //------------------------------------------------------------------- + // P a r a m s + //------------------------------------------------------------------- + // List parameters. + public enum StatusCat + { + Any, + ActiveOnly, + InactiveOnly, + NotDeleted, + DeletedOnly, + } + /// + /// Item list parameters. + /// + public new class Params : SacsHierarchyItem.Params + { + // List filtering. + public List IdsIncluded { get; } = new List(); + public List IdsExcluded { get; } = new List(); + /// Restrict to User Account via User Organisations and Organisations. + public List UserAccountIdsIncluded { get; } = new List(); + public List OrganisationIdsIncluded { get; } = new List(); + public List SportIdsIncluded { get; set; } = new List(); + public List RegionIdsIncluded { get; } = new List(); + public DateTime EventFrom { get; set; } + public DateTime EventTo{ get; set; } + public String AboutPartial { get; set; } + /// General filter value - position, outline, sport, body etc. + public String EventFilter { get; set; } + public String NotesPartial { get; set; } + public StatusCat StatusCat { get; set; } = StatusCat.ActiveOnly; + // Table aliases - blank if not linked. + public String Alias_Organisation { get; set; } + public String Alias_UserOrganisation { get; set; } + public String Alias_UserAccount { get; set; } + } + + //------------------------------------------------------------------- + } + //======================================================================= + // Item list extension methods. + public static class SaxOrganisationEventList + { + } + + //======================================================================= +} diff --git a/SaxoniteStandardBase/Base/Bus/SaxUserOrganisation.cs b/SaxoniteStandardBase/Base/Bus/SaxUserOrganisation.cs index a1ef2b9..68e4a57 100644 --- a/SaxoniteStandardBase/Base/Bus/SaxUserOrganisation.cs +++ b/SaxoniteStandardBase/Base/Bus/SaxUserOrganisation.cs @@ -36,6 +36,8 @@ namespace Saxonite.Net.Standard.Base.Bus User_Status_Desc, // Organisation. Organisation_Name, + Organisation_Category, + Organisation_Type, Organisation_RegionId, Organisation_Region_Name, Organisation_SportId, diff --git a/SaxoniteStandardBase/Base/Mgr/SaxActivityMgr-OrganisationEvent.cs b/SaxoniteStandardBase/Base/Mgr/SaxActivityMgr-OrganisationEvent.cs new file mode 100644 index 0000000..f22a7c8 --- /dev/null +++ b/SaxoniteStandardBase/Base/Mgr/SaxActivityMgr-OrganisationEvent.cs @@ -0,0 +1,246 @@ +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.Base.App; +using Saxonite.Net.Standard.Base.Bus; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Saxonite.Net.Standard.Base.Mgr +{ + //======================================================================= + partial class SaxActivityMgr + { + //******************************************************************* + // Activity Mgr - Organisation Event + //******************************************************************* + // Utilities. + + //------------------------------------------------------------------- + // Create item. + public abstract SaxOrganisationEvent CreateOrganisationEvent(SysId organisationId); + + //------------------------------------------------------------------- + // Item exists. + public bool OrganisationEventExistsById(SysId id) + { + ClearErrorState(); + if (!SysId.IsValid(id)) return false; + SaxOrganisationEvent.Params prmOrganisationEvent = new SaxOrganisationEvent.Params(); + prmOrganisationEvent.IdsIncluded.Add(id); + prmOrganisationEvent.StatusCat = SaxOrganisationEvent.StatusCat.Any; + return GetOrganisationEventCount(prmOrganisationEvent) == 1; + } + + //------------------------------------------------------------------- + // Retrieve individual items. + public abstract SaxOrganisationEvent GetOrganisationEvent(SaxOrganisationEvent.Params prmOrganisationEvent); + public SaxOrganisationEvent GetOrganisationEventById(SysId id) + { + ClearErrorState(); + if (!SysId.IsValid(id)) return null; + SaxOrganisationEvent.Params prmOrganisationEvent = new SaxOrganisationEvent.Params(); + prmOrganisationEvent.IdsIncluded.Add(id); + prmOrganisationEvent.StatusCat = SaxOrganisationEvent.StatusCat.Any; + return GetOrganisationEvent(prmOrganisationEvent); + } + + //------------------------------------------------------------------- + // Validate item data. + public bool IsValidOrganisationEvent(SaxOrganisationEvent organisationEvent) + { + ClearErrorState(); + if (organisationEvent == null) return SetErrorState(ErrorMessage.ItemNotSpecified); + return IsValidOrganisationEventData(organisationEvent.GetData(), new SaxOrganisationEvent.ErrField()); + } + public virtual bool IsValidOrganisationEventData(SaxOrganisationEvent.Data data, SaxOrganisationEvent.ErrField errField) + { + ClearErrorState(); + + // Organisation. + if (errField.OrganisationId != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.OrganisationId)) + { + errField.OrganisationId = SacsHierarchyItem.ValidValue.Invalid; + return SetErrorState("Organisation must be specified"); + } + // Primary Sport. + if (errField.SportIdPrimary != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.SportIdPrimary)) + { + errField.SportIdPrimary = SacsHierarchyItem.ValidValue.Invalid; + return SetErrorState("Sport must be specified"); + } + // Country Region. + if (errField.RegionIdCountry != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.RegionIdCountry)) + { + errField.RegionIdCountry = SacsHierarchyItem.ValidValue.Invalid; + return SetErrorState("Country Region must be specified"); + } + + // Event date and time. + if (errField.EventAt != SacsHierarchyItem.ValidValue.Ignore && !DateUtil.IsValid(data.EventAt)) + { + errField.EventType = SacsHierarchyItem.ValidValue.Invalid; + return SetErrorState("Event data and time must be specified."); + } + // Event type. + if (errField.EventType != SacsHierarchyItem.ValidValue.Ignore && data.EventType <= 0) + { + errField.EventType = SacsHierarchyItem.ValidValue.Invalid; + return SetErrorState("Event type must be specified."); + } + // About. + if (errField.About != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.About, "outline", (long)SaxDbDfn_Core.GetColTextLen(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_About), true)) + { + errField.About = SacsHierarchyItem.ValidValue.Invalid; + return false; + } + + // Common properties. + if (errField.Notes != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Notes, "notes", (long)SaxDbDfn_Core.GetColTextLen(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Notes))) + { + errField.Notes = SacsHierarchyItem.ValidValue.Invalid; + return false; + } + if (errField.Status != SacsHierarchyItem.ValidValue.Ignore) + { + if (!IsValidValue(data.StatusCode, "status", (long)SaxDbDfn_Core.GetColTextLen(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Status), true, true)) + { + errField.Status = SacsHierarchyItem.ValidValue.Invalid; + return false; + } + if (!SaxOrganisationEvent.ValidStatuses.Contains(data.Status)) + { + errField.Status = SacsHierarchyItem.ValidValue.Invalid; + return SetErrorState(ErrorMessage.InvalidStatus); + } + } + + //--------------------------------------------------------------- + // Associated data - ignore for deleted items. + if (!data.IsStatusDeleted) + { + + // Organisation. + if (errField.OrganisationId != SacsHierarchyItem.ValidValue.Ignore && SysId.IsValid(data.OrganisationId)) + { + SaxOrganisation.Params prmOrganisation = new SaxOrganisation.Params(); + prmOrganisation.IdsIncluded.Add(data.OrganisationId); + prmOrganisation.StatusCat = SaxOrganisation.StatusCat.NotDeleted; + if (AccountMgr.GetOrganisationCount(prmOrganisation) < 1) + { + errField.OrganisationId = SacsHierarchyItem.ValidValue.Invalid; + return SetErrorState("Invalid organisation specified"); + } + } + + // Primary Sport. + if (errField.SportIdPrimary != SacsHierarchyItem.ValidValue.Ignore && SysId.IsValid(data.SportIdPrimary)) + { + SaxSport.Params prmSport = new SaxSport.Params(); + prmSport.IdsIncluded.Add(data.SportIdPrimary); + prmSport.StatusCat = SaxSport.StatusCat.NotDeleted; + if (ReferenceMgr.GetSportCount(prmSport) < 1) + { + errField.SportIdPrimary = SacsHierarchyItem.ValidValue.Invalid; + return SetErrorState("Invalid sport specified"); + } + } + + // Country Region. + if (errField.RegionIdCountry != SacsHierarchyItem.ValidValue.Ignore && SysId.IsValid(data.RegionIdCountry)) + { + SaxRegion.Params prmRegion = new SaxRegion.Params(); + prmRegion.IdsIncluded.Add(data.RegionIdCountry); + prmRegion.StatusCat = SaxRegion.StatusCat.NotDeleted; + if (ReferenceMgr.GetRegionCount(prmRegion) < 1) + { + errField.RegionIdCountry = SacsHierarchyItem.ValidValue.Invalid; + return SetErrorState("Invalid region specified"); + } + } + } + + //--------------------------------------------------------------- + return true; + } + + //------------------------------------------------------------------- + // OrganisationEvent database interface. + public abstract bool InsertOrganisationEvent(SaxOrganisationEvent organisationEvent, DbUpdateInfo dbUpdateInfo); + public abstract bool UpdateOrganisationEvent(SaxOrganisationEvent organisationEvent, DbUpdateInfo dbUpdateInfo); + public virtual bool OrganisationEventCanBeDeleted(SaxOrganisationEvent organisationEvent) + { + ClearErrorState(); + return true; + } + public abstract bool DeleteOrganisationEvent(SaxOrganisationEvent organisationEvent, DbUpdateInfo dbUpdateInfo); + + //------------------------------------------------------------------- + // OrganisationEvent list: + public abstract ColumnDfn GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column columnId, String caption = "", int width = 0); + public abstract List GetOrganisationEventQueryFilter(SaxOrganisationEvent.Params prmOrganisationEvent); + public abstract long GetOrganisationEventCount(SaxOrganisationEvent.Params prmOrganisationEvent); + public abstract List GetOrganisationEventList(SaxOrganisationEvent.Params prmOrganisationEvent); + public abstract DbResultSet ExecuteOrganisationEventQuery(List columns, SaxOrganisationEvent.Params prmOrganisationEvent); + + //------------------------------------------------------------------- + /// + /// Extract and format result set data value where specific handling is required. + /// Where response is an invalid data value, format value using column.FormatValue(values). + /// + public virtual DataValue GetOrganisationEventDataValue(ColumnDfn column, NamedValue.Map values) + { + DataValue value = new DataValue(); + switch ((SaxOrganisationEvent.Column)column.Id) + { + //----------------------------------------------------------- + // Event type desc. + case SaxOrganisationEvent.Column.EventType_Desc: + { + String code = values.GetValue(column.DataName).ToString(); + value = new DataValue(EventTypeCodes.GetDescForCode(code, code)); + } + break; + + //----------------------------------------------------------- + // Summary - limit to 200 chars. + case SaxOrganisationEvent.Column.About: + { + value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200)); + } + break; + + //----------------------------------------------------------- + // Notes - limit to 200 chars. + case SaxOrganisationEvent.Column.Notes: + { + value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200)); + } + break; + + //----------------------------------------------------------- + // Status. + case SaxOrganisationEvent.Column.Status_Desc: + case SaxOrganisationEvent.Column.Status_Ind: + { + String statusCode = values.GetValue(column.DataName).ToString(); + SaStatus status = SacsSystem.GetStatusForCode(statusCode); + if (column.Id == (int)SaxOrganisationEvent.Column.Status_Desc) + value = new DataValue(SacsSystem.GetStatusDesc(status)); + else if (column.Id == (int)SaxOrganisationEvent.Column.Status_Ind) + value = new DataValue(SaxOrganisationEvent.GetStatusTriState(status)); + } + break; + + //----------------------------------------------------------- + } + return value; + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SaxoniteStandardBase/Base/Mgr/SaxActivityMgr-OrganisationOpportunity.cs b/SaxoniteStandardBase/Base/Mgr/SaxActivityMgr-OrganisationOpportunity.cs index c52db1e..83ec0ea 100644 --- a/SaxoniteStandardBase/Base/Mgr/SaxActivityMgr-OrganisationOpportunity.cs +++ b/SaxoniteStandardBase/Base/Mgr/SaxActivityMgr-OrganisationOpportunity.cs @@ -82,7 +82,7 @@ namespace Saxonite.Net.Standard.Base.Mgr // Opportunity type. if (errField.OpportunityType != SacsHierarchyItem.ValidValue.Ignore && data.OpportunityType <= 0) { - errField.Position = SacsHierarchyItem.ValidValue.Invalid; + errField.OpportunityType = SacsHierarchyItem.ValidValue.Invalid; return SetErrorState("Opportunity type must be specified."); } // Position. diff --git a/SaxoniteStandardBase/Base/Mgr/SaxItemMgr.cs b/SaxoniteStandardBase/Base/Mgr/SaxItemMgr.cs index b0b0fc9..9c48e66 100644 --- a/SaxoniteStandardBase/Base/Mgr/SaxItemMgr.cs +++ b/SaxoniteStandardBase/Base/Mgr/SaxItemMgr.cs @@ -76,6 +76,7 @@ namespace Saxonite.Net.Standard.Base.Mgr public List OrganisationCategoryCodes { get { return Internals.OrganisationCategoryCodes; } } public List OrganisationRoleCodes { get { return Internals.OrganisationRoleCodes; } } public List AddressTypeCodes { get { return Internals.AddressTypeCodes; } } + public List EventTypeCodes { get { return Internals.EventTypeCodes; } } public List OpportunityTypeCodes { get { return Internals.OpportunityTypeCodes; } } public List ActivityReactionCodes { get { return Internals.ActivityReactionCodes; } } diff --git a/SaxoniteStandardDbas/Dbas/Bus/SaxOrganisationEvent_Dbas.cs b/SaxoniteStandardDbas/Dbas/Bus/SaxOrganisationEvent_Dbas.cs new file mode 100644 index 0000000..effa318 --- /dev/null +++ b/SaxoniteStandardDbas/Dbas/Bus/SaxOrganisationEvent_Dbas.cs @@ -0,0 +1,32 @@ +using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Dbas; +using Saxonite.Net.Standard.Base.Bus; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Saxonite.Net.Standard.Dbas.Bus +{ + //======================================================================= + public class SaxOrganisationEvent_Dbas : SaxOrganisationEvent + { + //------------------------------------------------------------------- + // Data members. + private ISacsDatabase database; + + //------------------------------------------------------------------- + // Construction. + public SaxOrganisationEvent_Dbas(ISacsDatabase database, SysId id, SysId organisationId, UInt16 flags) : + base(id, organisationId) + { + this.database = database; + Flags = flags; + } + + //------------------------------------------------------------------- + // Associated data. + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SaxoniteStandardDbas/Dbas/Internal/ActivityIndex_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/ActivityIndex_Db.cs index 2a52c1c..0b26bf9 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/ActivityIndex_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/ActivityIndex_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/Article_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/Article_Db.cs index 4b2de40..62106a1 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/Article_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/Article_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/ItemAddress_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/ItemAddress_Db.cs index 5915d00..bc670f6 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/ItemAddress_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/ItemAddress_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/ItemImage_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/ItemImage_Db.cs index 8bd076a..32e08e7 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/ItemImage_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/ItemImage_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/ItemSport_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/ItemSport_Db.cs index 75ec682..28e3d0a 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/ItemSport_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/ItemSport_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/OrganisationEvent_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/OrganisationEvent_Db.cs new file mode 100644 index 0000000..ddda804 --- /dev/null +++ b/SaxoniteStandardDbas/Dbas/Internal/OrganisationEvent_Db.cs @@ -0,0 +1,254 @@ +using Microsoft.Data.SqlClient; +using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Dbas; +using Sarand.Net.Standard.Base.Utils; +using Saxonite.Net.Standard.Dbas.Data; +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Linq; + +//--------------------------------------------------------------------------- +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 +//--------------------------------------------------------------------------- +namespace Saxonite.Net.Standard.Dbas.Internal +{ + internal class OrganisationEvent_Db : SaxDbDataItem + { + //------------------------------------------------------------------- + // Column definitions. + public class ColumnsData + { + public ColumnDataInt32 _Id { get; } = new ColumnDataInt32("Id", true); + public ColumnDataInt32 _OrganisationId { get; } = new ColumnDataInt32("OrganisationId"); + public ColumnDataInt32 _SportIdPrimary { get; } = new ColumnDataInt32("SportIdPrimary"); + public ColumnDataInt32 _RegionIdCountry { get; } = new ColumnDataInt32("RegionIdCountry"); + public ColumnDataDateTime _EventAt { get; } = new ColumnDataDateTime("EventAt"); + public ColumnDataString _EventTypeCode { get; } = new ColumnDataString("EventTypeCode"); + public ColumnDataString _About { get; } = new ColumnDataString("About"); + public ColumnDataString _EventData { get; } = new ColumnDataString("EventData"); + public ColumnDataDateTime _PublishedAt { get; } = new ColumnDataDateTime("PublishedAt"); + public ColumnDataDateTime _ExpiresAt { get; } = new ColumnDataDateTime("ExpiresAt"); + public ColumnDataString _Notes { get; } = new ColumnDataString("Notes"); + public ColumnDataInt16 _Flags { get; } = new ColumnDataInt16("Flags"); + public ColumnDataString _Status { get; } = new ColumnDataString("Status"); + public ColumnDataDateTime _CreateOn { get; } = new ColumnDataDateTime("CreateOn"); + public ColumnDataInt32 _CreateBy { get; } = new ColumnDataInt32("CreateBy"); + public ColumnDataString _CreateHost { get; } = new ColumnDataString("CreateHost"); + public ColumnDataDateTime _UpdateOn { get; } = new ColumnDataDateTime("UpdateOn"); + public ColumnDataInt32 _UpdateBy { get; } = new ColumnDataInt32("UpdateBy"); + public ColumnDataString _UpdateHost { get; } = new ColumnDataString("UpdateHost"); + } + + //------------------------------------------------------------------- + // Data members. + protected static List fields { get; } = new List() + { + "Id", + "OrganisationId", + "SportIdPrimary", + "RegionIdCountry", + "EventAt", + "EventTypeCode", + "About", + "EventData", + "PublishedAt", + "ExpiresAt", + "Notes", + "Flags", + "Status", + "CreateOn", + "CreateBy", + "CreateHost", + "UpdateOn", + "UpdateBy", + "UpdateHost", + }; + protected static List fieldsId { get; } = new List() + { + "Id", + }; + protected static List fieldsPrimary { get; } = new List() + { + "Id", + }; + protected static List fieldsIgnoreOnUpdate { get; } = new List() + { + "CreateOn", + "CreateBy", + "CreateHost", + }; + + //------------------------------------------------------------------- + // Construction. + internal OrganisationEvent_Db (IDatabaseInfo dbInfo) : base(dbInfo) + { + } + + //------------------------------------------------------------------- + // Properties. + public override String SchemaName { get; } = "dbo"; + public override String TableName { get; } = "OrganisationEvent"; + public String TableNameFmt { get { return (!String.IsNullOrEmpty(SchemaName) ? "[" + SchemaName + "]." : "") + "[" + TableName + "]"; } } + public static List Fields { get { return new List(fields); } } + public static List FieldsId { get { return new List(fieldsId); } } + public static List FieldsNonId { get { return fields.FindAll(item => !fieldsId.ContainsCI(item)); } } + // Columns. + public ColumnsData Cols { get; } = new ColumnsData(); + public Int32 _Id { get { return Cols._Id.Value; } set { Cols._Id.Value = value; } } + public Int32 _OrganisationId { get { return Cols._OrganisationId.Value; } set { Cols._OrganisationId.Value = value; } } + public Int32 _SportIdPrimary { get { return Cols._SportIdPrimary.Value; } set { Cols._SportIdPrimary.Value = value; } } + public Int32 _RegionIdCountry { get { return Cols._RegionIdCountry.Value; } set { Cols._RegionIdCountry.Value = value; } } + public DateTime _EventAt { get { return Cols._EventAt.Value; } set { Cols._EventAt.Value = value; } } + public String _EventTypeCode { get { return Cols._EventTypeCode.Value; } set { Cols._EventTypeCode.Value = value; } } + public String _About { get { return Cols._About.Value; } set { Cols._About.Value = value; } } + public String _EventData { get { return Cols._EventData.Value; } set { Cols._EventData.Value = value; } } + public DateTime _PublishedAt { get { return Cols._PublishedAt.Value; } set { Cols._PublishedAt.Value = value; } } + public DateTime _ExpiresAt { get { return Cols._ExpiresAt.Value; } set { Cols._ExpiresAt.Value = value; } } + public String _Notes { get { return Cols._Notes.Value; } set { Cols._Notes.Value = value; } } + public Int16 _Flags { get { return Cols._Flags.Value; } set { Cols._Flags.Value = value; } } + public String _Status { get { return Cols._Status.Value; } set { Cols._Status.Value = value; } } + public DateTime _CreateOn { get { return Cols._CreateOn.Value; } set { Cols._CreateOn.Value = value; } } + public Int32 _CreateBy { get { return Cols._CreateBy.Value; } set { Cols._CreateBy.Value = value; } } + public String _CreateHost { get { return Cols._CreateHost.Value; } set { Cols._CreateHost.Value = value; } } + public DateTime _UpdateOn { get { return Cols._UpdateOn.Value; } set { Cols._UpdateOn.Value = value; } } + public Int32 _UpdateBy { get { return Cols._UpdateBy.Value; } set { Cols._UpdateBy.Value = value; } } + public String _UpdateHost { get { return Cols._UpdateHost.Value; } set { Cols._UpdateHost.Value = value; } } + // Existing columns - confirmed on database if table exists. + public List ExistingColumnNames { get { return GetExistingColumnNames(Fields); } } + public List ExistingColumnNamesNonId { get { return GetExistingColumnNames(FieldsNonId); } } + + //------------------------------------------------------------------- + // Population. + public override void PopulateFrom (DbCommand dbCommand, String tableAlias, String filter) + { + dbCommand.CommandText = + "SELECT " + ExistingColumnNames.Concat(", ", (!String.IsNullOrEmpty(tableAlias) ? tableAlias + "." : "") + "[", "]") + " " + + "FROM " + TableNameFmt + (!String.IsNullOrEmpty(tableAlias) ? " " + tableAlias : "") + " " + + (!String.IsNullOrEmpty(filter) ? "WHERE " + filter : ""); + Log(GetType().Name + ".PopulateFrom", dbCommand.CommandText); + using (DbDataReader dbDataReader = dbCommand.ExecuteReader()) + { + dbDataReader.Read(); + PopulateFrom(dbDataReader); + } + } + public override void PopulateFrom (DbDataReader dbDataReader) + { + _Id = GetFieldInt32(dbDataReader, "Id", _Id); + _OrganisationId = GetFieldInt32(dbDataReader, "OrganisationId", _OrganisationId); + _SportIdPrimary = GetFieldInt32(dbDataReader, "SportIdPrimary", _SportIdPrimary); + _RegionIdCountry = GetFieldInt32(dbDataReader, "RegionIdCountry", _RegionIdCountry); + _EventAt = GetFieldDateTime(dbDataReader, "EventAt", _EventAt); + _EventTypeCode = GetFieldString(dbDataReader, "EventTypeCode", _EventTypeCode); + _About = GetFieldString(dbDataReader, "About", _About); + _EventData = GetFieldString(dbDataReader, "EventData", _EventData); + _PublishedAt = GetFieldDateTime(dbDataReader, "PublishedAt", _PublishedAt); + _ExpiresAt = GetFieldDateTime(dbDataReader, "ExpiresAt", _ExpiresAt); + _Notes = GetFieldString(dbDataReader, "Notes", _Notes); + _Flags = GetFieldInt16(dbDataReader, "Flags", _Flags); + _Status = GetFieldString(dbDataReader, "Status", _Status); + _CreateOn = GetFieldDateTime(dbDataReader, "CreateOn", _CreateOn); + _CreateBy = GetFieldInt32(dbDataReader, "CreateBy", _CreateBy); + _CreateHost = GetFieldString(dbDataReader, "CreateHost", _CreateHost); + _UpdateOn = GetFieldDateTime(dbDataReader, "UpdateOn", _UpdateOn); + _UpdateBy = GetFieldInt32(dbDataReader, "UpdateBy", _UpdateBy); + _UpdateHost = GetFieldString(dbDataReader, "UpdateHost", _UpdateHost); + } + + //------------------------------------------------------------------- + // Insert command. + public override bool ExecuteInsertCommand (DbCommand dbCommand) + { + List columnNames = ExistingColumnNamesNonId; + // Avoid insert if Identity field is already valid. + if (_Id != 0) throw new Exception("Invalid for Insert - item already has a valid Id"); + // Construct query. + String query = + "INSERT INTO " + TableNameFmt + " " + + "("+columnNames.Concat(",","[","]")+") "; + query += "Output Inserted.Id "; + if (dbCommand is SqlCommand) + query += "VALUES (" + columnNames.Concat(",", "@", "") + ") "; + else query += "VALUES (" + StringListUtil.CreateList("?", columnNames.Count).Concat(",") + ") "; + dbCommand.CommandText = query; + Log(GetType().Name + ".ExecuteInsertCommand", dbCommand.CommandText); + // Populate parameters. + dbCommand.Parameters.Clear(); + if (columnNames.ContainsCI("OrganisationId")) AddCommandParameter(dbCommand, "@OrganisationId", _OrganisationId); + if (columnNames.ContainsCI("SportIdPrimary")) AddCommandParameter(dbCommand, "@SportIdPrimary", _SportIdPrimary); + if (columnNames.ContainsCI("RegionIdCountry")) AddCommandParameter(dbCommand, "@RegionIdCountry", _RegionIdCountry); + if (columnNames.ContainsCI("EventAt")) AddCommandParameter(dbCommand, "@EventAt", _EventAt); + if (columnNames.ContainsCI("EventTypeCode")) AddCommandParameter(dbCommand, "@EventTypeCode", _EventTypeCode); + if (columnNames.ContainsCI("About")) AddCommandParameter(dbCommand, "@About", _About); + if (columnNames.ContainsCI("EventData")) AddCommandParameter(dbCommand, "@EventData", _EventData); + if (columnNames.ContainsCI("PublishedAt")) AddCommandParameter(dbCommand, "@PublishedAt", _PublishedAt); + if (columnNames.ContainsCI("ExpiresAt")) AddCommandParameter(dbCommand, "@ExpiresAt", _ExpiresAt); + if (columnNames.ContainsCI("Notes")) AddCommandParameter(dbCommand, "@Notes", _Notes); + if (columnNames.ContainsCI("Flags")) AddCommandParameter(dbCommand, "@Flags", _Flags); + if (columnNames.ContainsCI("Status")) AddCommandParameter(dbCommand, "@Status", _Status); + if (columnNames.ContainsCI("CreateOn")) AddCommandParameter(dbCommand, "@CreateOn", _CreateOn); + if (columnNames.ContainsCI("CreateBy")) AddCommandParameter(dbCommand, "@CreateBy", _CreateBy); + if (columnNames.ContainsCI("CreateHost")) AddCommandParameter(dbCommand, "@CreateHost", _CreateHost); + if (columnNames.ContainsCI("UpdateOn")) AddCommandParameter(dbCommand, "@UpdateOn", _UpdateOn); + if (columnNames.ContainsCI("UpdateBy")) AddCommandParameter(dbCommand, "@UpdateBy", _UpdateBy); + if (columnNames.ContainsCI("UpdateHost")) AddCommandParameter(dbCommand, "@UpdateHost", _UpdateHost); + // Execute insert command. + bool commandSuccess = false; + int executeNonQuery = dbCommand.ExecuteNonQuery(); + if (executeNonQuery == 1) + { + dbCommand.CommandText = "SELECT Max(Id) FROM " + TableNameFmt + ";"; + _Id = (Int32)Convert.ToInt64(dbCommand.ExecuteScalar()); + commandSuccess = (_Id > 0); + } + return commandSuccess; + } + + //------------------------------------------------------------------- + // Update command. + public override bool ExecuteUpdateCommand (DbCommand dbCommand) + { + // Avoid update if Identity field isn't valid. + if (_Id == 0) throw new Exception("Invalid for Update - item has an invalid Id"); + // Columns to update. + List columnNames = ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); + // Construct query. + String query = "UPDATE " + TableNameFmt + " SET "; + if (dbCommand is SqlCommand) + { + query += StringPairList.CreateFrom(columnNames.Bracket("[","]"),columnNames).Concat("=@").Concat(", ") + " "; + query += "WHERE Id=@Id;"; + } + else + { + query += columnNames.Concat(", ", "", "=?") + " "; + query += "WHERE Id=?;"; + } + dbCommand.CommandText = query; + Log(GetType().Name + ".ExecuteUpdateCommand", dbCommand.CommandText); + // Populate parameters. + dbCommand.Parameters.Clear(); + if (columnNames.ContainsCI("OrganisationId")) AddCommandParameter(dbCommand, "@OrganisationId", _OrganisationId); + if (columnNames.ContainsCI("SportIdPrimary")) AddCommandParameter(dbCommand, "@SportIdPrimary", _SportIdPrimary); + if (columnNames.ContainsCI("RegionIdCountry")) AddCommandParameter(dbCommand, "@RegionIdCountry", _RegionIdCountry); + if (columnNames.ContainsCI("EventAt")) AddCommandParameter(dbCommand, "@EventAt", _EventAt); + if (columnNames.ContainsCI("EventTypeCode")) AddCommandParameter(dbCommand, "@EventTypeCode", _EventTypeCode); + if (columnNames.ContainsCI("About")) AddCommandParameter(dbCommand, "@About", _About); + if (columnNames.ContainsCI("EventData")) AddCommandParameter(dbCommand, "@EventData", _EventData); + if (columnNames.ContainsCI("PublishedAt")) AddCommandParameter(dbCommand, "@PublishedAt", _PublishedAt); + if (columnNames.ContainsCI("ExpiresAt")) AddCommandParameter(dbCommand, "@ExpiresAt", _ExpiresAt); + if (columnNames.ContainsCI("Notes")) AddCommandParameter(dbCommand, "@Notes", _Notes); + if (columnNames.ContainsCI("Flags")) AddCommandParameter(dbCommand, "@Flags", _Flags); + if (columnNames.ContainsCI("Status")) AddCommandParameter(dbCommand, "@Status", _Status); + if (columnNames.ContainsCI("UpdateOn")) AddCommandParameter(dbCommand, "@UpdateOn", _UpdateOn); + if (columnNames.ContainsCI("UpdateBy")) AddCommandParameter(dbCommand, "@UpdateBy", _UpdateBy); + if (columnNames.ContainsCI("UpdateHost")) AddCommandParameter(dbCommand, "@UpdateHost", _UpdateHost); + AddCommandParameter(dbCommand, "@Id", _Id); + int executeNonQueryResult = dbCommand.ExecuteNonQuery(); + return (executeNonQueryResult == 1); + } + + //------------------------------------------------------------------- + } +} diff --git a/SaxoniteStandardDbas/Dbas/Internal/OrganisationOpportunity_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/OrganisationOpportunity_Db.cs index 26eb166..232ea3b 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/OrganisationOpportunity_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/OrganisationOpportunity_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/Organisation_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/Organisation_Db.cs index 5174baf..1a51e4f 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/Organisation_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/Organisation_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/Region_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/Region_Db.cs index d5cd68c..4343684 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/Region_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/Region_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/Sport_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/Sport_Db.cs index 8cc3c0e..cb462d4 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/Sport_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/Sport_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/UserAccount_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/UserAccount_Db.cs index 287f893..6efb07e 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/UserAccount_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/UserAccount_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/UserActivity_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/UserActivity_Db.cs index f29d095..fbc2b53 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/UserActivity_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/UserActivity_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/UserOrganisation_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/UserOrganisation_Db.cs index 129e38f..68e3e86 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/UserOrganisation_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/UserOrganisation_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/UserRole_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/UserRole_Db.cs index 180d373..62d2933 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/UserRole_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/UserRole_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/UserSession_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/UserSession_Db.cs index 021bd4c..b859422 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/UserSession_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/UserSession_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/UserSportExperience_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/UserSportExperience_Db.cs index c326420..ed09b57 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/UserSportExperience_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/UserSportExperience_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Internal/UserSport_Db.cs b/SaxoniteStandardDbas/Dbas/Internal/UserSport_Db.cs index 0a89593..b9c62df 100644 --- a/SaxoniteStandardDbas/Dbas/Internal/UserSport_Db.cs +++ b/SaxoniteStandardDbas/Dbas/Internal/UserSport_Db.cs @@ -9,7 +9,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 26-Aug-2021 12:36:27 +// Code generated by Sarand Database Utilities Sat 20-Nov-2021 14:44:06 //--------------------------------------------------------------------------- namespace Saxonite.Net.Standard.Dbas.Internal { diff --git a/SaxoniteStandardDbas/Dbas/Mgr/SaxAccountMgr_Dbas-UserOrganisation.cs b/SaxoniteStandardDbas/Dbas/Mgr/SaxAccountMgr_Dbas-UserOrganisation.cs index 2ead669..828383d 100644 --- a/SaxoniteStandardDbas/Dbas/Mgr/SaxAccountMgr_Dbas-UserOrganisation.cs +++ b/SaxoniteStandardDbas/Dbas/Mgr/SaxAccountMgr_Dbas-UserOrganisation.cs @@ -348,6 +348,14 @@ namespace Saxonite.Net.Standard.Dbas.Mgr SetUserOrganisationColDfn(columnDfn, "Organisation", 160, SaxDbDfn_Core.ColumnIdx.Organisation_Name, ColumnAlignment.Left, DataValue.DataType.String, aliasUserOrganisation_Organisation, prefixUserOrganisation_Organisation); columnDfn.ReadOnly = true; break; + case SaxUserOrganisation.Column.Organisation_Category: + SetUserOrganisationColDfn(columnDfn, "Category", 60, SaxDbDfn_Core.ColumnIdx.Organisation_OrganisationCategory, ColumnAlignment.Center, DataValue.DataType.Long, aliasUserOrganisation_Organisation, prefixUserOrganisation_Organisation); + columnDfn.ReadOnly = true; + break; + case SaxUserOrganisation.Column.Organisation_Type: + SetUserOrganisationColDfn(columnDfn, "Type", 60, SaxDbDfn_Core.ColumnIdx.Organisation_OrganisationType, ColumnAlignment.Center, DataValue.DataType.Long, aliasUserOrganisation_Organisation, prefixUserOrganisation_Organisation); + columnDfn.ReadOnly = true; + break; case SaxUserOrganisation.Column.Organisation_RegionId: SetUserOrganisationColDfn(columnDfn, "Organisation region Id", 80, SaxDbDfn_Core.ColumnIdx.Organisation_RegionIdPrimary, ColumnAlignment.Right, DataValue.DataType.Long, aliasUserOrganisation_Organisation, prefixUserOrganisation_Organisation); columnDfn.ReadOnly = true; @@ -693,6 +701,8 @@ namespace Saxonite.Net.Standard.Dbas.Mgr query.Joins.Add(joinOrganisation); List OrganisationCols = new List(); OrganisationCols.Add(SaxDbDfn_Core.ColumnIdx.Organisation_Name); + OrganisationCols.Add(SaxDbDfn_Core.ColumnIdx.Organisation_OrganisationCategory); + OrganisationCols.Add(SaxDbDfn_Core.ColumnIdx.Organisation_OrganisationType); OrganisationCols.Add(SaxDbDfn_Core.ColumnIdx.Organisation_RegionIdPrimary); OrganisationCols.Add(SaxDbDfn_Core.ColumnIdx.Organisation_SportIdPrimary); foreach (var col in OrganisationCols) diff --git a/SaxoniteStandardDbas/Dbas/Mgr/SaxActivityMgr_Dbas-OrganisationEvent.cs b/SaxoniteStandardDbas/Dbas/Mgr/SaxActivityMgr_Dbas-OrganisationEvent.cs new file mode 100644 index 0000000..e6ed0b8 --- /dev/null +++ b/SaxoniteStandardDbas/Dbas/Mgr/SaxActivityMgr_Dbas-OrganisationEvent.cs @@ -0,0 +1,689 @@ +using Sarand.Net.Standard.Dbas.Data; +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 Saxonite.Base.App; +using Saxonite.Net.Standard.Dbas.Bus; +using Saxonite.Net.Standard.Dbas.Internal; +using Saxonite.Net.Standard.Base.App; +using Saxonite.Net.Standard.Base.Bus; +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Text; +using Sarand.Net.Standard.Base.Utils; +using System.Linq; + +namespace Saxonite.Net.Standard.Dbas.Mgr +{ + //======================================================================= + partial class SaxActivityMgr_Dbas + { + //******************************************************************* + // Activity Mgr - Organisation Event + //******************************************************************* + // Utilities. + private List GetLogProperties(SaxOrganisationEvent organisationEvent) + { + return new List() + { + new StringPair("Id", SysId.ToString(organisationEvent.Id)), + new StringPair("OrganisationId", SysId.ToString(organisationEvent.OrganisationId)), + new StringPair("Event at", DateUtil.Format(organisationEvent.EventAt, "d-MMM-yyyy HH:mm")), + new StringPair("Event type", EventTypeCodes.GetDescForType(organisationEvent.EventType)), + new StringPair("Status", organisationEvent.StatusCode) + }; + } + + //------------------------------------------------------------------- + // Create item. + public override SaxOrganisationEvent CreateOrganisationEvent(SysId userAccountIdJournalist) + { + ClearErrorState(); + return new SaxOrganisationEvent_Dbas(CoreDatabase, null, userAccountIdJournalist, 0); + } + private SaxOrganisationEvent_Dbas CreateOrganisationEvent(OrganisationEvent_Db dbOrganisationEvent) + { + ClearErrorState(); + SaxOrganisationEvent_Dbas organisationEvent = new SaxOrganisationEvent_Dbas(CoreDatabase, new SysId(dbOrganisationEvent._Id), new SysId(dbOrganisationEvent._OrganisationId), (UInt16)dbOrganisationEvent._Flags); + PopulateFrom(dbOrganisationEvent, organisationEvent); + return organisationEvent; + } + + //------------------------------------------------------------------- + // Get item. + public override SaxOrganisationEvent GetOrganisationEvent(SaxOrganisationEvent.Params prm) + { + ClearErrorState(); + return GetOrganisationEvent(GetOrganisationEventQueryFilter(prm).Concat(" And ", "(", ")")); + } + private SaxOrganisationEvent GetOrganisationEvent(String filter) + { + ClearErrorState(); + long count = GetOrganisationEventCount(filter); + if (count == 0) return null; + if (count != 1) + { + SetErrorState("Multiple items found"); + return null; + } + SaxOrganisationEvent organisationEvent = null; + // Query data. + using (var dbConnection = CoreDatabase.CreateConnection()) + using (var dbCommand = dbConnection.CreateCommand()) + { + try + { + dbConnection.Open(); + OrganisationEvent_Db dbOrganisationEvent = new OrganisationEvent_Db(CoreDbInfo); + dbOrganisationEvent.PopulateFrom(dbCommand, aliasOrganisationEvent, filter); + organisationEvent = CreateOrganisationEvent(dbOrganisationEvent); + } + catch (Exception exc) + { + SetErrorState("Database query exception"); + SaLogger.Warn(GetType().Name + ".GetOrganisationEvent\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc)); + } + } + return organisationEvent; + } + + //------------------------------------------------------------------- + // Validate item. + public override bool IsValidOrganisationEventData(SaxOrganisationEvent.Data data, SaxOrganisationEvent.ErrField errField) + { + ClearErrorState(); + if (!base.IsValidOrganisationEventData(data, errField)) return false; + return true; + } + + //------------------------------------------------------------------- + // Insert item. + public override bool InsertOrganisationEvent(SaxOrganisationEvent organisationEvent, DbUpdateInfo dbUpdateInfo) + { + String fn = GetType().Name + ".InsertOrganisationEvent"; + ClearErrorState(); + if (!IsValidOrganisationEvent(organisationEvent)) return false; + if (SysId.IsValid(organisationEvent.Id)) return SetErrorState(ErrorMessage.ValiditemId); + using (var dbConnection = CoreDatabase.CreateConnection()) + using (var dbCommand = dbConnection.CreateCommand()) + { + try + { + dbConnection.Open(); + OrganisationEvent_Db dbOrganisationEvent = new OrganisationEvent_Db(CoreDbInfo); + PopulateTo(dbOrganisationEvent, organisationEvent, dbUpdateInfo); + if (OrganisationEvent_Db.FieldsNonId.Contains("Id")) + { + // Generate next Id. + // ToDo dbOrganisationEvent._Id = CoreDatabase.GetNextIdFromTable("OrganisationEvent"); + } + dbOrganisationEvent.ExecuteInsertCommand(dbCommand); + organisationEvent.Id = new SysId(dbOrganisationEvent._Id); + organisationEvent.Changed = false; + if (DebugMode) SaLogger.Debug(fn + " Inserted. " + GetLogProperties(organisationEvent).Concat(": ").Concat("", "\n\t")); + } + catch (Exception exc) { SetErrorState(exc.Message); } + } + return !HasErrorState(); + } + + //------------------------------------------------------------------- + // Update item. + public override bool UpdateOrganisationEvent(SaxOrganisationEvent organisationEvent, DbUpdateInfo dbUpdateInfo) + { + String fn = GetType().Name + ".UpdateOrganisationEvent"; + ClearErrorState(); + if (!IsValidOrganisationEvent(organisationEvent)) return false; + if (!SysId.IsValid(organisationEvent.Id)) return SetErrorState(ErrorMessage.InvalidItemId); + if (!organisationEvent.Changed) + { + if (DebugMode) SaLogger.Debug(fn + " Data not changed. " + GetLogProperties(organisationEvent).Concat(": ").Concat("", "\n\t")); + return true; + } + using (var dbConnection = CoreDatabase.CreateConnection()) + using (var dbCommand = dbConnection.CreateCommand()) + { + try + { + // Retrieve item. + dbConnection.Open(); + OrganisationEvent_Db dbOrganisationEvent = new OrganisationEvent_Db(CoreDbInfo); + dbOrganisationEvent.PopulateFrom(dbCommand, aliasOrganisationEvent, "Id=" + SysId.ToString(organisationEvent.Id)); + // ToDo SaxUpdateLogItemMonitor_OrganisationEvent updateLogMonitor = new SaxUpdateLogItemMonitor_OrganisationEvent(SessionContext, CreateOrganisationEvent(dbOrganisationEvent), dbUpdateInfo); + // Update item. + PopulateTo(dbOrganisationEvent, organisationEvent, dbUpdateInfo); + dbOrganisationEvent.ExecuteUpdateCommand(dbCommand); + organisationEvent.Changed = false; + if (DebugMode) SaLogger.Debug(fn + " Updated. " + GetLogProperties(organisationEvent).Concat(": ").Concat("", "\n\t")); + // Record updates. + // ToDo updateLogMonitor.RecordUpdatedValues(organisationEvent); + // ToDo updateLogMonitor.LogUpdates(); + } + catch (Exception exc) { SetErrorState(exc.Message); } + } + return !HasErrorState(); + } + + //------------------------------------------------------------------- + // Delete item. + public override bool OrganisationEventCanBeDeleted(SaxOrganisationEvent organisationEvent) + { + ClearErrorState(); + if (!base.OrganisationEventCanBeDeleted(organisationEvent)) return false; + return true; + } + public override bool DeleteOrganisationEvent(SaxOrganisationEvent organisationEvent, DbUpdateInfo dbUpdateInfo) + { + String fn = GetType().Name + ".DeleteOrganisationEvent"; + ClearErrorState(); + if (!OrganisationEventCanBeDeleted(organisationEvent)) return false; + + // Organisation Events are logically deleted by changing the status. + organisationEvent.Status = SaStatus.Deleted; + return UpdateOrganisationEvent(organisationEvent, dbUpdateInfo); + + /* + * Physical deletion. + using (var dbConnection = CoreDatabase.CreateConnection()) + using (var dbCommand = dbConnection.CreateCommand()) + { + try + { + // Retrieve item. + dbConnection.Open(); + OrganisationEvent_Db dbOrganisationEvent = new OrganisationEvent_Db(CoreDbInfo); + dbOrganisationEvent.PopulateFrom(dbCommand, aliasOrganisationEvent, "Id=" + organisationEvent.Id.ToString()); + // Delete item. + dbCommand.CommandType = System.Data.CommandType.Text; + dbCommand.CommandText = "DELETE FROM " + SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.OrganisationEvent) + " WHERE Id=" + SysId.ToString(organisationEvent.Id) + ";"; + dbCommand.ExecuteNonQuery(); + organisationEvent.Changed = false; + if (DebugMode) SaLogger.Debug(fn + " Deleted. " + GetLogProperties(organisationEvent).Concat(": ").Concat("", "\n\t")); + } + catch (Exception exc) { SetErrorState(exc.Message); } + } + return !HasErrorState(); + */ + } + + //------------------------------------------------------------------- + // Copy data properties to and from database. + private void PopulateTo(OrganisationEvent_Db dbOrganisationEvent, SaxOrganisationEvent organisationEvent, DbUpdateInfo dbUpdateInfo) + { + dbOrganisationEvent._Id = SysId.ToInt(organisationEvent.Id); + dbOrganisationEvent._OrganisationId = SysId.ToInt(organisationEvent.OrganisationId); + dbOrganisationEvent._SportIdPrimary = SysId.ToInt(organisationEvent.SportIdPrimary); + dbOrganisationEvent._RegionIdCountry = SysId.ToInt(organisationEvent.RegionIdCountry); + dbOrganisationEvent._EventAt = organisationEvent.EventAt; + dbOrganisationEvent._EventTypeCode = EventTypeCodes.GetCodeForType(organisationEvent.EventType); + dbOrganisationEvent._About = organisationEvent.About; + dbOrganisationEvent._EventData = organisationEvent.EventData; + dbOrganisationEvent._PublishedAt = organisationEvent.PublishedAt; + dbOrganisationEvent._ExpiresAt = organisationEvent.ExpiresAt; + dbOrganisationEvent._Notes = organisationEvent.Notes; + dbOrganisationEvent._Status = SacsSystem.GetStatusCode(organisationEvent.Status); + dbOrganisationEvent._Flags = (short)organisationEvent.Flags; + if (!SysId.IsValid(organisationEvent.Id)) + { + dbOrganisationEvent._CreateOn = DateTime.Now; + dbOrganisationEvent._CreateBy = dbUpdateInfo.UserId.ToInt(); + dbOrganisationEvent._CreateHost = dbUpdateInfo.Host; + } + dbOrganisationEvent._UpdateOn = DateTime.Now; + dbOrganisationEvent._UpdateBy = dbUpdateInfo.UserId.ToInt(); + dbOrganisationEvent._UpdateHost = dbUpdateInfo.Host; + } + private void PopulateFrom(OrganisationEvent_Db dbOrganisationEvent, SaxOrganisationEvent organisationEvent) + { + //organisationEvent.Id = new SysId(dbOrganisationEvent._Id); + //organisationEvent.OrganisationId = new SysId(dbOrganisationEvent._OrganisationId); + organisationEvent.SportIdPrimary = new SysId(dbOrganisationEvent._SportIdPrimary); + organisationEvent.RegionIdCountry = new SysId(dbOrganisationEvent._RegionIdCountry); + organisationEvent.EventAt = dbOrganisationEvent._EventAt; + organisationEvent.EventType = (Sax.EventType)EventTypeCodes.GetTypeForCode(dbOrganisationEvent._EventTypeCode); + organisationEvent.About = dbOrganisationEvent._About; + organisationEvent.EventData = dbOrganisationEvent._EventData; + organisationEvent.PublishedAt = dbOrganisationEvent._PublishedAt; + organisationEvent.ExpiresAt = dbOrganisationEvent._ExpiresAt; + organisationEvent.Notes = dbOrganisationEvent._Notes; + organisationEvent.Status = SacsSystem.GetStatusForCode(dbOrganisationEvent._Status); + organisationEvent.SetCreateStamp(dbOrganisationEvent._CreateOn, new SysId(dbOrganisationEvent._CreateBy), dbOrganisationEvent._CreateHost); + organisationEvent.SetUpdateStamp(dbOrganisationEvent._UpdateOn, new SysId(dbOrganisationEvent._UpdateBy), dbOrganisationEvent._UpdateHost); + organisationEvent.AcceptChanges(); + } + + //------------------------------------------------------------------- + // Item column definitions. + private static readonly String aliasOrganisationEvent = "Sprt"; + private static readonly String aliasOrganisationEvent_Organisation = "OrgOpp_Org"; + private static readonly String prefixOrganisationEvent_Organisation = "OrgOpp_Org_"; + private static readonly String aliasOrganisationEvent_Organisation_UserOrganisation = "OrgOpp_Org_UsrOrg"; + private static readonly String aliasOrganisationEvent_Sport = "OrgOpp_Spt"; + private static readonly String prefixOrganisationEvent_Sport = "OrgOpp_Spt_"; + private static readonly String aliasOrganisationEvent_Region = "OrgOpp_Rgn"; + private static readonly String prefixOrganisationEvent_Region = "OrgOpp_Rgn_"; + private void SetOrganisationEventColDfn + (ColumnDfn col, String caption, int width, SaxDbDfn_Core.ColumnIdx dbCol, + ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String, + String alias = "", String prefix = "") + { + if (String.IsNullOrEmpty(alias) && SaxDbDfn_Core.GetTableForColumn(dbCol) == SaxDbDfn_Core.TableIdx.OrganisationEvent) + alias = aliasOrganisationEvent; + col.Set(caption, width, (int)dbCol, prefix + SaxDbDfn_Core.GetColumnName(dbCol, false), SaxDbDfn_Core.GetColumnNameQual(dbCol, alias), dataType, align); + if (dataType == DataValue.DataType.String && dbCol != SaxDbDfn_Core.ColumnIdx.Unknown) + col.MaxLength = (int)SaxDbDfn_Core.GetColTextLen(dbCol); + } + public override ColumnDfn GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column columnId, string caption = "", int width = 0) + { + ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width); + switch (columnId) + { + //----------------------------------------------------------- + case SaxOrganisationEvent.Column.Pos: + SetOrganisationEventColDfn(columnDfn, "Pos", 60, SaxDbDfn_Core.ColumnIdx.Unknown, ColumnAlignment.Right); + columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off; + columnDfn.ReadOnly = true; + columnDfn.Resizable = false; + break; + case SaxOrganisationEvent.Column.Id: + SetOrganisationEventColDfn(columnDfn, "Id", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Id, ColumnAlignment.Right, DataValue.DataType.Long); + columnDfn.ReadOnly = true; + break; + + //----------------------------------------------------------- + // Organisation. + case SaxOrganisationEvent.Column.OrganisationId: + SetOrganisationEventColDfn(columnDfn, "Organisation Id", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_OrganisationId, ColumnAlignment.Right, DataValue.DataType.Long); + columnDfn.ReadOnly = true; + break; + case SaxOrganisationEvent.Column.Organisation_Name: + SetOrganisationEventColDfn(columnDfn, "Organisation", 160, SaxDbDfn_Core.ColumnIdx.Organisation_Name, ColumnAlignment.Left, DataValue.DataType.String, aliasOrganisationEvent_Organisation, prefixOrganisationEvent_Organisation); + columnDfn.ReadOnly = true; + break; + + //----------------------------------------------------------- + // Sport. + case SaxOrganisationEvent.Column.SportIdPrimary: + SetOrganisationEventColDfn(columnDfn, "Sport Id", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_SportIdPrimary, ColumnAlignment.Right, DataValue.DataType.Long); + columnDfn.ReadOnly = true; + break; + case SaxOrganisationEvent.Column.Sport_Name: + SetOrganisationEventColDfn(columnDfn, "Sport", 100, SaxDbDfn_Core.ColumnIdx.Sport_Name, ColumnAlignment.Left, DataValue.DataType.String, aliasOrganisationEvent_Sport, prefixOrganisationEvent_Sport); + columnDfn.ReadOnly = true; + break; + + //----------------------------------------------------------- + // Region. + case SaxOrganisationEvent.Column.RegionIdCountry: + SetOrganisationEventColDfn(columnDfn, "Region Id", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_RegionIdCountry, ColumnAlignment.Right, DataValue.DataType.Long); + columnDfn.ReadOnly = true; + break; + case SaxOrganisationEvent.Column.Region_Name: + SetOrganisationEventColDfn(columnDfn, "Region", 100, SaxDbDfn_Core.ColumnIdx.Region_Name, ColumnAlignment.Left, DataValue.DataType.String, aliasOrganisationEvent_Region, prefixOrganisationEvent_Region); + columnDfn.ReadOnly = true; + break; + + //----------------------------------------------------------- + // Event. + case SaxOrganisationEvent.Column.EventAt_Date: + SetOrganisationEventColDfn(columnDfn, "Event", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_EventAt, ColumnAlignment.Center, DataValue.DataType.Date); + columnDfn.ReadOnly = true; + break; + case SaxOrganisationEvent.Column.EventAt_DateTime: + SetOrganisationEventColDfn(columnDfn, "Event", 100, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_EventAt, ColumnAlignment.Center, DataValue.DataType.DateTime); + columnDfn.ReadOnly = true; + break; + case SaxOrganisationEvent.Column.EventTypeCode: + SetOrganisationEventColDfn(columnDfn, "Type", 90, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_EventTypeCode, ColumnAlignment.Center); + break; + case SaxOrganisationEvent.Column.EventType_Desc: + SetOrganisationEventColDfn(columnDfn, "Type", 120, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_EventTypeCode, ColumnAlignment.Center); + break; + case SaxOrganisationEvent.Column.About: + SetOrganisationEventColDfn(columnDfn, "About", 200, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_About); + break; + case SaxOrganisationEvent.Column.PublishedAt_Date: + SetOrganisationEventColDfn(columnDfn, "Published", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_PublishedAt, ColumnAlignment.Center, DataValue.DataType.Date); + columnDfn.ReadOnly = true; + break; + case SaxOrganisationEvent.Column.PublishedAt_DateTime: + SetOrganisationEventColDfn(columnDfn, "Published", 100, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_PublishedAt, ColumnAlignment.Center, DataValue.DataType.DateTime); + columnDfn.ReadOnly = true; + break; + case SaxOrganisationEvent.Column.ExpiresAt_Date: + SetOrganisationEventColDfn(columnDfn, "Expires", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_ExpiresAt, ColumnAlignment.Center, DataValue.DataType.Date); + columnDfn.ReadOnly = true; + break; + case SaxOrganisationEvent.Column.ExpiresAt_DateTime: + SetOrganisationEventColDfn(columnDfn, "Expires", 100, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_ExpiresAt, ColumnAlignment.Center, DataValue.DataType.DateTime); + columnDfn.ReadOnly = true; + break; + + //----------------------------------------------------------- + // Derived properties. + + //----------------------------------------------------------- + // Common properties. + case SaxOrganisationEvent.Column.Notes: + SetOrganisationEventColDfn(columnDfn, "Notes", 240, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Notes); + break; + case SaxOrganisationEvent.Column.Flags: + SetOrganisationEventColDfn(columnDfn, "Flags", 60, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Flags, ColumnAlignment.Center, DataValue.DataType.Long); + break; + case SaxOrganisationEvent.Column.Status: + SetOrganisationEventColDfn(columnDfn, "Status", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Status, ColumnAlignment.Center); + break; + case SaxOrganisationEvent.Column.Status_Desc: + SetOrganisationEventColDfn(columnDfn, "Status", 90, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Status, ColumnAlignment.Center); + break; + case SaxOrganisationEvent.Column.Status_Ind: + SetOrganisationEventColDfn(columnDfn, "Status", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Status, ColumnAlignment.Center, DataValue.DataType.TriState); + columnDfn.TriStateFormat = ColumnTriStateFormat.Lights; + break; + case SaxOrganisationEvent.Column.CreateOn_Date: + SetOrganisationEventColDfn(columnDfn, "Created", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date); + columnDfn.ReadOnly = true; + break; + case SaxOrganisationEvent.Column.UpdateOn_Date: + SetOrganisationEventColDfn(columnDfn, "Updated", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date); + columnDfn.ReadOnly = true; + break; + + //----------------------------------------------------------- + } + if (!String.IsNullOrEmpty(caption)) + columnDfn.Caption = caption; + if (width > 0) + columnDfn.Width = width; + return columnDfn; + } + + //------------------------------------------------------------------- + // Item query filter. + public override List GetOrganisationEventQueryFilter(SaxOrganisationEvent.Params prm) + { + List filter = new List(); + + // Item Ids. + String idsIncluded = prm.IdsIncluded.Concat(","); + if (!idsIncluded.IsEmpty()) + filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Id, aliasOrganisationEvent) + " IN (" + idsIncluded + ")"); + String idsExcluded = prm.IdsExcluded.Concat(","); + if (!idsExcluded.IsEmpty()) + filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Id, aliasOrganisationEvent) + " NOT IN (" + idsExcluded + ")"); + + // User Account Ids. + String userAccountIdsIncluded = prm.UserAccountIdsIncluded.Concat(","); + if (!userAccountIdsIncluded.IsEmpty()) + { + // User Organisation. + if (!StringUtil.IsEmpty(prm.Alias_UserOrganisation)) + { + // Filter directly on the joined User Organisation table. + filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOrganisation_UserAccountId, prm.Alias_UserOrganisation) + " IN (" + userAccountIdsIncluded + ")"); + } + else + { + // User Organisation query. + String alias_UserOrganisation = aliasOrganisationEvent_Organisation_UserOrganisation; + DbQuery queryUserOrganisation = new DbQuery(CoreDatabase.DbmsType); + queryUserOrganisation.Tables.Add(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.UserOrganisation), alias_UserOrganisation); + queryUserOrganisation.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOrganisation_UserAccountId, alias_UserOrganisation) + " IN (" + userAccountIdsIncluded + ")"); + + // Filter Organisation directly against the Organisation Event. + queryUserOrganisation.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOrganisation_OrganisationId, alias_UserOrganisation)); + filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_OrganisationId, aliasOrganisationEvent) + " IN (" + queryUserOrganisation.BuildQuery() + ")"); + } + } + + // Organisation Ids. + String organisationIdsIncluded = prm.OrganisationIdsIncluded.Concat(","); + if (!organisationIdsIncluded.IsEmpty()) + filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_OrganisationId, aliasOrganisationEvent) + " IN (" + organisationIdsIncluded + ")"); + + // Sport Ids. + String sportIdsIncluded = prm.SportIdsIncluded.Concat(","); + if (!sportIdsIncluded.IsEmpty()) + filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_SportIdPrimary, aliasOrganisationEvent) + " IN (" + sportIdsIncluded + ")"); + + // Region Ids. + String regionIdsIncluded = prm.RegionIdsIncluded.Concat(","); + if (!regionIdsIncluded.IsEmpty()) + filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_RegionIdCountry, aliasOrganisationEvent) + " IN (" + regionIdsIncluded + ")"); + + // About. + if (!StringUtil.IsEmpty(prm.AboutPartial)) + filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_About, aliasOrganisationEvent) + " Like '%" + DbQuery.FormatForLike(prm.AboutPartial, true) + "%'"); + + // Article. + if (!StringUtil.IsEmpty(prm.EventFilter)) + { + // Split filter into words. + List filterWords = prm.EventFilter.Split((char[])null).ToList(); + filterWords.RemoveDuplicatesCI(); + filterWords.RemoveBlanks(); + foreach (String filterWord in filterWords) + { + List articleFilter = new List(); + articleFilter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_About, aliasOrganisationEvent) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'"); + filter.Add(articleFilter.Concat(" OR ", "(", ")")); + } + } + + // Notes. + if (!StringUtil.IsEmpty(prm.NotesPartial)) + filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Notes, aliasOrganisationEvent) + " LIKE '%" + DbQuery.FormatForLike(prm.NotesPartial) + "%'"); + + // Status. + if (prm.StatusCat != SaxOrganisationEvent.StatusCat.Any) + filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Status, aliasOrganisationEvent) + GetOrganisationEventStatusCatFilterCondition(prm.StatusCat)); + + if (filter.Count < 1) filter.Add("1=1"); + return filter; + } + internal static String GetOrganisationEventStatusCatFilterCondition(SaxOrganisationEvent.StatusCat statusCat) + { + if (statusCat == SaxOrganisationEvent.StatusCat.ActiveOnly) + return "='" + SacsSystem.GetStatusCode(SaStatus.Active) + "'"; + if (statusCat == SaxOrganisationEvent.StatusCat.InactiveOnly) + return "='" + SacsSystem.GetStatusCode(SaStatus.Inactive) + "'"; + if (statusCat == SaxOrganisationEvent.StatusCat.NotDeleted) + return "!='" + SacsSystem.GetStatusCode(SaStatus.Deleted) + "'"; + if (statusCat == SaxOrganisationEvent.StatusCat.DeletedOnly) + return "='" + SacsSystem.GetStatusCode(SaStatus.Deleted) + "'"; + return ""; + } + // Item sort columns. + public List GetOrganisationEventSortColumns(SaxOrganisationEvent.Params prm) + { + // Sort sequence: + List sortColumnNames = new List(); + foreach (var columnDfn in prm.SortColumns) + { + // Need to ensure correct alias used for OrganisationEvent columns in case of conflict. + String sortCol = String.Empty; + if (SaxDbDfn_Core.GetTableForColumn((SaxDbDfn_Core.ColumnIdx)columnDfn.DbColumn) == SaxDbDfn_Core.TableIdx.OrganisationEvent) + { + sortCol = SaxDbDfn_Core.GetColumnNameQual((SaxDbDfn_Core.ColumnIdx)columnDfn.DbColumn, aliasOrganisationEvent); + } + else + { + sortCol = columnDfn.DataName; + if (!StringUtil.IsEmpty(columnDfn.SortDataName)) + sortCol = columnDfn.SortDataName; + } + if (!sortCol.IsEmpty()) + { + DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls + sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", ")); + } + } + sortColumnNames.RemoveBlanks(); + if (sortColumnNames.IsEmpty()) + { + // Default sort columns. + sortColumnNames.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Id, aliasOrganisationEvent) + " ASC"); + } + return sortColumnNames; + } + + //------------------------------------------------------------------- + // Item count. + private long GetOrganisationEventCount(String filter) + { + ClearErrorState(); + return CoreDatabase.GetRowCount(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.OrganisationEvent) + " As " + aliasOrganisationEvent, filter); + } + public override long GetOrganisationEventCount(SaxOrganisationEvent.Params prm) + { + ClearErrorState(); + return GetOrganisationEventCount(GetOrganisationEventQueryFilter(prm).Concat(" AND ", "(", ")")); + } + + //------------------------------------------------------------------- + // Item list. + public override List GetOrganisationEventList(SaxOrganisationEvent.Params prm) + { + List userActivitys = new List(); + DbQuery qry = new DbQuery(CoreDatabase.DbmsType); + qry.Tables.Add(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.OrganisationEvent), aliasOrganisationEvent); + OrganisationEvent_Db dbOrganisationEvent = new OrganisationEvent_Db(CoreDbInfo); + qry.Columns.AddRange(dbOrganisationEvent.ExistingColumnNames); + qry.Filters.AddRange(GetOrganisationEventQueryFilter(prm)); + qry.OrderBy.AddRange(GetOrganisationEventSortColumns(prm)); + // Query data. + using (var dbConnection = CoreDatabase.CreateConnection()) + using (var dbCommand = dbConnection.CreateCommand()) + { + try + { + dbConnection.Open(); + dbCommand.CommandText = qry.BuildQuery(prm.ResultsPaging); + using (DbDataReader dbDataReader = dbCommand.ExecuteReader()) + { + while (dbDataReader.Read()) + { + dbOrganisationEvent = new OrganisationEvent_Db(CoreDbInfo); + dbOrganisationEvent.PopulateFrom(dbDataReader); + userActivitys.Add(CreateOrganisationEvent(dbOrganisationEvent)); + } + } + } + catch (Exception exc) + { + SaLogger.Warn(GetType().Name + ".GetOrganisationEventList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc)); + } + } + return userActivitys; + } + + //------------------------------------------------------------------- + // Item query execution. + public override DbResultSet ExecuteOrganisationEventQuery(List columns, SaxOrganisationEvent.Params prm) + { + ClearErrorState(); + + //--------------------------------------------------------------------- + // Construct query. + DbQuery query = new DbQuery(CoreDatabase.DbmsType); + query.Tables.Add(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.OrganisationEvent), aliasOrganisationEvent); + + // Add columns as defined in query list. + if (columns.HasId(SaxOrganisationEvent.Column.Id)) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Id, aliasOrganisationEvent)); + bool hasOrganisationCols = (columns.HasId(SaxOrganisationEvent.Column.Organisation_Name)); + if (columns.HasId(SaxOrganisationEvent.Column.OrganisationId) || hasOrganisationCols) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_OrganisationId, aliasOrganisationEvent)); + bool hasSportCols = (columns.HasId(SaxOrganisationEvent.Column.Sport_Name)); + if (columns.HasId(SaxOrganisationEvent.Column.SportIdPrimary) || hasSportCols) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_SportIdPrimary, aliasOrganisationEvent)); + bool hasRegionCols = (columns.HasId(SaxOrganisationEvent.Column.Region_Name)); + if (columns.HasId(SaxOrganisationEvent.Column.RegionIdCountry) || hasRegionCols) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_RegionIdCountry, aliasOrganisationEvent)); + if (columns.HasId(SaxOrganisationEvent.Column.EventAt_Date) || columns.HasId(SaxOrganisationEvent.Column.EventAt_DateTime)) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_EventAt, aliasOrganisationEvent)); + if (columns.HasId(SaxOrganisationEvent.Column.EventTypeCode) || columns.HasId(SaxOrganisationEvent.Column.EventType_Desc)) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_EventTypeCode, aliasOrganisationEvent)); + if (columns.HasId(SaxOrganisationEvent.Column.About)) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_About, aliasOrganisationEvent)); + if (columns.HasId(SaxOrganisationEvent.Column.PublishedAt_Date) || columns.HasId(SaxOrganisationEvent.Column.PublishedAt_DateTime)) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_PublishedAt, aliasOrganisationEvent)); + if (columns.HasId(SaxOrganisationEvent.Column.ExpiresAt_Date) || columns.HasId(SaxOrganisationEvent.Column.ExpiresAt_DateTime)) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_ExpiresAt, aliasOrganisationEvent)); + // Common properties. + if (columns.HasId(SaxOrganisationEvent.Column.Notes)) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Notes, aliasOrganisationEvent)); + if (columns.HasId(SaxOrganisationEvent.Column.Flags)) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Flags, aliasOrganisationEvent)); + if (columns.HasId(SaxOrganisationEvent.Column.Status) || columns.HasId(SaxOrganisationEvent.Column.Status_Desc) || columns.HasId(SaxOrganisationEvent.Column.Status_Ind)) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Status, aliasOrganisationEvent)); + if (columns.HasId(SaxOrganisationEvent.Column.CreateOn_Date)) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_CreateOn, aliasOrganisationEvent)); + if (columns.HasId(SaxOrganisationEvent.Column.UpdateOn_Date)) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_UpdateOn, aliasOrganisationEvent)); + + //--------------------------------------------------------------------- + // Organisation. + if (hasOrganisationCols) + { + DbQueryJoin joinOrganisation = new DbQueryJoin(DbJoinType.LeftOuter); + joinOrganisation.Table = new StringPair(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.Organisation), aliasOrganisationEvent_Organisation); + joinOrganisation.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.Organisation_Id, aliasOrganisationEvent_Organisation) + "=" + SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_OrganisationId, aliasOrganisationEvent)); + query.Joins.Add(joinOrganisation); + List cols = new List(); + cols.Add(SaxDbDfn_Core.ColumnIdx.Organisation_Name); + foreach (var col in cols) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(col, aliasOrganisationEvent_Organisation), prefixOrganisationEvent_Organisation + SaxDbDfn_Core.GetColumnName(col, false)); + prm.Alias_Organisation = aliasOrganisationEvent_Organisation; + } + + //--------------------------------------------------------------------- + // Primary Sport. + if (hasSportCols) + { + DbQueryJoin joinSport = new DbQueryJoin(DbJoinType.LeftOuter); + joinSport.Table = new StringPair(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.Sport), aliasOrganisationEvent_Sport); + joinSport.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.Sport_Id, aliasOrganisationEvent_Sport) + "=" + SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_SportIdPrimary, aliasOrganisationEvent)); + query.Joins.Add(joinSport); + List cols = new List(); + cols.Add(SaxDbDfn_Core.ColumnIdx.Sport_Name); + foreach (var col in cols) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(col, aliasOrganisationEvent_Sport), prefixOrganisationEvent_Sport + SaxDbDfn_Core.GetColumnName(col, false)); + } + + //--------------------------------------------------------------------- + // Primary Region. + if (hasRegionCols) + { + DbQueryJoin joinRegion = new DbQueryJoin(DbJoinType.LeftOuter); + joinRegion.Table = new StringPair(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.Region), aliasOrganisationEvent_Region); + joinRegion.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.Region_Id, aliasOrganisationEvent_Region) + "=" + SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_RegionIdCountry, aliasOrganisationEvent)); + query.Joins.Add(joinRegion); + List cols = new List(); + cols.Add(SaxDbDfn_Core.ColumnIdx.Region_Name); + foreach (var col in cols) + query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(col, aliasOrganisationEvent_Region), prefixOrganisationEvent_Region + SaxDbDfn_Core.GetColumnName(col, false)); + } + + //--------------------------------------------------------------------- + // Populate filter. + query.Filters.AddRange(GetOrganisationEventQueryFilter(prm)); + + if (prm.IdsIncluded.Count != 1) + { + // Configure sort sequence. + foreach (String sortColumn in GetOrganisationEventSortColumns(prm)) + query.OrderBy.Add(sortColumn); + } + + //--------------------------------------------------------------------- + //return new DbResultSet_DataTableReader(db, query.BuildQuery(prm.ResultsPaging)); + return DbResultSet_DataReader.ExecuteQuery(CoreDatabase, query.BuildQuery(prm.ResultsPaging)); + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SaxoniteStandardDbas/Dbas/Mgr/SaxActivityMgr_Dbas-OrganisationOpportunity.cs b/SaxoniteStandardDbas/Dbas/Mgr/SaxActivityMgr_Dbas-OrganisationOpportunity.cs index c76c1bf..926f183 100644 --- a/SaxoniteStandardDbas/Dbas/Mgr/SaxActivityMgr_Dbas-OrganisationOpportunity.cs +++ b/SaxoniteStandardDbas/Dbas/Mgr/SaxActivityMgr_Dbas-OrganisationOpportunity.cs @@ -30,6 +30,7 @@ namespace Saxonite.Net.Standard.Dbas.Mgr { new StringPair("Id", SysId.ToString(organisationOpportunity.Id)), new StringPair("OrganisationId", SysId.ToString(organisationOpportunity.OrganisationId)), + new StringPair("Opportunity type", OpportunityTypeCodes.GetDescForType(organisationOpportunity.OpportunityType)), new StringPair("Position", StringUtil.Left(organisationOpportunity.Position,32)), new StringPair("Status", organisationOpportunity.StatusCode) }; @@ -327,10 +328,10 @@ namespace Saxonite.Net.Standard.Dbas.Mgr //----------------------------------------------------------- // Opportunity. case SaxOrganisationOpportunity.Column.OpportunityTypeCode: - SetOrganisationOpportunityColDfn(columnDfn, "Opportunity", 90, SaxDbDfn_Core.ColumnIdx.OrganisationOpportunity_OpportunityTypeCode, ColumnAlignment.Center); + SetOrganisationOpportunityColDfn(columnDfn, "Type", 90, SaxDbDfn_Core.ColumnIdx.OrganisationOpportunity_OpportunityTypeCode, ColumnAlignment.Center); break; case SaxOrganisationOpportunity.Column.OpportunityType_Desc: - SetOrganisationOpportunityColDfn(columnDfn, "Opportunbity", 120, SaxDbDfn_Core.ColumnIdx.OrganisationOpportunity_OpportunityTypeCode, ColumnAlignment.Center); + SetOrganisationOpportunityColDfn(columnDfn, "Type", 120, SaxDbDfn_Core.ColumnIdx.OrganisationOpportunity_OpportunityTypeCode, ColumnAlignment.Center); break; case SaxOrganisationOpportunity.Column.Position: SetOrganisationOpportunityColDfn(columnDfn, "Position", 200, SaxDbDfn_Core.ColumnIdx.OrganisationOpportunity_Position); diff --git a/SaxoniteStandardDbas/Resources/Database/SaxDbDfn_Core.xml b/SaxoniteStandardDbas/Resources/Database/SaxDbDfn_Core.xml index 543282c..45e7121 100644 --- a/SaxoniteStandardDbas/Resources/Database/SaxDbDfn_Core.xml +++ b/SaxoniteStandardDbas/Resources/Database/SaxDbDfn_Core.xml @@ -256,7 +256,7 @@ false false 1 - 9 + 11 false @@ -666,7 +666,7 @@ false false 2 - 11 + 13 false @@ -1289,7 +1289,7 @@ false false 1 - 3 + 9 false @@ -1717,7 +1717,7 @@ false false 1 - 11 + 12 false @@ -2449,7 +2449,7 @@ false false 1 - 7 + 11 false @@ -2526,6 +2526,418 @@ + + dbo + OrganisationEvent + + + + dbo + OrganisationEvent
+ 1 + Id + Int + + 4 + int + true + 10 + 4 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 2 + OrganisationId + Int + + 4 + int + false + 10 + 4 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 3 + SportIdPrimary + Int + + 4 + int + false + 10 + 4 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 4 + RegionIdCountry + Int + + 4 + int + false + 10 + 4 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 5 + EventAt + DateTime + + 93 + smalldatetime + false + 16 + 16 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 6 + EventTypeCode + VarChar + + 12 + varchar + false + 3 + 3 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 7 + About + VarChar + + -9 + nvarchar + false + 2000 + 4000 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 8 + EventData + VarChar + + -9 + nvarchar + false + 0 + 0 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 9 + PublishedAt + DateTime + + 93 + smalldatetime + false + 16 + 16 + 0 + Nullable + true + +
+ + dbo + OrganisationEvent
+ 10 + ExpiresAt + DateTime + + 93 + smalldatetime + false + 16 + 16 + 0 + Nullable + true + +
+ + dbo + OrganisationEvent
+ 11 + Notes + VarChar + + -9 + nvarchar + false + 2000 + 4000 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 12 + Flags + SmallInt + + 5 + smallint + false + 5 + 2 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 13 + Status + VarChar + + 12 + varchar + false + 3 + 3 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 14 + CreateOn + DateTime + + 93 + datetime + false + 23 + 16 + 3 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 15 + CreateBy + Int + + 4 + int + false + 10 + 4 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 16 + CreateHost + VarChar + + 12 + varchar + false + 100 + 100 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 17 + UpdateOn + DateTime + + 93 + datetime + false + 23 + 16 + 3 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 18 + UpdateBy + Int + + 4 + int + false + 10 + 4 + 0 + NoNulls + false + +
+ + dbo + OrganisationEvent
+ 19 + UpdateHost + VarChar + + 12 + varchar + false + 100 + 100 + 0 + NoNulls + false + +
+
+ + + dbo + OrganisationEvent
+ PK_OrganisationEvent + 1 + true + false + false + false + 0 + 0 + false + + + 1 + Id + true + + +
+ + dbo + OrganisationEvent
+ IDX_OrganisationEvent_Country + 3 + false + false + false + false + 0 + 0 + false + + + 1 + RegionIdCountry + true + + +
+ + dbo + OrganisationEvent
+ IDX_OrganisationEvent_Organisation + 3 + false + false + false + false + 0 + 0 + false + + + 1 + OrganisationId + true + + +
+ + dbo + OrganisationEvent
+ IDX_OrganisationEvent_Sport + 3 + false + false + false + false + 0 + 0 + false + + + 1 + SportIdPrimary + true + + +
+
+
dbo OrganisationOpportunity @@ -2866,7 +3278,7 @@ false false 1 - 4 + 5 false @@ -2891,7 +3303,7 @@ 1 - SportIdPrimary + RegionIdPrimary true @@ -2919,7 +3331,7 @@ dbo OrganisationOpportunity
- IDX_OrganisationOpportunity_Region + IDX_OrganisationOpportunity_Sport 3 false false @@ -2931,7 +3343,7 @@ 1 - RegionIdPrimary + SportIdPrimary true @@ -4113,7 +4525,7 @@ false false 1 - 8 + 11 false @@ -4576,7 +4988,7 @@ false false 1 - 16 + 18 false @@ -4960,7 +5372,7 @@ false false 1 - 10 + 15 false @@ -5760,7 +6172,7 @@ false false 1 - 9 + 14 false