v1.2.6.4
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Helpers;
|
||||
using Saxonite.Net.Core.Web.Admin.Controllers;
|
||||
using Saxonite.Net.Core.Web.Base.App;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
@@ -45,6 +48,21 @@ namespace Saxonite.Net.Core.Web.Admin.App
|
||||
/// <summary>User - JSON deserialisation route.</summary>
|
||||
public new UserData User { get { return base.User; } set { SetUser(new UserData_Admin(value)); } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// General filters.
|
||||
public class FilterData
|
||||
{
|
||||
// Sport.
|
||||
public SysId SportId { get; set; }
|
||||
// Region.
|
||||
public SysId RegionId { get; set; }
|
||||
}
|
||||
public FilterData Filter { get; private set; } = new FilterData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Online application encryption IV value - for consistent encryption during session.
|
||||
public String Base64IV_AdminApp { get; private set; } = SacsEncryptionHelper.InitSymmetricEncryptionIV(SaxController_Admin.Base64Key_AdminApp);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Core.Web.Base.App;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
// Admin Image Controller - delivers dynamic images.
|
||||
//=======================================================================
|
||||
public partial class ImageController : SaxController_Admin
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
public static String ParamName_OrganisationLogoEncrypted { get; } = "ole";
|
||||
public static String ParamName_ArticleImageEncrypted { get; } = "aie";
|
||||
public static String ParamName_OrganisationId { get; } = "ori";
|
||||
public static String ParamName_ItemImageId { get; } = "iii";
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public ImageController(SaxLocaliser localiser, ILogger<HomeController> logger) :
|
||||
base(localiser, logger)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Account Contact image request.
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Get the Account Contact Image for the specified account.
|
||||
/// <para>Current User Account is used if no other specified in the encrypted parameter.</para>
|
||||
/// <para>Encrypted parameter:</para>
|
||||
/// <para>- uaie: User Account Id encrypted.</para>
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Route("Image/Account/Contact")]
|
||||
public IActionResult GetAccountContactImage(String uaie)
|
||||
{
|
||||
String userAccountIdParam = "";// ToDo Decrypt from uaie value.
|
||||
SysId userAccountId = userAccountIdParam.ToSysId();
|
||||
if (!SysId.IsValid(userAccountId))
|
||||
userAccountId = UserAccountId;
|
||||
return GetAccountContactImage(userAccountId, Sax.ImageType.Avatar);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Account Contact Image Profile/Upload request.
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Get the current Account Profile Contact Image for the specified account.
|
||||
/// <para>Account is always current User Account - this request is only fir use from the user's own profile page.</para>
|
||||
/// <para>'Uploaded' avatar image will take precedence as this will be the latest if present.</para>
|
||||
/// <para>NB Avoid caching this image as it will change whenever a new one is uploaded.</para>
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Route("Image/Account/Contact/Profile")]
|
||||
[Route("Image/Account/Contact/Upload")]
|
||||
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
|
||||
public IActionResult GetAccountContactImage()
|
||||
{
|
||||
// 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 = UserAccountId;
|
||||
return GetAccountContactImage(userAccountId, Sax.ImageType.Avatar_Upload);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Get the Avatar image for the specified user account.
|
||||
/// </summary>
|
||||
/// <param name="imageTypePriority"></param>
|
||||
/// <returns></returns>
|
||||
private IActionResult GetAccountContactImage(SysId userAccountId, Sax.ImageType imageTypePriority)
|
||||
{
|
||||
String fn = GetType().Name + ".GetAccountContactImage";
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer || !ValidUserSession) return Forbid();
|
||||
ItemId userItemId = new ItemId((short)Sax.DataItemType.UserAccount, userAccountId);
|
||||
|
||||
// Retrieve account contact images.
|
||||
SaxItemImage.Params prmItemImage = new SaxItemImage.Params();
|
||||
prmItemImage.ItemIdsIncluded.Add(userItemId);
|
||||
prmItemImage.ImageTypesIncluded.Add(Sax.ImageType.Avatar);
|
||||
prmItemImage.ImageTypesIncluded.Add(Sax.ImageType.Avatar_Upload);
|
||||
prmItemImage.StatusCat = SaxItemImage.StatusCat.ActiveOnly;
|
||||
SaxItemImage itemImage = null;
|
||||
foreach (SaxItemImage itemImageCandidate in ItemDataMgr.GetItemImageList(prmItemImage))
|
||||
{
|
||||
// One of the 'Avatar' image types will take precedence.
|
||||
if (itemImage == null || itemImageCandidate.ImageType == imageTypePriority)
|
||||
itemImage = itemImageCandidate;
|
||||
}
|
||||
|
||||
if (itemImage == null)
|
||||
return NotFound();
|
||||
|
||||
// Construct response.
|
||||
return File(itemImage.ImageData, itemImage.ContentType);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Organisation logo.
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Get the logo for the specified Organisation.
|
||||
/// <para>Method parameter name (ole) must match name of encrypted parameter.</para>
|
||||
/// <para>Encrypted parameters:</para>
|
||||
/// <para>- ori: Organisation Id.</para>
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Route("Image/Organisation/Logo")]
|
||||
public IActionResult GetOrganisationLogo(String ole)
|
||||
{
|
||||
return GetOrganisationLogo(ole, false);
|
||||
}
|
||||
/// <summary>
|
||||
/// Get the logo for the specified Organisation.
|
||||
/// <para>Method parameter name (ole) must match name of encrypted parameter.</para>
|
||||
/// <para>Encrypted parameters:</para>
|
||||
/// <para>- ori: Organisation Id.</para>
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Route("Image/Organisation/Logo/Upload")]
|
||||
public IActionResult GetOrganisationLogoUpload(String ole)
|
||||
{
|
||||
return GetOrganisationLogo(ole, true);
|
||||
}
|
||||
private IActionResult GetOrganisationLogo(String encryptedParams, bool allowUploadImage)
|
||||
{
|
||||
String fn = GetType().Name + ".GetOrganisationLogo";
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer || !ValidUserSession) return Forbid();
|
||||
|
||||
// Extract encrypted parameters.
|
||||
NameValueCollection parameters = ExtractSessionParams(encryptedParams);
|
||||
if (parameters.Count < 1) return Forbid();
|
||||
|
||||
// Organisation Id.
|
||||
SysId organisationId = parameters.Get(ParamName_OrganisationId).ToSysId();
|
||||
if (!SysId.IsValid(organisationId)) return Forbid();
|
||||
ItemId organisationItemId = new ItemId((short)Sax.DataItemType.Organisation, organisationId);
|
||||
|
||||
// Query Organisation Logo images.
|
||||
SaxItemImage.Params prmItemImage = new SaxItemImage.Params();
|
||||
prmItemImage.ItemIdsIncluded.Add(organisationItemId);
|
||||
prmItemImage.ImageTypesIncluded.Add(Sax.ImageType.OrganisationLogo);
|
||||
if (allowUploadImage)
|
||||
prmItemImage.ImageTypesIncluded.Add(Sax.ImageType.OrganisationLogo_Upload);
|
||||
prmItemImage.StatusCat = SaxItemImage.StatusCat.ActiveOnly;
|
||||
SaxItemImage itemImage = null;
|
||||
foreach (SaxItemImage itemImageCandidate in ItemDataMgr.GetItemImageList(prmItemImage))
|
||||
{
|
||||
// The 'Upload' image will take precedence if allowed.
|
||||
if (itemImage == null || itemImageCandidate.ImageType == Sax.ImageType.OrganisationLogo_Upload)
|
||||
itemImage = itemImageCandidate;
|
||||
}
|
||||
|
||||
if (itemImage == null)
|
||||
return NotFound();
|
||||
|
||||
// Construct response.
|
||||
Response.Headers[HeaderNames.CacheControl] = "no-cache, no-store, must-revalidate, max-age=0";
|
||||
Response.Headers[HeaderNames.Expires] = "-1";
|
||||
return File(itemImage.ImageData, itemImage.ContentType);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Article image.
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Get the specified Article Image.
|
||||
/// <para>Method parameter name (aie) must match name of encrypted parameter.</para>
|
||||
/// <para>Encrypted parameters:</para>
|
||||
/// <para>- iii: Item Image Id.</para>
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Route("Image/Article")]
|
||||
public IActionResult GetArticleImage(String aie)
|
||||
{
|
||||
String fn = GetType().Name + ".GetArticleImage";
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer || !ValidUserSession) return Forbid();
|
||||
ItemId userItemId = new ItemId((short)Sax.DataItemType.UserAccount, UserAccountId);
|
||||
|
||||
// Extract encrypted parameters.
|
||||
NameValueCollection parameters = ExtractSessionParams(aie);
|
||||
if (parameters.Count < 1) return Forbid();
|
||||
|
||||
// Item Image.
|
||||
SysId itemImageId = parameters.Get(ParamName_ItemImageId).ToSysId();
|
||||
if (!SysId.IsValid(itemImageId)) return Forbid();
|
||||
SaxItemImage itemImage = ItemDataMgr.GetItemImageById(itemImageId);
|
||||
if (itemImage == null)
|
||||
return NotFound();
|
||||
|
||||
// Construct response.
|
||||
return File(itemImage.ImageData, itemImage.ContentType);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -9,6 +9,7 @@ using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -30,13 +31,20 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
public String CategoryDesc { get; set; }
|
||||
public long MemberCount { get; set; }
|
||||
// Sport.
|
||||
public long SportId { get; set; }
|
||||
public String SportId { get; set; }
|
||||
public String SportName { get; set; }
|
||||
// Region - country.
|
||||
public long RegionIdCountry { get; set; }
|
||||
public String RegionNameCountry { get; set; }
|
||||
// Primary Region.
|
||||
public class RegionData
|
||||
{
|
||||
public String Id { get; set; }
|
||||
public String Name { get; set; }
|
||||
public bool? Country { get; set; } = null;
|
||||
}
|
||||
public RegionData RegionPrimary { get; } = new RegionData();
|
||||
// Address.
|
||||
public String AddressSummary { get; set; }
|
||||
// Logo.
|
||||
public String LogoImageUrl { get; set; }
|
||||
}
|
||||
private class OrganisationItemData : OrganisationListData
|
||||
{
|
||||
@@ -55,22 +63,30 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
data.CategoryDesc = OrganisationCategoryCodes.GetDescForType(organisation.OrganisationCategory);
|
||||
data.MemberCount = AccountMgr.GetOrganisationMemberCount(organisation.Id);
|
||||
// Sport.
|
||||
data.SportId = SysId.ToLong(organisation.SportIdPrimary);
|
||||
data.SportId = SysId.ToString(organisation.SportIdPrimary, null);
|
||||
using (SaxSport sport = ReferenceMgr.GetSportById(organisation.SportIdPrimary))
|
||||
data.SportName = sport?.Name ?? "";
|
||||
// Region.
|
||||
data.RegionIdCountry = SysId.ToLong(organisation.RegionIdPrimary);
|
||||
using (SaxRegion region = ReferenceMgr.GetRegionById(organisation.RegionIdPrimary))
|
||||
data.RegionNameCountry = region?.Name ?? "";
|
||||
data.SportName = sport?.Name ?? null;
|
||||
// Primary region.
|
||||
data.RegionPrimary.Id = SysId.ToString(organisation.RegionIdPrimary, null);
|
||||
SaxRegion.Data region = Internals.GetRegion(organisation.RegionIdPrimary);
|
||||
if (region != null)
|
||||
{
|
||||
data.RegionPrimary.Name = region.Name;
|
||||
data.RegionPrimary.Country = region.RegionType == Sax.RegionType.Country ? true : (bool?)null;
|
||||
}
|
||||
// Common properties.
|
||||
data.StatusCode = organisation.StatusCode;
|
||||
data.StatusDesc = organisation.StatusDesc;
|
||||
|
||||
// Organisation Logo image url.
|
||||
if (ItemDataMgr.ItemHasActiveImage(organisation.GetItemId(), Sax.ImageType.OrganisationLogo))
|
||||
data.LogoImageUrl = GetOrganisationLogoUrl(organisation.Id, false);
|
||||
}
|
||||
private void PopulateOrganisationResponseItemData(SaxOrganisation organisation, SaxItemAddress address, OrganisationItemData data)
|
||||
{
|
||||
PopulateOrganisationResponseListData(organisation, data as OrganisationListData);
|
||||
data.About = organisation.About;
|
||||
data.Facilities = organisation.Facilities;
|
||||
PopulateOrganisationResponseListData(organisation, data);
|
||||
data.About = StringUtil.OnEmpty(organisation.About, null);
|
||||
data.Facilities = StringUtil.OnEmpty(organisation.Facilities, null);
|
||||
// Contact methods.
|
||||
SaxContactData contactData = new SaxContactData(organisation.ContactData);
|
||||
foreach (Sax.ContactMethod method in contactData.Methods)
|
||||
@@ -82,14 +98,16 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (address != null && !address.IsStatusDeleted)
|
||||
{
|
||||
data.Address = new AjaxResponse_Data.AddressData();
|
||||
data.Address.Id = address.Id.ToString();
|
||||
data.Address.Line1 = address.Line1;
|
||||
data.Address.Line2 = address.Line2;
|
||||
data.Address.Line3 = address.Line3;
|
||||
data.Address.Id = address.Id.ToString(null);
|
||||
data.Address.Line1 = StringUtil.OnEmpty(address.Line1, null);
|
||||
data.Address.Line2 = StringUtil.OnEmpty(address.Line2, null);
|
||||
data.Address.Line3 = StringUtil.OnEmpty(address.Line3, null);
|
||||
data.Address.Town = address.Town;
|
||||
data.Address.Province = address.Province;
|
||||
data.Address.Country = address.Country;
|
||||
data.Address.PostalCode = address.PostalCode;
|
||||
data.Address.RegionIdProvince = SysId.ToString(address.RegionIdProvince, null);
|
||||
data.Address.RegionNameProvince = StringUtil.OnEmpty(address.Province, null);
|
||||
data.Address.RegionIdCountry = SysId.ToString(address.RegionIdCountry, null);
|
||||
data.Address.RegionNameCountry = StringUtil.OnEmpty(address.Country, null);
|
||||
data.Address.PostalCode = StringUtil.OnEmpty(address.PostalCode, null);
|
||||
}
|
||||
// Common properties.
|
||||
data.Notes = organisation.Notes;
|
||||
@@ -136,13 +154,19 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
responseData.Statuses.Add(SacsSystem.GetStatusCode(status), Localiser.GetStatusCaption(status));
|
||||
responseData.DefaultStatusCode = SacsSystem.GetStatusCode(SaxOrganisation.DefaultStatus);
|
||||
|
||||
// Store filter values.
|
||||
SysId filterSportId = model.Filter.OrganisationSportId.ToSysId();
|
||||
SessionData_Admin.Filter.SportId = SysId.IsValid(filterSportId) ? filterSportId : null;
|
||||
SysId filterRegionId = model.Filter.OrganisationRegionId.ToSysId();
|
||||
SessionData_Admin.Filter.RegionId = SysId.IsValid(filterRegionId) ? filterRegionId : null;
|
||||
|
||||
// Item filter.
|
||||
SaxOrganisation.Params prmOrganisation = new SaxOrganisation.Params();
|
||||
prmOrganisation.OrganisationFilter = model.Filter.Organisation;
|
||||
prmOrganisation.OrganisationType = model.FilterOrganisationType;
|
||||
prmOrganisation.OrganisationCategory = model.FilterOrganisationCategory;
|
||||
prmOrganisation.SportIdsIncluded.AddId(model.Filter.OrganisationSportId.ToSysId());
|
||||
prmOrganisation.RegionIdsIncluded.AddId(model.Filter.OrganisationRegionId.ToSysId());
|
||||
prmOrganisation.SportIdsIncluded.AddId(filterSportId);
|
||||
prmOrganisation.RegionIdsIncluded.AddId(filterRegionId);
|
||||
prmOrganisation.StatusCat = model.Filter.OrganisationStatusCategoryCode != null ? model.FilterOrganisationStatusCategory : SaxOrganisation.StatusCat.NotDeleted;
|
||||
prmOrganisation.SortColumns.Add(AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.Name));
|
||||
model.Paging.ItemTotal = (ulong)AccountMgr.GetOrganisationCount(prmOrganisation);
|
||||
@@ -153,10 +177,9 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
ColumnDfn colName = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.Name);
|
||||
ColumnDfn colOrganisationType = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.OrganisationType);
|
||||
ColumnDfn colOrganisationCategory = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.OrganisationCategory);
|
||||
ColumnDfn colPhoneMain = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.PhoneMain);
|
||||
ColumnDfn colPhoneAlt = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.PhoneAlt);
|
||||
ColumnDfn colUserCount = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.User_Count);
|
||||
ColumnDfn colMemberCount = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.Member_Count);
|
||||
ColumnDfn colLogoCount = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.LogoImage_Count);
|
||||
ColumnDfn colSportId = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.SportId);
|
||||
ColumnDfn colSportName = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.Sport_Name);
|
||||
ColumnDfn colRegionId = AccountMgr.GetOrganisationColumnDfn(SaxOrganisation.Column.RegionId);
|
||||
@@ -168,9 +191,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
colName,
|
||||
colOrganisationType,
|
||||
colOrganisationCategory,
|
||||
colPhoneMain,
|
||||
colPhoneAlt,
|
||||
colUserCount, colMemberCount,
|
||||
colUserCount, colMemberCount, colLogoCount,
|
||||
colSportId, colSportName,
|
||||
colRegionId, colRegionName,
|
||||
colStatus
|
||||
@@ -182,22 +203,28 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
while (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
|
||||
{
|
||||
NamedValue.Map values = resultSet.GetRecordValues();
|
||||
SysId organisationId = new SysId(values.GetLong(colId.DataName));
|
||||
OrganisationListData organisationData = new OrganisationListData()
|
||||
{
|
||||
Id = values.GetLong(colId.DataName).ToString(),
|
||||
Id = organisationId.ToString(),
|
||||
Name = values.GetString(colName.DataName),
|
||||
TypeCode = values.GetString(colOrganisationType.DataName),
|
||||
TypeDesc = OrganisationTypeCodes.GetDescForCode(values.GetString(colOrganisationType.DataName)),
|
||||
CategoryCode = values.GetString(colOrganisationCategory.DataName),
|
||||
CategoryDesc = OrganisationCategoryCodes.GetDescForCode(values.GetString(colOrganisationCategory.DataName)),
|
||||
MemberCount = StringUtil.ToLong(values.GetString(colMemberCount.DataName)),
|
||||
SportId = values.GetLong(colSportId.DataName),
|
||||
SportName = values.GetString(colSportName.DataName),
|
||||
RegionIdCountry = values.GetLong(colRegionId.DataName),
|
||||
RegionNameCountry = values.GetString(colRegionName.DataName),
|
||||
SportId = SysId.ToString(new SysId(values.GetLong(colSportId.DataName)), null),
|
||||
SportName = StringUtil.OnEmpty(values.GetString(colSportName.DataName), null),
|
||||
StatusCode = values.GetString(colStatus.DataName),
|
||||
StatusDesc = SacsSystem.GetStatusDescForCode(values.GetString(colStatus.DataName))
|
||||
};
|
||||
// Logo image.
|
||||
if (StringUtil.ToLong(values.GetString(colLogoCount.DataName)) > 0)
|
||||
organisationData.LogoImageUrl = GetOrganisationLogoUrl(organisationId, false);
|
||||
// Primary region.
|
||||
organisationData.RegionPrimary.Id = SysId.ToString(new SysId(values.GetLong(colRegionId.DataName)), null);
|
||||
organisationData.RegionPrimary.Name = StringUtil.OnEmpty(values.GetString(colRegionName.DataName), null);
|
||||
// Add item to list.
|
||||
responseData.Organisations.Add(organisationData);
|
||||
}
|
||||
}
|
||||
@@ -318,8 +345,8 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
organisation.OrganisationCategory = model.OrganisationCategory;
|
||||
if (model.OrganisationSportId != null)
|
||||
organisation.SportIdPrimary = model.OrganisationSportId.ToSysId();
|
||||
if (model.OrganisationRegionIdCountry != null)
|
||||
organisation.RegionIdPrimary = model.OrganisationRegionIdCountry.ToSysId();
|
||||
if (model.OrganisationRegionIdPrimary != null)
|
||||
organisation.RegionIdPrimary = model.OrganisationRegionIdPrimary.ToSysId();
|
||||
if (model.OrganisationAbout != null)
|
||||
organisation.About = model.OrganisationAbout;
|
||||
if (model.OrganisationFacilities != null)
|
||||
@@ -356,7 +383,10 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (model.Address.IsPopulated())
|
||||
{
|
||||
// Organisation regions.
|
||||
SaxRegion.Data regionCountry = Internals.GetRegion(organisation.RegionIdPrimary);
|
||||
SaxRegion.Data regionCountry = Internals.GetRegion(model.Address.RegionIdCountry.ToSysId());
|
||||
if (regionCountry == null)
|
||||
// Default to Organisation's primary region.
|
||||
regionCountry = Internals.GetRegion(organisation.RegionIdPrimary);
|
||||
if (regionCountry != null && regionCountry.RegionType != Sax.RegionType.Country)
|
||||
regionCountry = null;
|
||||
SaxRegion.Data regionProvince = null;
|
||||
@@ -392,11 +422,6 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
organisationAddress.Country = regionCountry.Name;
|
||||
organisationAddress.RegionIdCountry = regionCountry.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (model.Address.Country != null)
|
||||
organisationAddress.Country = model.Address.Country;
|
||||
}
|
||||
organisationAddress.PostalCode = model.Address.PostalCode;
|
||||
organisationAddress.Status = SaxItemAddress.DefaultStatus;
|
||||
|
||||
@@ -420,7 +445,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (organisationAddress != null && !organisationAddress.IsStatusDeleted)
|
||||
{
|
||||
// Address not populated - delete it.
|
||||
if (!ItemDataMgr.DeleteItemAddress(organisationAddress, DbUpdateInfo))
|
||||
|
||||
@@ -0,0 +1,308 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
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.Helpers;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Core.Web.Admin.Models;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
// Controller: Organisation Images - Ajax
|
||||
//=======================================================================
|
||||
partial class OrganisationController
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
private class OrganisationImagesData : OrganisationItemData
|
||||
{
|
||||
}
|
||||
private void PopulateOrganisationResponseImagesData(SaxOrganisation organisation, SaxItemAddress address, OrganisationImagesData data)
|
||||
{
|
||||
PopulateOrganisationResponseItemData(organisation, address, data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Organisation Images ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_OrganisationImages : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_OrganisationImages(SaxModel_Admin model) : base(model) { }
|
||||
// Organisation details.
|
||||
public OrganisationImagesData organisation { get; } = new OrganisationImagesData();
|
||||
// Reference data.
|
||||
public List<String> ImageContentTypes { get; set; }
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("Organisation/Ajax/GetImages")]
|
||||
[Route("Organisation/Ajax/GetItemImages")]
|
||||
public IActionResult Ajax_GetImages(Model_Organisation model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetImages";
|
||||
String messageTitle = Localiser["organisation.caption.organisation"];
|
||||
AjaxResponse_OrganisationImages responseData = new AjaxResponse_OrganisationImages(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Reference data - Image content types.
|
||||
responseData.ImageContentTypes = SaxItemImage.GetValidContentTypes(Sax.DataItemType.Organisation);
|
||||
|
||||
// Identify item.
|
||||
SysId organisationId = model.OrganisationId.ToSysId();
|
||||
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: '" + model.OrganisationId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// Organisation address.
|
||||
SaxItemAddress address = ItemDataMgr.GetFirstItemAddressByItemAndType(organisation.GetItemId());
|
||||
disposableItems.Add(address);
|
||||
|
||||
// Construct response.
|
||||
PopulateOrganisationResponseImagesData(organisation, address, responseData.organisation);
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Account - Upload Contact Image.
|
||||
// Ref. http://www.binaryintellect.net/articles/474dc031-087f-4b81-b994-9ca2adb949d6.aspx
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_UploadOrganisationLogoImage : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_UploadOrganisationLogoImage(SaxModel_Admin model) : base(model) { }
|
||||
// Uploaded image URL.
|
||||
public String ImageUrl { get; set; }
|
||||
// Upload message.
|
||||
public String UploadMsg { get; set; }
|
||||
}
|
||||
// Ajax request.
|
||||
[HttpPost]
|
||||
[Route("Organisation/Ajax/UploadLogo")]
|
||||
[Route("Organisation/Ajax/UploadLogoImage")]
|
||||
public IActionResult UploadOrganisationLogoImage(Model_Organisation model)
|
||||
{
|
||||
String fn = GetType().Name + ".UploadOrganisationLogoImage";
|
||||
AjaxResponse_UploadOrganisationLogoImage responseData = new AjaxResponse_UploadOrganisationLogoImage(model);
|
||||
String messageTitle = Localiser["organisation.caption.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<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
// Retrieve organisation.
|
||||
SysId organisationId = model.OrganisationId.ToSysId();
|
||||
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: '" + model.OrganisationId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// Validate number of images.
|
||||
if (model.OrganisationLogoImage.IsEmpty())
|
||||
{
|
||||
SaLogger.Warn(fn + " No image file supplied for upload");
|
||||
return Json(responseData);
|
||||
}
|
||||
if (model.OrganisationLogoImage.Count != 1)
|
||||
{
|
||||
SaLogger.Warn(fn + " Invalid number of image files uploaded: " + model.OrganisationLogoImage.Count);
|
||||
return Json(responseData.SetControlError("OrganisationLogoImage", Localiser["msg.upload.image.single"]));
|
||||
}
|
||||
IFormFile file = model.OrganisationLogoImage[0];
|
||||
|
||||
// Image properties.
|
||||
byte[] imageData = null;
|
||||
using (MemoryStream fileStream = new MemoryStream())
|
||||
{
|
||||
file.CopyTo(fileStream);
|
||||
imageData = fileStream.ToArray();
|
||||
}
|
||||
|
||||
// Validate the image.
|
||||
ImageUtils.ImageConfig imageConfig = ImageUtils.VerifyImageData(imageData);
|
||||
if (!imageConfig.ValidImage)
|
||||
return Json(responseData.SetControlError("OrganisationLogoImage", Localiser["msg.upload.image.invalid"]));
|
||||
|
||||
// Validate mime type.
|
||||
if (!SaxItemImage.GetValidMimeTypes(Sax.DataItemType.UserAccount).Contains(imageConfig.MimeType))
|
||||
return Json(responseData.SetControlError("OrganisationLogoImage", Localiser["msg.upload.image.invalid.mime"]));
|
||||
|
||||
// Validate content type.
|
||||
if (StringUtil.IsEmpty(file.ContentType) || !SaxItemImage.GetValidContentTypes(Sax.DataItemType.UserAccount).ContainsCI(file.ContentType))
|
||||
return Json(responseData.SetControlError("OrganisationLogoImage", Localiser["msg.upload.image.invalid.content.type"]));
|
||||
|
||||
// Resize the image if required.
|
||||
if (!ImageUtils.ConstrainImage(imageConfig, Sax.Config.Organisation.Logo.WidthMax, Sax.Config.Organisation.Logo.HeightMax))
|
||||
return Json(responseData.SetControlError("OrganisationLogoImage", Localiser["msg.upload.image.resize.failed"]));
|
||||
|
||||
// Image belongs to the organisation.
|
||||
ItemId organisationItemId = organisation.GetItemId();
|
||||
|
||||
// Store uploaded image as 'Upload' Logo - awaiting confirmation that the details are to be saved.
|
||||
SaxItemImage itemImage = ItemDataMgr.GetItemImage(organisationItemId, Sax.ImageType.OrganisationLogo_Upload, SaxItemImage.StatusCat.Any);
|
||||
if (itemImage == null)
|
||||
itemImage = ItemDataMgr.CreateItemImage(organisationItemId, Sax.ImageType.OrganisationLogo_Upload);
|
||||
itemImage.Filename = file.FileName;
|
||||
itemImage.Mime = SacsContentTypeHelper.GetMimeTypeFromContentType(file.ContentType).ToString().ToLower();
|
||||
itemImage.ContentType = file.ContentType;
|
||||
itemImage.ImageData = imageConfig.ImageData;
|
||||
itemImage.Width = imageConfig.Width;
|
||||
itemImage.Height = imageConfig.Height;
|
||||
itemImage.Status = SaxItemImage.DefaultStatus;
|
||||
|
||||
if (!SysId.IsValid(itemImage.Id))
|
||||
{
|
||||
if (!ItemDataMgr.InsertItemImage(itemImage, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to insert uploaded image - " + ItemDataMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetControlError("OrganisationLogoImage", Localiser["msg.error.item.insert.failed"]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ItemDataMgr.UpdateItemImage(itemImage, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to update uploaded image - " + ItemDataMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetControlError("OrganisationLogoImage", Localiser["msg.error.item.insert.failed"]));
|
||||
}
|
||||
}
|
||||
|
||||
// Return image url with response.
|
||||
responseData.ImageUrl = GetOrganisationLogoUrl(organisation.Id, true);
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.SetNotification(messageTitle, "Image uploaded.");
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Store Organisation Images ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("Organisation/Ajax/StoreImages")]
|
||||
public IActionResult Ajax_StoreImages(Model_Organisation model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_StoreImages";
|
||||
String messageTitle = Localiser["organisation.caption.organisation"];
|
||||
AjaxResponse_OrganisationImages responseData = new AjaxResponse_OrganisationImages(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Validate item properties.
|
||||
model.ValidateOrganisationData(responseData);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Retrieve organisation.
|
||||
SysId organisationId = model.OrganisationId.ToSysId();
|
||||
SaxOrganisation organisation = AccountMgr.GetOrganisationById(organisationId);
|
||||
disposableItems.Add(organisation);
|
||||
if (organisation == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve organisation for Id: '" + model.OrganisationId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// Organisation address.
|
||||
SaxItemAddress address = ItemDataMgr.GetFirstItemAddressByItemAndType(organisation.GetItemId());
|
||||
disposableItems.Add(address);
|
||||
|
||||
// Check for uploaded logo image.
|
||||
ItemId organisationItemId = organisation.GetItemId();
|
||||
SaxItemImage itemImageLogoUploaded = ItemDataMgr.GetItemImage(organisationItemId, Sax.ImageType.OrganisationLogo_Upload, SaxItemImage.StatusCat.ActiveOnly);
|
||||
disposableItems.Add(itemImageLogoUploaded);
|
||||
if (itemImageLogoUploaded != null)
|
||||
{
|
||||
// Retrieve current OrganisationLogo image.
|
||||
SaxItemImage itemImageLogo = ItemDataMgr.GetItemImage(organisationItemId, Sax.ImageType.OrganisationLogo, SaxItemImage.StatusCat.Any);
|
||||
if (itemImageLogo == null)
|
||||
itemImageLogo = ItemDataMgr.CreateItemImage(organisationItemId, Sax.ImageType.OrganisationLogo);
|
||||
disposableItems.Add(itemImageLogo);
|
||||
// Copy properties from uploaded image.
|
||||
itemImageLogo.Filename = itemImageLogoUploaded.Filename;
|
||||
itemImageLogo.Mime = itemImageLogoUploaded.Mime;
|
||||
itemImageLogo.ContentType = itemImageLogoUploaded.ContentType;
|
||||
itemImageLogo.Width = itemImageLogoUploaded.Width;
|
||||
itemImageLogo.Height = itemImageLogoUploaded.Height;
|
||||
itemImageLogo.ImageData = itemImageLogoUploaded.ImageData;
|
||||
itemImageLogo.Status = SaxItemImage.DefaultStatus;
|
||||
if (!SysId.IsValid(itemImageLogo.Id))
|
||||
{
|
||||
if (!ItemDataMgr.InsertItemImage(itemImageLogo, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to insert logo image - " + ItemDataMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetControlError("AccountContactImage", Localiser["msg.error.item.insert.failed"]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ItemDataMgr.UpdateItemImage(itemImageLogo, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to update logo image - " + ItemDataMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetControlError("AccountContactImage", Localiser["msg.error.item.update.failed"]));
|
||||
}
|
||||
}
|
||||
// Logically delete the uplaoded image.
|
||||
itemImageLogoUploaded.Status = SaStatus.Deleted;
|
||||
if (!ItemDataMgr.UpdateItemImage(itemImageLogoUploaded, DbUpdateInfo))
|
||||
SaLogger.Warn(fn + " Failed to logically delete uploaded logo image - " + ItemDataMgr.ErrorStateMessage);
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateOrganisationResponseImagesData(organisation, address, responseData.organisation);
|
||||
}
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -32,8 +32,19 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (!ValidUserSession)
|
||||
return RedirectToAction("", "");
|
||||
|
||||
// Paging.
|
||||
// Model.
|
||||
Model_Organisation model = new Model_Organisation(Localiser);
|
||||
|
||||
// Stored Sport filter.
|
||||
model.Filter.OrganisationSportId = SessionData_Admin.Filter.SportId?.ToString() ?? null;
|
||||
using (SaxSport filterSport = ReferenceMgr.GetSportById(SessionData_Admin.Filter.SportId))
|
||||
model.Filter.OrganisationSportName = Localiser.GetSportName(SessionData_Admin.Filter.SportId, filterSport?.Name ?? "");
|
||||
// Stored Region filter.
|
||||
model.Filter.OrganisationRegionId = SessionData_Admin.Filter.RegionId?.ToString() ?? null;
|
||||
using (SaxRegion filterRegion = ReferenceMgr.GetRegionById(SessionData_Admin.Filter.RegionId))
|
||||
model.Filter.OrganisationRegionName = Localiser.GetRegionName(SessionData_Admin.Filter.RegionId, filterRegion?.Name ?? "");
|
||||
|
||||
// Paging.
|
||||
model.Paging.PageNo = 1;
|
||||
model.Paging.PageLength = 8;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
// Region data.
|
||||
private class RegionListData : AjaxResponse_Data.ItemData_Base
|
||||
{
|
||||
public String RegionTypeCode { get; set; }
|
||||
public int? RegionType { get; set; } = null;
|
||||
public String RegionTypeDesc { get; set; }
|
||||
public String CountryIso2Code { get; set; }
|
||||
public String Name { get; set; }
|
||||
@@ -29,12 +29,13 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
}
|
||||
private class RegionItemData : RegionListData
|
||||
{
|
||||
public String RegionTypeCode { get; set; }
|
||||
public String RegionIdParent { get; set; }
|
||||
}
|
||||
private void PopulateRegionResponseListData(SaxRegion region, RegionListData data)
|
||||
{
|
||||
data.Id = SysId.ToString(region.Id);
|
||||
data.RegionTypeCode = RegionTypeCodes.GetCodeForType(region.RegionType);
|
||||
data.RegionType = (int)region.RegionType;
|
||||
data.RegionTypeDesc = RegionTypeCodes.GetDescForType(region.RegionType);
|
||||
data.CountryIso2Code = region.CountryIso2Code;
|
||||
data.Name = region.Name;
|
||||
@@ -48,6 +49,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
private void PopulateRegionResponseItemData(SaxRegion region, RegionItemData data)
|
||||
{
|
||||
PopulateRegionResponseListData(region, data);
|
||||
data.RegionTypeCode = RegionTypeCodes.GetCodeForType(region.RegionType);
|
||||
data.RegionIdParent = SysId.ToString(region.RegionIdParent);
|
||||
}
|
||||
|
||||
@@ -121,7 +123,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
RegionListData regionData = new RegionListData()
|
||||
{
|
||||
Id = values.GetString(colId.DataName),
|
||||
RegionTypeCode = RegionTypeCodes.GetCodeForType(regionType),
|
||||
RegionType = (int)regionType,
|
||||
RegionTypeDesc = RegionTypeCodes.GetDescForType(regionType),
|
||||
CountryIso2Code = values.GetString(colIso2Code.DataName),
|
||||
Name = values.GetString(colName.DataName),
|
||||
|
||||
@@ -15,6 +15,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
{
|
||||
@@ -119,6 +120,21 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
ClearSessionData();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Organisation utilities.
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Construct URL to display Organisation logo.
|
||||
/// <para>- Option to allow for 'Upload' image if active.</para>
|
||||
/// </summary>
|
||||
protected String GetOrganisationLogoUrl(SysId organisationId, bool uploadImage)
|
||||
{
|
||||
String imageLink = "Image/Organisation/Logo" + (uploadImage ? "/Upload" : "") + "?";
|
||||
NameValueCollection parameters = new NameValueCollection();
|
||||
parameters.Add(ImageController.ParamName_OrganisationId, SysId.ToString(organisationId));
|
||||
return imageLink + ImageController.ParamName_OrganisationLogoEncrypted + "=" + EncryptSessionParams(parameters);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Keep Logged In.
|
||||
//-------------------------------------------------------------------
|
||||
@@ -187,6 +203,25 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
return keepLoggedInParams;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Parameter encryption, eg. for images.
|
||||
//-------------------------------------------------------------------
|
||||
// Encryption key is the same for all users each time the application is started,
|
||||
// but a different IV value is generated for each session so that the links/parameters cannot be shared.
|
||||
public static String Base64Key_AdminApp { get; } = SacsEncryptionHelper.EncodePlainKey("Saxonite&Admin#Encryption-"+DateTime.Today.Format("ddMMyy"), SacsEncryptionHelper.KeyLength);
|
||||
protected String EncryptSessionParams(NameValueCollection parameters)
|
||||
{
|
||||
return HttpUtility.UrlEncode(EncryptParameters(parameters, SessionData_Admin.Base64IV_AdminApp, Base64Key_AdminApp));
|
||||
}
|
||||
public static String EncryptSessionParams(SaxController_Admin controller, NameValueCollection parameters)
|
||||
{
|
||||
return controller.EncryptSessionParams(parameters);
|
||||
}
|
||||
protected NameValueCollection ExtractSessionParams(String encryptedParams)
|
||||
{
|
||||
return DecryptParameters(encryptedParams, SessionData_Admin.Base64IV_AdminApp, Base64Key_AdminApp);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
@@ -161,6 +161,12 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
foreach (SaStatus status in SaxUserAccount.ValidStatuses.FindAll(item => item != SaStatus.Deleted))
|
||||
responseData.Statuses.Add(SacsSystem.GetStatusCode(status), Localiser.GetStatusCaption(status));
|
||||
|
||||
// Store filter values.
|
||||
SysId filterSportId = model.Filter.UserSportId.ToSysId();
|
||||
SessionData_Admin.Filter.SportId = SysId.IsValid(filterSportId) ? filterSportId : null;
|
||||
SysId filterRegionId = model.Filter.UserRegionId.ToSysId();
|
||||
SessionData_Admin.Filter.RegionId = SysId.IsValid(filterRegionId) ? filterRegionId : null;
|
||||
|
||||
// Item filter.
|
||||
SaxUserAccount.Params prmUserAccount = new SaxUserAccount.Params();
|
||||
prmUserAccount.UserFilterPartial = model.Filter.User;
|
||||
|
||||
@@ -31,8 +31,19 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (!ValidUserSession)
|
||||
return RedirectToAction("", "");
|
||||
|
||||
// Paging.
|
||||
// Model.
|
||||
Model_User model = new Model_User(Localiser);
|
||||
|
||||
// Stored Sport filter.
|
||||
model.Filter.UserSportId = SessionData_Admin.Filter.SportId?.ToString() ?? null;
|
||||
using (SaxSport filterSport = ReferenceMgr.GetSportById(SessionData_Admin.Filter.SportId))
|
||||
model.Filter.UserSportName = Localiser.GetSportName(SessionData_Admin.Filter.SportId, filterSport?.Name ?? "");
|
||||
// Stored Region filter.
|
||||
model.Filter.UserRegionId = SessionData_Admin.Filter.RegionId?.ToString() ?? null;
|
||||
using (SaxRegion filterRegion = ReferenceMgr.GetRegionById(SessionData_Admin.Filter.RegionId))
|
||||
model.Filter.UserRegionName = Localiser.GetRegionName(SessionData_Admin.Filter.RegionId, filterRegion?.Name ?? "");
|
||||
|
||||
// Paging.
|
||||
model.Paging.PageNo = 1;
|
||||
model.Paging.PageLength = 12;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
public String Town { get; set; }
|
||||
public String Province { get; set; }
|
||||
public String RegionIdProvince { get; set; }
|
||||
public String Country { get; set; }
|
||||
public String RegionIdCountry { get; set; }
|
||||
public String PostalCode { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
@@ -47,14 +47,14 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
/// <summary>Have any address values been supplied by the form.</summary>
|
||||
public bool IsSpecified()
|
||||
{
|
||||
if (Id != null || Line1 != null || Town != null || Province != null || Country != null || PostalCode != null)
|
||||
if (Id != null || Line1 != null || Town != null || Province != null || RegionIdCountry != null || PostalCode != null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
/// <summary>Have any address values been populated on the form.</summary>
|
||||
public bool IsPopulated()
|
||||
{
|
||||
if (SysId.IsValid(Id.ToSysId()) || !StringUtil.IsEmpty(Line1) || !StringUtil.IsEmpty(Town) || !StringUtil.IsEmpty(Province) || !StringUtil.IsEmpty(Country) || !StringUtil.IsEmpty(PostalCode))
|
||||
if (SysId.IsValid(Id.ToSysId()) || !StringUtil.IsEmpty(Line1) || !StringUtil.IsEmpty(Town) || !StringUtil.IsEmpty(Province) || !StringUtil.IsEmpty(RegionIdCountry) || !StringUtil.IsEmpty(PostalCode))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
// Validation.
|
||||
//-------------------------------------------------------------------
|
||||
// Address.
|
||||
public bool ValidateAddressData(SaxController_Base.AjaxResponse_Data responseData)
|
||||
public bool ValidateAddressData(SaxModel_Admin model, SaxController_Base.AjaxResponse_Data responseData)
|
||||
{
|
||||
// Are any properties populated.
|
||||
bool populated = IsPopulated();
|
||||
@@ -101,32 +101,37 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
// Address Town - mandatory if any value populated.
|
||||
if (Town != null)
|
||||
{
|
||||
responseData.SetControlValue(ControlNameSuffix + "Town", Town);
|
||||
String controlName = ControlNameSuffix + nameof(Town);
|
||||
responseData.SetControlValue(controlName, Town);
|
||||
if (StringUtil.IsEmpty(Town) && populated)
|
||||
responseData.SetControlError(ControlNameSuffix + "Town", Model.Localiser["msg.validation.mandatory.value"]);
|
||||
responseData.SetControlError(controlName, 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)]);
|
||||
responseData.SetControlError(controlName, Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Town)]);
|
||||
}
|
||||
|
||||
// Address Province - optional.
|
||||
if (Province != null)
|
||||
{
|
||||
responseData.SetControlValue(ControlNameSuffix + "Province", Province);
|
||||
String controlName = ControlNameSuffix + nameof(Province);
|
||||
responseData.SetControlValue(controlName, 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)]);
|
||||
responseData.SetControlError(controlName, Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Province)]);
|
||||
}
|
||||
}
|
||||
|
||||
// Address Country - optional.
|
||||
if (Country != null)
|
||||
// Address Country - mandatory if any value populated.
|
||||
if (RegionIdCountry != null)
|
||||
{
|
||||
responseData.SetControlValue(ControlNameSuffix + "Country", Country);
|
||||
if (!StringUtil.IsEmpty(Country))
|
||||
String controlName = ControlNameSuffix + nameof(RegionIdCountry);
|
||||
if (!SysId.IsValid(RegionIdCountry.ToSysId()) && populated)
|
||||
responseData.SetControlError(controlName, Model.Localiser["msg.validation.mandatory.value"]);
|
||||
else if (SysId.IsValid(RegionIdCountry.ToSysId()))
|
||||
{
|
||||
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)]);
|
||||
SaxRegion.Data region = model.Internals.GetRegion(RegionIdCountry.ToSysId());
|
||||
if (region == null || region.RegionType != Sax.RegionType.Country)
|
||||
responseData.SetControlError(controlName, Model.Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
@@ -34,7 +35,9 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
public String OrganisationTypeCode { get; set; }
|
||||
public String OrganisationCategoryCode { get; set; }
|
||||
public String OrganisationSportId { get; set; }
|
||||
public String OrganisationSportName { get; set; }
|
||||
public String OrganisationRegionId { get; set; }
|
||||
public String OrganisationRegionName { get; set; }
|
||||
public String OrganisationStatusCategoryCode { get; set; }
|
||||
}
|
||||
public FilterData Filter { get; } = new FilterData();
|
||||
@@ -75,7 +78,7 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
public String OrganisationCategoryValue { get; set; }
|
||||
public Sax.OrganisationCategory OrganisationCategory { get { return (Sax.OrganisationCategory)OrganisationCategoryCodes.GetTypeForCode(OrganisationCategoryValue); } }
|
||||
public String OrganisationSportId { get; set; }
|
||||
public String OrganisationRegionIdCountry { get; set; }
|
||||
public String OrganisationRegionIdPrimary { get; set; }
|
||||
public String OrganisationAbout { get; set; }
|
||||
public String OrganisationFacilities { get; set; }
|
||||
// Common properties.
|
||||
@@ -92,6 +95,11 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
// Address.
|
||||
public ModelData_Address Address { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Images.
|
||||
public List<IFormFile> OrganisationLogoImage { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
public bool IsSportMandatory()
|
||||
{
|
||||
@@ -143,15 +151,15 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
}
|
||||
}
|
||||
|
||||
// Organisation region.
|
||||
if (OrganisationRegionIdCountry != null)
|
||||
// Organisation primary region.
|
||||
if (OrganisationRegionIdPrimary != null)
|
||||
{
|
||||
using (SaxRegion region = ReferenceMgr.GetRegionById(OrganisationRegionIdCountry.ToSysId()))
|
||||
using (SaxRegion region = ReferenceMgr.GetRegionById(OrganisationRegionIdPrimary.ToSysId()))
|
||||
{
|
||||
if (region == null)
|
||||
responseData.SetControlError(nameof(OrganisationRegionIdCountry), Localiser["msg.validation.invalid.value"]);
|
||||
responseData.SetControlError(nameof(OrganisationRegionIdPrimary), Localiser["msg.validation.invalid.value"]);
|
||||
else if (region.RegionType != Sax.RegionType.Country && region.RegionType != Sax.RegionType.Continent && region.RegionType != Sax.RegionType.World)
|
||||
responseData.SetControlError(nameof(OrganisationRegionIdCountry), "Organisation region must be a country or international region");
|
||||
responseData.SetControlError(nameof(OrganisationRegionIdPrimary), "Organisation region must be a country or international region");
|
||||
}
|
||||
|
||||
if (!StringUtil.IsEmpty(OrganisationName))
|
||||
@@ -161,7 +169,7 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
if (SysId.IsValid(OrganisationId.ToSysId()))
|
||||
prmOrganisation.IdsExcluded.Add(OrganisationId.ToSysId());
|
||||
prmOrganisation.NameFull = OrganisationName;
|
||||
prmOrganisation.RegionIdsIncluded.Add(OrganisationRegionIdCountry.ToSysId());
|
||||
prmOrganisation.RegionIdsIncluded.Add(OrganisationRegionIdPrimary.ToSysId());
|
||||
prmOrganisation.StatusCat = SaxOrganisation.StatusCat.Any;
|
||||
if (AccountMgr.GetOrganisationCount(prmOrganisation) > 0)
|
||||
responseData.SetControlError(nameof(OrganisationName), Localiser["msg.validation.duplicate.value"]);
|
||||
@@ -226,7 +234,7 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
|
||||
// Validate address fields.
|
||||
if (Address != null)
|
||||
Address.ValidateAddressData(responseData);
|
||||
Address.ValidateAddressData(this, responseData);
|
||||
|
||||
return !responseData.HasControlErrors();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,9 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
{
|
||||
public String User { get; set; }
|
||||
public String UserSportId { get; set; }
|
||||
public String UserSportName { get; set; }
|
||||
public String UserRegionId { get; set; }
|
||||
public String UserRegionName { get; set; }
|
||||
public String UserStatusCategoryCode { get; set; }
|
||||
}
|
||||
public FilterData Filter { get; } = new FilterData();
|
||||
|
||||
Reference in New Issue
Block a user