v1.2.4.1
This commit is contained in:
@@ -41,7 +41,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
}
|
||||
private void PopulateProfileSportResponseData(Model_Account model, SaxUserSport userSport, SaxSport sport, ProfileSportResponseData_Item data)
|
||||
{
|
||||
data.Id = SysId.ToString(userSport.Id);
|
||||
data.Id = model.EncryptId(userSport.Id);
|
||||
data.SportId = model.GetEncryptedSportId(userSport.SportId);
|
||||
data.SportName = sport.Name;
|
||||
data.SportSpecialityLabel = model.GetSportSpecialityLabel(userSport.SportId);
|
||||
@@ -113,7 +113,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
SysId sportId = new SysId(values.GetLong(colSportId.DataName));
|
||||
ProfileSportResponseData_List userSportData = new ProfileSportResponseData_List()
|
||||
{
|
||||
Id = values.GetLong(colId.DataName).ToString(),
|
||||
Id = model.EncryptId(new SysId(values.GetLong(colId.DataName))),
|
||||
SportId = model.GetEncryptedSportId(sportId),
|
||||
SportName = values.GetString(colSportName.DataName),
|
||||
SportSpecialityLabel = model.GetSportSpecialityLabel(sportId),
|
||||
@@ -158,30 +158,37 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Identify item.
|
||||
SysId userSportId = model.ExtractSysId(model.UserSportId);
|
||||
if (!SysId.IsValid(userSportId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
// Retrieve item.
|
||||
SaxUserSport userSport = AccountMgr.GetUserSportById(userSportId);
|
||||
if (userSport == null)
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve User Sport for Id: '" + model.UserSportId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// Retrieve sport.
|
||||
SaxSport sport = ReferenceMgr.GetSportById(userSport.SportId);
|
||||
if (sport == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve Sport for Id: '" + userSport.SportId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
// Identify item.
|
||||
SysId userSportId = model.ExtractSysId(model.UserSportId);
|
||||
if (!SysId.IsValid(userSportId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
// Construct response.
|
||||
PopulateProfileSportResponseData(model, userSport, sport, responseData.Sport);
|
||||
responseData.Success = true;
|
||||
// Retrieve item.
|
||||
SaxUserSport userSport = AccountMgr.GetUserSportById(userSportId);
|
||||
disposableItems.Add(userSport);
|
||||
if (userSport == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve User Sport for Id: '" + model.UserSportId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// Retrieve sport.
|
||||
SaxSport sport = ReferenceMgr.GetSportById(userSport.SportId);
|
||||
disposableItems.Add(sport);
|
||||
if (sport == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve Sport for Id: '" + userSport.SportId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateProfileSportResponseData(model, userSport, sport, responseData.Sport);
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
@@ -201,108 +208,119 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Validate item properties.
|
||||
model.ValidateProfileSportData(responseData);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Validate Profile Sport Id against 'Exists' flag.
|
||||
SysId userSportId = model.ExtractSysId(model.UserSportId);
|
||||
bool profileSportExists = StringUtil.ToBool(model.ProfileSportExists);
|
||||
if (profileSportExists && !SysId.IsValid(userSportId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id not specified for existing Profile Sport.");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!profileSportExists && SysId.IsValid(userSportId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id specified for new Profile Sport: '" + model.UserSportId + "'");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
// Validate item properties.
|
||||
model.ValidateProfileSportData(responseData);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Retrieve the sport.
|
||||
SysId sportId = model.ExtractSysId(model.ProfileSportId);
|
||||
SaxSport sport = ReferenceMgr.GetSportById(sportId);
|
||||
if (sport == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve Sport for Id: " + sportId);
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Retrieve existing item.
|
||||
SaxUserSport userSport = AccountMgr.GetUserSportById(userSportId);
|
||||
if (userSport == null && SysId.IsValid(userSportId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve User Sport for Id: '" + model.UserSportId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
// Validate user sport properties.
|
||||
if (userSport != null)
|
||||
{
|
||||
if (!userSport.SportId.Equals(sportId))
|
||||
// Validate Profile Sport Id against 'Exists' flag.
|
||||
SysId userSportId = model.ExtractSysId(model.UserSportId);
|
||||
bool profileSportExists = StringUtil.ToBool(model.ProfileSportExists);
|
||||
if (profileSportExists && !SysId.IsValid(userSportId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Inconsistent Sport Id specified for User Sport. Expected: " + userSport.SportId + ". Found: " + sportId);
|
||||
SaLogger.Warn(fn + " Id not specified for existing Profile Sport.");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!profileSportExists && SysId.IsValid(userSportId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id specified for new Profile Sport: '" + model.UserSportId + "'");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
}
|
||||
|
||||
// If sport doesn't exist for the user, it may have been previously deleted.
|
||||
if (userSport == null)
|
||||
{
|
||||
SaxUserSport.Params prmUserSport = new SaxUserSport.Params();
|
||||
prmUserSport.UserAccountIdsIncluded.Add(UserAccountId);
|
||||
prmUserSport.SportIdsIncluded.Add(sportId);
|
||||
prmUserSport.StatusCat = SaxUserSport.StatusCat.Any;
|
||||
userSport = AccountMgr.GetUserSport(prmUserSport);
|
||||
// Retrieve the sport.
|
||||
SysId sportId = model.ExtractSysId(model.ProfileSportId);
|
||||
SaxSport sport = ReferenceMgr.GetSportById(sportId);
|
||||
disposableItems.Add(sport);
|
||||
if (sport == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve Sport for Id: " + sportId);
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Retrieve existing item.
|
||||
SaxUserSport userSport = AccountMgr.GetUserSportById(userSportId);
|
||||
disposableItems.Add(userSport);
|
||||
if (userSport == null && SysId.IsValid(userSportId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve User Sport for Id: '" + model.UserSportId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
// Validate user sport properties.
|
||||
if (userSport != null)
|
||||
{
|
||||
if (userSport.Status == SaStatus.Deleted)
|
||||
if (!userSport.SportId.Equals(sportId))
|
||||
{
|
||||
SaLogger.Info(fn + " Resurrecting User Sport with status: " + userSport.StatusDesc + ". Id: " + SysId.ToString(userSport.Id));
|
||||
userSport.Status = SaxUserSport.DefaultStatus;
|
||||
SaLogger.Warn(fn + " Inconsistent Sport Id specified for User Sport. Expected: " + userSport.SportId + ". Found: " + sportId);
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
}
|
||||
|
||||
// If sport doesn't exist for the user, it may have been previously deleted.
|
||||
if (userSport == null)
|
||||
{
|
||||
SaxUserSport.Params prmUserSport = new SaxUserSport.Params();
|
||||
prmUserSport.UserAccountIdsIncluded.Add(UserAccountId);
|
||||
prmUserSport.SportIdsIncluded.Add(sportId);
|
||||
prmUserSport.StatusCat = SaxUserSport.StatusCat.Any;
|
||||
userSport = AccountMgr.GetUserSport(prmUserSport);
|
||||
if (userSport != null)
|
||||
{
|
||||
disposableItems.Add(userSport);
|
||||
if (userSport.Status == SaStatus.Deleted)
|
||||
{
|
||||
SaLogger.Info(fn + " Resurrecting User Sport with status: " + userSport.StatusDesc + ". Id: " + SysId.ToString(userSport.Id));
|
||||
userSport.Status = SaxUserSport.DefaultStatus;
|
||||
}
|
||||
else
|
||||
{
|
||||
responseData.SetControlError(nameof(model.ProfileSportId), Localiser["msg.validation.duplicate.value"]);
|
||||
return Json(responseData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
responseData.SetControlError(nameof(model.ProfileSportId), Localiser["msg.validation.duplicate.value"]);
|
||||
return Json(responseData);
|
||||
userSport = AccountMgr.CreateUserSport(UserAccountId, sportId);
|
||||
disposableItems.Add(userSport);
|
||||
}
|
||||
}
|
||||
|
||||
// Populate item properties.
|
||||
if (model.ProfileSportAbout != null)
|
||||
userSport.About = model.ProfileSportAbout;
|
||||
if (model.ProfileSportParticipationCode != null)
|
||||
userSport.Participation = model.ProfileSportParticipation;
|
||||
if (model.ProfileSportOfficiatingCode != null)
|
||||
userSport.Officiating = model.ProfileSportOfficiating;
|
||||
|
||||
// Store item.
|
||||
if (!SysId.IsValid(userSport.Id))
|
||||
{
|
||||
if (!AccountMgr.InsertUserSport(userSport, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to insert user sport: " + AccountMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.insert.failed"]));
|
||||
}
|
||||
}
|
||||
else
|
||||
userSport = AccountMgr.CreateUserSport(UserAccountId, sportId);
|
||||
}
|
||||
|
||||
// Populate item properties.
|
||||
if (model.ProfileSportAbout != null)
|
||||
userSport.About = model.ProfileSportAbout;
|
||||
if (model.ProfileSportParticipationCode != null)
|
||||
userSport.Participation = model.ProfileSportParticipation;
|
||||
if (model.ProfileSportOfficiatingCode != null)
|
||||
userSport.Officiating = model.ProfileSportOfficiating;
|
||||
|
||||
// Store item.
|
||||
if (!SysId.IsValid(userSport.Id))
|
||||
{
|
||||
if (!AccountMgr.InsertUserSport(userSport, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to insert user sport: " + AccountMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.insert.failed"]));
|
||||
if (!AccountMgr.UpdateUserSport(userSport, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to update user sport [Id:" + SysId.ToString(userSport.Id) + "]: " + AccountMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.update.failed"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!AccountMgr.UpdateUserSport(userSport, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to update user sport [Id:" + SysId.ToString(userSport.Id) + "]: " + AccountMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.update.failed"]));
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh list of profile sports for Activity Index.
|
||||
RefreshSessionProfileSports();
|
||||
// Refresh list of profile sports for Activity Index.
|
||||
RefreshSessionProfileSports();
|
||||
|
||||
// Construct response.
|
||||
PopulateProfileSportResponseData(model, userSport, sport, responseData.Sport);
|
||||
responseData.Success = true;
|
||||
// Construct response.
|
||||
PopulateProfileSportResponseData(model, userSport, sport, responseData.Sport);
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -29,9 +29,8 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Common response data.
|
||||
private class SportExperienceResponseData_List
|
||||
private class SportExperienceResponseData_List : AjaxResponse_Data.ItemData_Base
|
||||
{
|
||||
public String Id { get; set; }
|
||||
public String UserSportId { get; set; }
|
||||
public String Period { get; set; }
|
||||
public String PeriodFrom { get; set; }
|
||||
|
||||
@@ -182,8 +182,18 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
indexContext.EffectiveTo = DateTime.Today;
|
||||
|
||||
// Sport and region combinations.
|
||||
List<SysId> sportIds = new List<SysId>();
|
||||
foreach (SysId sportId in sessionData.Profile.Sports.Select(item => item.SportId))
|
||||
{
|
||||
if (sportIds.Contains(sportId)) continue;
|
||||
sportIds.AddId(sportId);
|
||||
// Include child sports.
|
||||
sportIds.AddIds(model.GetChildSports_Active(sportId).Select(item => item.Id));
|
||||
model.GetSportCaption(sportId);
|
||||
}
|
||||
foreach (SysId sportId in sportIds)
|
||||
{
|
||||
// Regions.
|
||||
if (SysId.IsValid(sessionData.User.RegionIdProvince))
|
||||
indexContext.SportRegionIdsIncluded.Add(new SaxActivityIndex.SportRegionIds(sportId, sessionData.User.RegionIdProvince));
|
||||
else if (SysId.IsValid(sessionData.User.RegionIdCountry))
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
private class ArticleData_List : AjaxResponse_Data.ItemData_Base
|
||||
{
|
||||
public String OrganisationId { get; set; }
|
||||
public String OrganisationName { get; set; }
|
||||
public String Headline { get; set; }
|
||||
public String Summary { get; set; }
|
||||
public String RegionCaptionPrimary { get; set; }
|
||||
@@ -69,7 +70,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
public String PublishedOn_Calendar { get; set; }
|
||||
public ArticleContentData Content { get; } = new ArticleContentData();
|
||||
}
|
||||
private void PopulateArticleResponseData(Model_Article model, SaxArticle article, ArticleData_List data)
|
||||
private void PopulateArticleResponseData(Model_Article model, SaxArticle article, SaxOrganisation organisation, ArticleData_List data)
|
||||
{
|
||||
data.Id = model.EncryptId(article.Id);
|
||||
data.OrganisationId = SysId.ToString(article.OrganisationId);
|
||||
@@ -82,9 +83,9 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
data.StatusCode = article.StatusCode;
|
||||
data.StatusDesc = article.StatusDesc;
|
||||
}
|
||||
private void PopulateArticleResponseData(Model_Article model, SaxArticle article, ArticleData_Full data)
|
||||
private void PopulateArticleResponseData(Model_Article model, SaxArticle article, SaxOrganisation organisation, ArticleData_Full data)
|
||||
{
|
||||
PopulateArticleResponseData(model, article, data as ArticleData_List);
|
||||
PopulateArticleResponseData(model, article, organisation, data as ArticleData_List);
|
||||
data.RegionIdPrimary = model.GetEncryptedRegionId(article.RegionIdPrimary);
|
||||
data.SportIdPrimary = model.GetEncryptedSportId(article.SportIdPrimary);
|
||||
data.Published = DateUtil.IsValid(article.PublishedAt) ? true : (bool?)null;
|
||||
@@ -207,6 +208,8 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
prmArticle.UserAccountIdsAuthorIncluded.Add(sessionData.User.UserAccountId);
|
||||
if (SysId.IsValid(organisationIdFilter))
|
||||
prmArticle.OrganisationIdsIncluded.Add(organisationIdFilter);
|
||||
else
|
||||
prmArticle.ExcludeOrganisationArticles = true;
|
||||
prmArticle.ArticleFilter = model.Filter.Article;
|
||||
prmArticle.StatusCat = SaxArticle.StatusCat.NotDeleted;
|
||||
model.Paging.ItemTotal = (ulong)ActivityMgr.GetArticleCount(prmArticle);
|
||||
@@ -215,6 +218,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
// Item columns.
|
||||
ColumnDfn colId = ActivityMgr.GetArticleColumnDfn(SaxArticle.Column.Id);
|
||||
ColumnDfn colOrganisationId = ActivityMgr.GetArticleColumnDfn(SaxArticle.Column.OrganisationId);
|
||||
ColumnDfn colOrganisationName = ActivityMgr.GetArticleColumnDfn(SaxArticle.Column.Organisation_Name);
|
||||
ColumnDfn colHeadline = ActivityMgr.GetArticleColumnDfn(SaxArticle.Column.Headline);
|
||||
ColumnDfn colSummary = ActivityMgr.GetArticleColumnDfn(SaxArticle.Column.Summary);
|
||||
ColumnDfn colRegionIdPrimary = ActivityMgr.GetArticleColumnDfn(SaxArticle.Column.RegionIdPrimary);
|
||||
@@ -224,7 +228,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
ColumnDfn colCreatedOn = ActivityMgr.GetArticleColumnDfn(SaxArticle.Column.CreateOn_Date);
|
||||
List<ColumnDfn> columns = new List<ColumnDfn>()
|
||||
{
|
||||
colId, colOrganisationId, colHeadline, colSummary,
|
||||
colId, colOrganisationId, colOrganisationName, colHeadline, colSummary,
|
||||
colRegionIdPrimary, colSportIdPrimary, colPublishedOn,
|
||||
colStatus, colCreatedOn
|
||||
};
|
||||
@@ -243,6 +247,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
{
|
||||
Id = model.EncryptId(new SysId(values.GetLong(colId.DataName))),
|
||||
OrganisationId = model.EncryptId(new SysId(values.GetLong(colOrganisationId.DataName))),
|
||||
OrganisationName = values.GetString(colOrganisationName.DataName),
|
||||
Headline = values.GetString(colHeadline.DataName),
|
||||
Summary = values.GetString(colSummary.DataName),
|
||||
RegionCaptionPrimary = model.GetRegionCaption(values.GetString(colRegionIdPrimary.DataName).ToSysId()),
|
||||
@@ -315,6 +320,10 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Organisation.
|
||||
SaxOrganisation organisation = AccountMgr.GetOrganisationById(article.OrganisationId);
|
||||
disposableItems.Add(organisation);
|
||||
|
||||
// Delete upload images.
|
||||
SaxItemImage.Params prmItemImage = new SaxItemImage.Params();
|
||||
prmItemImage.ItemIdsIncluded.Add(new ItemId((short)Sax.DataItemType.Article, articleId));
|
||||
@@ -330,7 +339,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateArticleResponseData(model, article, responseData.Article);
|
||||
PopulateArticleResponseData(model, article, organisation, responseData.Article);
|
||||
}
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
@@ -484,188 +493,202 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
SaxSessionData_Online sessionData = SessionData_Online;
|
||||
RefreshModel(model);
|
||||
|
||||
// Validate item properties.
|
||||
model.ValidateArticleData(responseData);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Validate User & Organisation.
|
||||
SysId userAccountId = UserAccountId;
|
||||
SysId organisationId = model.ExtractSysId(model.ArticleOrganisationId);
|
||||
if (SysId.IsValid(organisationId))
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
// Organisation specified - User must have Article Admin role.
|
||||
if (!AccountMgr.UserHasAnyOrganisationRole(userAccountId, organisationId, new[] { Sax.OrganisationRole.Admin, Sax.OrganisationRole.ArticleAdmin }))
|
||||
|
||||
// Validate item properties.
|
||||
model.ValidateArticleData(responseData);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Validate User & Organisation.
|
||||
SysId userAccountId = UserAccountId;
|
||||
SysId organisationId = model.ExtractSysId(model.ArticleOrganisationId);
|
||||
if (SysId.IsValid(organisationId))
|
||||
{
|
||||
SaLogger.Warn(fn + " User does not have Article Admin role for organisation." + GetLogSuffix());
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Organisation not specified - User must be a Journalist.
|
||||
if (!UserIsJournalist)
|
||||
{
|
||||
SaLogger.Warn(fn + " User is not a Journalist for non-organisation article." + GetLogSuffix());
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
}
|
||||
|
||||
// Validate item Id against 'Exists' flag.
|
||||
SysId articleId = model.ExtractSysId(model.ArticleId);
|
||||
bool articleExists = StringUtil.ToBool(model.ArticleExists);
|
||||
if (articleExists && !SysId.IsValid(articleId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id not specified for existing Article.");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!articleExists && SysId.IsValid(articleId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id specified for new Article: '" + model.ArticleId + "'");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Retrieve existing item.
|
||||
SaxArticle article = ActivityMgr.GetArticleById(articleId);
|
||||
if (article == null && SysId.IsValid(articleId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve article for Id: '" + model.ArticleId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
if (article != null)
|
||||
{
|
||||
// Validate existing article.
|
||||
if (SysId.ToLong(article.UserAccountIdAuthor) != SysId.ToLong(userAccountId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Inconsistent Article Author." + GetLogSuffix());
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (SysId.ToLong(article.OrganisationId) != SysId.ToLong(organisationId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Inconsistent Article Organisation." + GetLogSuffix());
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
}
|
||||
|
||||
// Create new item if required.
|
||||
if (article == null)
|
||||
article = ActivityMgr.CreateArticle(sessionData.User.UserAccountId, organisationId);
|
||||
|
||||
// Populate item properties.
|
||||
if (model.ArticleRegionId != null)
|
||||
article.RegionIdPrimary = model.ExtractSysId(model.ArticleRegionId);
|
||||
if (model.ArticleSportId != null)
|
||||
article.SportIdPrimary = model.ExtractSysId(model.ArticleSportId);
|
||||
if (model.ArticleHeadline != null)
|
||||
article.Headline = model.ArticleHeadline;
|
||||
if (model.ArticleSummary != null)
|
||||
article.Summary = model.ArticleSummary;
|
||||
if (!model.ArticlePublished.ToBool())
|
||||
{
|
||||
if (model.ArticlePublish)
|
||||
article.PublishedAt = model.GetArticlePublishOn();
|
||||
else
|
||||
article.PublishedAt = DateTime.MinValue;
|
||||
}
|
||||
if (model.ArticleStatusCode != null)
|
||||
article.Status = model.ArticleStatus;
|
||||
|
||||
// Retrieve all article images - before new article is created as uploaded images are assigned to user first.
|
||||
SaxItemImage.Params prmItemImage = new SaxItemImage.Params();
|
||||
if (SysId.IsValid(article.Id))
|
||||
prmItemImage.ItemIdsIncluded.Add(article.GetItemId());
|
||||
else
|
||||
prmItemImage.ItemIdsIncluded.Add(new ItemId((short)Sax.DataItemType.UserAccount, sessionData.User.UserAccountId));
|
||||
prmItemImage.ImageTypesIncluded.Add(Sax.ImageType.Article);
|
||||
prmItemImage.ImageTypesIncluded.Add(Sax.ImageType.ArticleUpload);
|
||||
prmItemImage.StatusCat = SaxItemImage.StatusCat.NotDeleted;
|
||||
List<SaxItemImage> itemImages = ItemDataMgr.GetItemImageList(prmItemImage);
|
||||
|
||||
// If Article doesn't yet exist, create it now so that images can be assigned.
|
||||
bool articleCreated = false;
|
||||
if (!SysId.IsValid(article.Id))
|
||||
{
|
||||
if (!ActivityMgr.InsertArticle(article, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to insert article: " + ActivityMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.insert.failed"]));
|
||||
}
|
||||
articleCreated = true;
|
||||
}
|
||||
|
||||
// Content.
|
||||
if (model.ArticleContentSegmentBodies != null)
|
||||
{
|
||||
SaxArticle.ContentData articleContent = new SaxArticle.ContentData();
|
||||
for (int segmentIdx = 0; segmentIdx < model.ArticleContentSegmentBodies.Count; segmentIdx++)
|
||||
{
|
||||
String segmentBody = model.ArticleContentSegmentBodies[segmentIdx];
|
||||
String segmentItemImageId = model.ArticleContentSegmentItemImageIds.Count > segmentIdx ? model.ArticleContentSegmentItemImageIds[segmentIdx] : "";
|
||||
String segmentImageIdx = model.ArticleContentSegmentImageIdxs.Count > segmentIdx ? model.ArticleContentSegmentImageIdxs[segmentIdx] : "";
|
||||
if (!StringUtil.IsEmpty(segmentBody))
|
||||
// Organisation specified - User must have Article Admin role.
|
||||
if (!AccountMgr.UserHasAnyOrganisationRole(userAccountId, organisationId, new[] { Sax.OrganisationRole.Admin, Sax.OrganisationRole.ArticleAdmin }))
|
||||
{
|
||||
// HTML Body segment.
|
||||
var segment = articleContent.AddSegment();
|
||||
segment.Body.Html = segmentBody;
|
||||
SaLogger.Warn(fn + " User does not have Article Admin role for organisation." + GetLogSuffix());
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
else if (!StringUtil.IsEmpty(segmentItemImageId) || !StringUtil.IsEmpty(segmentImageIdx))
|
||||
}
|
||||
else
|
||||
{
|
||||
// Organisation not specified - User must be a Journalist.
|
||||
if (!UserIsJournalist)
|
||||
{
|
||||
SysId itemImageId = model.ExtractSysId(segmentItemImageId);
|
||||
int imageIdx = StringUtil.ToInt(segmentImageIdx);
|
||||
SaLogger.Warn(fn + " User is not a Journalist for non-organisation article." + GetLogSuffix());
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
}
|
||||
|
||||
// Check for new image first.
|
||||
SaxItemImage itemImage = itemImages.GetItemImageBySessionImage(sessionData.SessionIdx, imageIdx);
|
||||
if (itemImage == null)
|
||||
itemImage = itemImages.GetItemImageById(itemImageId);
|
||||
if (itemImage != null)
|
||||
// Validate item Id against 'Exists' flag.
|
||||
SysId articleId = model.ExtractSysId(model.ArticleId);
|
||||
bool articleExists = StringUtil.ToBool(model.ArticleExists);
|
||||
if (articleExists && !SysId.IsValid(articleId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id not specified for existing Article.");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (!articleExists && SysId.IsValid(articleId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Id specified for new Article: '" + model.ArticleId + "'");
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
|
||||
// Retrieve existing item.
|
||||
SaxArticle article = ActivityMgr.GetArticleById(articleId);
|
||||
disposableItems.Add(article);
|
||||
if (article == null && SysId.IsValid(articleId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve article for Id: '" + model.ArticleId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
if (article != null)
|
||||
{
|
||||
// Validate existing article.
|
||||
if (SysId.ToLong(article.UserAccountIdAuthor) != SysId.ToLong(userAccountId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Inconsistent Article Author." + GetLogSuffix());
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
if (SysId.ToLong(article.OrganisationId) != SysId.ToLong(organisationId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Inconsistent Article Organisation." + GetLogSuffix());
|
||||
return Json(responseData.SetGoHome(messageTitle, Localiser["msg.error.system"]));
|
||||
}
|
||||
}
|
||||
|
||||
// Organisation.
|
||||
SaxOrganisation organisation = AccountMgr.GetOrganisationById(article.OrganisationId);
|
||||
disposableItems.Add(organisation);
|
||||
|
||||
// Create new item if required.
|
||||
if (article == null)
|
||||
{
|
||||
article = ActivityMgr.CreateArticle(sessionData.User.UserAccountId, organisationId);
|
||||
disposableItems.Add(article);
|
||||
}
|
||||
|
||||
// Populate item properties.
|
||||
if (model.ArticleRegionId != null)
|
||||
article.RegionIdPrimary = model.ExtractSysId(model.ArticleRegionId);
|
||||
if (model.ArticleSportId != null)
|
||||
article.SportIdPrimary = model.ExtractSysId(model.ArticleSportId);
|
||||
if (model.ArticleHeadline != null)
|
||||
article.Headline = model.ArticleHeadline;
|
||||
if (model.ArticleSummary != null)
|
||||
article.Summary = model.ArticleSummary;
|
||||
if (!model.ArticlePublished.ToBool())
|
||||
{
|
||||
if (model.ArticlePublish)
|
||||
article.PublishedAt = model.GetArticlePublishOn();
|
||||
else
|
||||
article.PublishedAt = DateTime.MinValue;
|
||||
}
|
||||
if (model.ArticleStatusCode != null)
|
||||
article.Status = model.ArticleStatus;
|
||||
|
||||
// Retrieve all article images - before new article is created as uploaded images are assigned to user first.
|
||||
SaxItemImage.Params prmItemImage = new SaxItemImage.Params();
|
||||
if (SysId.IsValid(article.Id))
|
||||
prmItemImage.ItemIdsIncluded.Add(article.GetItemId());
|
||||
else
|
||||
prmItemImage.ItemIdsIncluded.Add(new ItemId((short)Sax.DataItemType.UserAccount, sessionData.User.UserAccountId));
|
||||
prmItemImage.ImageTypesIncluded.Add(Sax.ImageType.Article);
|
||||
prmItemImage.ImageTypesIncluded.Add(Sax.ImageType.ArticleUpload);
|
||||
prmItemImage.StatusCat = SaxItemImage.StatusCat.NotDeleted;
|
||||
List<SaxItemImage> itemImages = ItemDataMgr.GetItemImageList(prmItemImage);
|
||||
disposableItems.AddRange(itemImages);
|
||||
|
||||
// If Article doesn't yet exist, create it now so that images can be assigned.
|
||||
bool articleCreated = false;
|
||||
if (!SysId.IsValid(article.Id))
|
||||
{
|
||||
if (!ActivityMgr.InsertArticle(article, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to insert article: " + ActivityMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.insert.failed"]));
|
||||
}
|
||||
articleCreated = true;
|
||||
}
|
||||
|
||||
// Content.
|
||||
if (model.ArticleContentSegmentBodies != null)
|
||||
{
|
||||
SaxArticle.ContentData articleContent = new SaxArticle.ContentData();
|
||||
for (int segmentIdx = 0; segmentIdx < model.ArticleContentSegmentBodies.Count; segmentIdx++)
|
||||
{
|
||||
String segmentBody = model.ArticleContentSegmentBodies[segmentIdx];
|
||||
String segmentItemImageId = model.ArticleContentSegmentItemImageIds.Count > segmentIdx ? model.ArticleContentSegmentItemImageIds[segmentIdx] : "";
|
||||
String segmentImageIdx = model.ArticleContentSegmentImageIdxs.Count > segmentIdx ? model.ArticleContentSegmentImageIdxs[segmentIdx] : "";
|
||||
if (!StringUtil.IsEmpty(segmentBody))
|
||||
{
|
||||
// Ensure that the image is correctly identified for the Article.
|
||||
itemImage.ItemId = article.GetItemId();
|
||||
itemImage.ImageType = Sax.ImageType.Article;
|
||||
itemImage.SessionUid = 0;
|
||||
itemImage.ImageUid = 0;
|
||||
itemImage.Status = SaxItemImage.DefaultStatus;
|
||||
if (ItemDataMgr.UpdateItemImage(itemImage, DbUpdateInfo))
|
||||
// HTML Body segment.
|
||||
var segment = articleContent.AddSegment();
|
||||
segment.Body.Html = segmentBody;
|
||||
}
|
||||
else if (!StringUtil.IsEmpty(segmentItemImageId) || !StringUtil.IsEmpty(segmentImageIdx))
|
||||
{
|
||||
SysId itemImageId = model.ExtractSysId(segmentItemImageId);
|
||||
int imageIdx = StringUtil.ToInt(segmentImageIdx);
|
||||
|
||||
// Check for new image first.
|
||||
SaxItemImage itemImage = itemImages.GetItemImageBySessionImage(sessionData.SessionIdx, imageIdx);
|
||||
if (itemImage == null)
|
||||
itemImage = itemImages.GetItemImageById(itemImageId);
|
||||
if (itemImage != null)
|
||||
{
|
||||
// Assign the image segment to the article.
|
||||
var segment = articleContent.AddSegment();
|
||||
segment.Image.ItemImageId = itemImage.Id;
|
||||
// Remove the image from the list as it's now been handled.
|
||||
itemImages.Remove(itemImage);
|
||||
// Ensure that the image is correctly identified for the Article.
|
||||
itemImage.ItemId = article.GetItemId();
|
||||
itemImage.ImageType = Sax.ImageType.Article;
|
||||
itemImage.SessionUid = 0;
|
||||
itemImage.ImageUid = 0;
|
||||
itemImage.Status = SaxItemImage.DefaultStatus;
|
||||
if (ItemDataMgr.UpdateItemImage(itemImage, DbUpdateInfo))
|
||||
{
|
||||
// Assign the image segment to the article.
|
||||
var segment = articleContent.AddSegment();
|
||||
segment.Image.ItemImageId = itemImage.Id;
|
||||
// Remove the image from the list as it's now been handled.
|
||||
itemImages.Remove(itemImage);
|
||||
}
|
||||
else
|
||||
SaLogger.Warn(fn + " Failed to update article image: " + ItemDataMgr.ErrorStateMessage);
|
||||
}
|
||||
else
|
||||
SaLogger.Warn(fn + " Failed to update article image: " + ItemDataMgr.ErrorStateMessage);
|
||||
SaLogger.Warn(fn + " Failed to identify article image. ItemImageId: " + itemImageId.ToInt() + ". SessionIdx: " + sessionData.SessionIdx + ". ImageIdx: " + imageIdx + ".");
|
||||
}
|
||||
else
|
||||
SaLogger.Warn(fn + " Failed to identify article image. ItemImageId: " + itemImageId.ToInt() + ". SessionIdx: " + sessionData.SessionIdx + ". ImageIdx: " + imageIdx + ".");
|
||||
}
|
||||
article.BodyData = SaxArticle.GetContentData(articleContent);
|
||||
}
|
||||
article.BodyData = SaxArticle.GetContentData(articleContent);
|
||||
|
||||
// Update the Article.
|
||||
if (!ActivityMgr.UpdateArticle(article, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to update article [Id:" + SysId.ToString(article.Id) + "]: " + ActivityMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.update.failed"]));
|
||||
}
|
||||
SaLogger.Info(fn + " Article " + (articleCreated ? "created" : "updated") + ". Id: " + article.Id.ToString() + ". User: " + SessionData.User.EmailAddress, true);
|
||||
|
||||
// Store Article Activity Index data.
|
||||
ActivityConsole.StoreActivityIndex(article, DbUpdateInfo);
|
||||
|
||||
// Delete remaining images as they are no longer required.
|
||||
foreach (SaxItemImage itemImage in itemImages)
|
||||
{
|
||||
itemImage.SessionUid = 0;
|
||||
itemImage.ImageUid = 0;
|
||||
itemImage.Status = SaStatus.Deleted;
|
||||
ItemDataMgr.UpdateItemImage(itemImage, DbUpdateInfo);
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateArticleResponseData(model, article, organisation, responseData.Article);
|
||||
responseData.Success = true;
|
||||
}
|
||||
|
||||
// Update the Article.
|
||||
if (!ActivityMgr.UpdateArticle(article, DbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to update article [Id:" + SysId.ToString(article.Id) + "]: " + ActivityMgr.ErrorStateMessage);
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.update.failed"]));
|
||||
}
|
||||
SaLogger.Info(fn + " Article " + (articleCreated ? "created" : "updated") + ". Id: " + article.Id.ToString() + ". User: " + SessionData.User.EmailAddress, true);
|
||||
|
||||
// Store Article Activity Index data.
|
||||
ActivityConsole.StoreActivityIndex(article, DbUpdateInfo);
|
||||
|
||||
// Delete remaining images as they are no longer required.
|
||||
foreach (SaxItemImage itemImage in itemImages)
|
||||
{
|
||||
itemImage.SessionUid = 0;
|
||||
itemImage.ImageUid = 0;
|
||||
itemImage.Status = SaStatus.Deleted;
|
||||
ItemDataMgr.UpdateItemImage(itemImage, DbUpdateInfo);
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateArticleResponseData(model, article, responseData.Article);
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,73 +129,52 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
}
|
||||
private OrganisationData GetOrganisationForFilter(SysId filterOrganisationId, String filterOrganisationCaption, Sax.OrganisationRole organisationRole)
|
||||
{
|
||||
// Check that user is associated with organisations.
|
||||
SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params();
|
||||
prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId);
|
||||
prmUserOrganisation.OrganisationStatusCat = SaxOrganisation.StatusCat.ActiveOnly;
|
||||
prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly;
|
||||
if (AccountMgr.GetUserOrganisationCount(prmUserOrganisation) < 1)
|
||||
return null;
|
||||
OrganisationData organisationData = null;
|
||||
|
||||
// Roles (any) required for organisation list.
|
||||
List<Sax.OrganisationRole> requiredRoles = new List<Sax.OrganisationRole>() { Sax.OrganisationRole.Admin };
|
||||
List <Sax.OrganisationRole> requiredRoles = new List<Sax.OrganisationRole>() { Sax.OrganisationRole.Admin };
|
||||
if (organisationRole > 0)
|
||||
requiredRoles.Add(organisationRole);
|
||||
|
||||
// Retrieve specified organisation.
|
||||
OrganisationData organisationData = null;
|
||||
// Filter to identify suitable organisations that user is a member of and has the appropriate rights.
|
||||
SaxUserOrganisation.Params prmUserOrganisation = new SaxUserOrganisation.Params();
|
||||
prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId);
|
||||
prmUserOrganisation.OrganisationStatusCat = SaxOrganisation.StatusCat.ActiveOnly;
|
||||
prmUserOrganisation.OrganisationMembersOnly = true;
|
||||
prmUserOrganisation.OrganisationRolesAny.AddRange(requiredRoles);
|
||||
prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly;
|
||||
|
||||
// Restrict to specified Organisation.
|
||||
if (SysId.IsValid(filterOrganisationId))
|
||||
{
|
||||
organisationData = new OrganisationData(filterOrganisationId) { Caption = filterOrganisationCaption };
|
||||
using (SaxOrganisation organisation = AccountMgr.GetOrganisationById(organisationData.Id))
|
||||
{
|
||||
// Validate organisation.
|
||||
if (organisation != null && organisation.IsStatusActive && AccountMgr.UserHasAnyOrganisationRole(UserAccountId, organisation.Id, requiredRoles))
|
||||
organisationData.Caption = organisation.Name;
|
||||
else
|
||||
organisationData = null;
|
||||
}
|
||||
// Verify that the specified organisation is valid for the filter conditions.
|
||||
prmUserOrganisation.OrganisationIdsIncluded.Add(filterOrganisationId);
|
||||
if (AccountMgr.GetUserOrganisationCount(prmUserOrganisation) < 1)
|
||||
// Specified organisation is not valid - remove restriction.
|
||||
prmUserOrganisation.OrganisationIdsIncluded.Clear();
|
||||
}
|
||||
|
||||
if (organisationData == null)
|
||||
// Pick the first valid Organisation.
|
||||
ColumnDfn colOrganisationId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.OrganisationId);
|
||||
ColumnDfn colOrganisationName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Name);
|
||||
prmUserOrganisation.SortColumns.Add(colOrganisationName);
|
||||
prmUserOrganisation.ResultsPaging.PageLength = 1;
|
||||
prmUserOrganisation.ResultsPaging.PageNo = 1;
|
||||
using (DbResultSet resultSet = AccountMgr.ExecuteUserOrganisationQuery(new List<ColumnDfn>() { colOrganisationId, colOrganisationName }, prmUserOrganisation))
|
||||
{
|
||||
// Pick the first valid Organisation that the user is a member of.
|
||||
ColumnDfn colOrganisationId = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.OrganisationId);
|
||||
ColumnDfn colOrganisationName = AccountMgr.GetUserOrganisationColumnDfn(SaxUserOrganisation.Column.Organisation_Name);
|
||||
prmUserOrganisation = new SaxUserOrganisation.Params();
|
||||
prmUserOrganisation.UserAccountIdsIncluded.Add(UserAccountId);
|
||||
if (organisationData != null && SysId.IsValid(organisationData.Id))
|
||||
prmUserOrganisation.OrganisationIdsIncluded.Add(organisationData.Id);
|
||||
prmUserOrganisation.OrganisationStatusCat = SaxOrganisation.StatusCat.ActiveOnly;
|
||||
prmUserOrganisation.OrganisationMembersOnly = true;
|
||||
prmUserOrganisation.StatusCat = SaxUserOrganisation.StatusCat.ActiveOnly;
|
||||
prmUserOrganisation.SortColumns.Add(colOrganisationName);
|
||||
prmUserOrganisation.ResultsPaging.PageLength = 1;
|
||||
prmUserOrganisation.ResultsPaging.PageNo = 1;
|
||||
using (DbResultSet resultSet = AccountMgr.ExecuteUserOrganisationQuery(new List<ColumnDfn>() { colOrganisationId, colOrganisationName }, prmUserOrganisation))
|
||||
if (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
|
||||
{
|
||||
while (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
|
||||
NamedValue.Map values = resultSet.GetRecordValues();
|
||||
SysId organisationId = new SysId(values.GetLong(colOrganisationId.DataName));
|
||||
if (SysId.IsValid(organisationId))
|
||||
{
|
||||
NamedValue.Map values = resultSet.GetRecordValues();
|
||||
SysId organisationId = new SysId(values.GetLong(colOrganisationId.DataName));
|
||||
if (SysId.IsValid(organisationId))
|
||||
organisationData = new OrganisationData(organisationId)
|
||||
{
|
||||
organisationData = new OrganisationData(organisationId);
|
||||
organisationData.Caption = values.GetString(colOrganisationName.DataName);
|
||||
break;
|
||||
}
|
||||
Caption = values.GetString(colOrganisationName.DataName)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
if (SysId.IsValid(organisationData.Id) && StringUtil.IsEmpty(organisationData.Caption))
|
||||
{
|
||||
// Organisation has been identified but no caption available as yet.
|
||||
using (SaxOrganisation organisation = AccountMgr.GetOrganisationById(organisationData.Id))
|
||||
{
|
||||
if (organisation != null)
|
||||
organisationData.Caption = organisation.Name;
|
||||
}
|
||||
}
|
||||
return organisationData;
|
||||
}
|
||||
|
||||
|
||||
@@ -166,6 +166,8 @@ namespace Saxonite.Net.Core.Web.Online.Models
|
||||
}
|
||||
public SysId DecryptId(String encryptedId)
|
||||
{
|
||||
if (StringUtil.IsEmpty(encryptedId))
|
||||
return new SysId();
|
||||
if (StringUtil.IsNumeric(encryptedId))
|
||||
return encryptedId.ToSysId();
|
||||
NameValueCollection idObfuscationParams = SaxController_Base.DecryptParameters(encryptedId, Base64IV_IdObfuscation, Base64Key_IdObfuscation);
|
||||
@@ -230,6 +232,7 @@ namespace Saxonite.Net.Core.Web.Online.Models
|
||||
{
|
||||
/// <summary>Encrypted Id</summary>
|
||||
public String Id { get; set; }
|
||||
public String SportIdParent { get; set; }
|
||||
public String Name { get; set; }
|
||||
public String StatusCode { get; set; }
|
||||
public String StatusDesc { get; set; }
|
||||
@@ -242,6 +245,7 @@ namespace Saxonite.Net.Core.Web.Online.Models
|
||||
SportData sportData = new SportData()
|
||||
{
|
||||
Id = GetEncryptedSportId(sport.Id),
|
||||
SportIdParent = SysId.IsValid(sport.SportIdParent) ? GetEncryptedSportId(sport.SportIdParent) : null,
|
||||
Name = GetSportCaption(sport),
|
||||
StatusCode = sport.StatusCode,
|
||||
StatusDesc = Localiser.GetStatusCaption(sport.Status)
|
||||
@@ -250,6 +254,14 @@ namespace Saxonite.Net.Core.Web.Online.Models
|
||||
}
|
||||
return sports;
|
||||
}
|
||||
public List<SaxSport.Data> GetChildSports_Active(SysId sportIdParent)
|
||||
{
|
||||
List<SaxSport.Data> sports = new List<SaxSport.Data>();
|
||||
if (!SysId.IsValid(sportIdParent)) return sports;
|
||||
List<SaxSport.Data> activeSports = DataCacheConsole.GetActiveSports();
|
||||
sports.AddRange(activeSports.FindAll(item => sportIdParent.Equals(item.SportIdParent)));
|
||||
return sports;
|
||||
}
|
||||
public String GetEncryptedSportId(SysId sportId)
|
||||
{
|
||||
return DataCacheConsole.GetEncryptedSportId(sportId, EncryptId(sportId));
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
<div class="col">
|
||||
<div class="sax-caption"><div class="sax-action ArticleHeadline"></div></div>
|
||||
</div>
|
||||
<div class="fixed"><div class="OrganisationName pt4 pr16"></div></div>
|
||||
<div class="fixed sax-actions">
|
||||
@* Burger menu *@
|
||||
<ul class="nav navbar-nav navbar-light navbar-right sax-burger">
|
||||
|
||||
@@ -173,7 +173,7 @@
|
||||
.sax-header ul.nav.sax-burger ul.sax-dropdown-menu li.sax-action.sax-dropdown-item .sax-label
|
||||
{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
padding: 0 0 0 4px;
|
||||
}
|
||||
|
||||
.sax-header ul.nav.sax-burger ul.sax-dropdown-menu li.sax-action.sax-dropdown-item:hover .sax-label
|
||||
@@ -251,8 +251,8 @@
|
||||
.sax-alpha .sax-panel-item
|
||||
{
|
||||
background-color: #fff;
|
||||
border-radius: 0;
|
||||
border-radius: 3px;
|
||||
border-radius: 4px;
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-right-radius: 8px;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"use strict";
|
||||
sax.segIdPrefix = 'Seg_';
|
||||
sax.classFileDrag = 'sax-file-drag';
|
||||
let am = sax.articleMgt = { data: {}, $pnl: {}, $frm: {}, $dlg: {} };
|
||||
let am = sax.articleMgt = { ajax: {}, data: {}, $pnl: {}, $frm: {}, $dlg: {} };
|
||||
let $pnl = am.$pnl, $frm = am.$frm, $dlg = am.$dlg;
|
||||
let ac = sax.articleContent = sax.articleContent || {};
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
$('.sax-panel-item-list', $pnl.results).fadeOut(200).empty();
|
||||
$('.sax-panel-messages', $pnl.results).hide().empty().append($('<div class="sax-message">' + sax.msg.dataQuerying + '</div>')).fadeIn(200);
|
||||
}
|
||||
sax.ajax.refreshResults = sax.ajax.refreshResults || { url: sax.url.base + 'Article/Ajax/GetList', formId: 'frmArticleFilter', callbackFn: am.doRefreshResults };
|
||||
sax.doAjaxRequest(sax.ajax.refreshResults, delay || 50);
|
||||
am.ajax.refreshResults = am.ajax.refreshResults || { url: sax.url.base + 'Article/Ajax/GetList', formId: 'frmArticleFilter', callbackFn: am.doRefreshResults };
|
||||
sax.doAjaxRequest(am.ajax.refreshResults, delay || 50);
|
||||
am.awaitingRefreshResponse = true;
|
||||
}
|
||||
am.doRefreshResults = function (response)
|
||||
@@ -53,6 +53,8 @@
|
||||
{
|
||||
if (!item) return;
|
||||
$('.sax-panel-messages', $pnl.results).hide().empty();
|
||||
if (!$('#ifFilterOrganisationId', $frm.filter).val())
|
||||
$('.OrganisationName', $item).text(item.organisationName);
|
||||
$('.ArticleHeadline', $item).text(item.headline);
|
||||
$('.ArticleSummary', $item).text(item.summary);
|
||||
$('.ArticleRegionCaption', $item).text(item.regionCaptionPrimary);
|
||||
@@ -173,8 +175,8 @@
|
||||
am.clearItem();
|
||||
am.data.item = item; am.data.$item = $item;
|
||||
$('.ArticleId', $frm.articleId).val(item.id);
|
||||
sax.ajax.updateItem = sax.ajax.updateItem || { url: sax.url.base + 'Article/Ajax/GetItem', formId: 'frmArticleId', callbackFn: am.onUpdateItem };
|
||||
sax.doAjaxRequest(sax.ajax.updateItem, 50);
|
||||
am.ajax.updateItem = am.ajax.updateItem || { url: sax.url.base + 'Article/Ajax/GetItem', formId: 'frmArticleId', callbackFn: am.onUpdateItem };
|
||||
sax.doAjaxRequest(am.ajax.updateItem, 50);
|
||||
}
|
||||
am.onUpdateItem = function (response)
|
||||
{
|
||||
@@ -419,12 +421,12 @@
|
||||
sax.clearControlError();
|
||||
sax.data.contactImageUploadContext = context;
|
||||
|
||||
sax.ajax.uploadArticleImage = sax.ajax.uploadArticleImage || { url: sax.url.base + 'Article/Ajax/UploadImage', callbackFn: am.handleArticleImageUploadResponse, noWaitIcon: true };
|
||||
sax.ajax.uploadArticleImage.formData = new FormData();
|
||||
sax.ajax.uploadArticleImage.formData.append("__RequestVerificationToken", $('#frmNavigate input[name="__RequestVerificationToken"]').val());
|
||||
sax.ajax.uploadArticleImage.formData.append("ArticleId", $('#ifArticleId', $frm.article).val());
|
||||
sax.ajax.uploadArticleImage.formData.append("ArticleImage", file);
|
||||
sax.doAjaxRequest(sax.ajax.uploadArticleImage, 50);
|
||||
am.ajax.uploadArticleImage = am.ajax.uploadArticleImage || { url: sax.url.base + 'Article/Ajax/UploadImage', callbackFn: am.handleArticleImageUploadResponse, noWaitIcon: true };
|
||||
am.ajax.uploadArticleImage.formData = new FormData();
|
||||
am.ajax.uploadArticleImage.formData.append("__RequestVerificationToken", $('#frmNavigate input[name="__RequestVerificationToken"]').val());
|
||||
am.ajax.uploadArticleImage.formData.append("ArticleId", $('#ifArticleId', $frm.article).val());
|
||||
am.ajax.uploadArticleImage.formData.append("ArticleImage", file);
|
||||
sax.doAjaxRequest(am.ajax.uploadArticleImage, 50);
|
||||
}
|
||||
am.handleArticleImageUploadResponse = function (response)
|
||||
{
|
||||
@@ -445,8 +447,8 @@
|
||||
//--------------------------------------------------------------
|
||||
am.storeItem = function ()
|
||||
{
|
||||
sax.ajax.storeItem = sax.ajax.storeItem || { url: sax.url.base + 'Article/Ajax/StoreItem', formId: 'frmArticle', callbackFn: am.onStoreItem };
|
||||
sax.doAjaxRequest(sax.ajax.storeItem, 50);
|
||||
am.ajax.storeItem = am.ajax.storeItem || { url: sax.url.base + 'Article/Ajax/StoreItem', formId: 'frmArticle', callbackFn: am.onStoreItem };
|
||||
sax.doAjaxRequest(am.ajax.storeItem, 50);
|
||||
}
|
||||
am.onStoreItem = function (response)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
(function (win, doc, undef)
|
||||
{
|
||||
"use strict";
|
||||
let cs = sax.codeSelect = sax.codeSelect || { fn: {}, $dlg: {}, codeIdPrefix: 'Code_' };
|
||||
let cs = sax.codeSelect = sax.codeSelect || { fn: {}, $dlg: {} };
|
||||
|
||||
//--------------------------------------------------------------
|
||||
/*
|
||||
@@ -39,23 +39,23 @@
|
||||
let code = codes[codeIdx];
|
||||
let selected = cs.selectedCodes.indexOf(code.code) >= 0;
|
||||
let $code = $codeTmpl.clone();
|
||||
$($code).prop('id', cs.codeIdPrefix + code.code).attr('aria-code', code.code).on('click', function () { cs.fn.onClickCode(code.code); }).on('dblclick', function () { cs.fn.onDblClickCode(code.code); }).find('.CodeDesc').text(code.desc).end();
|
||||
$($code).attr('aria-code', code.code).on('click', function () { cs.fn.onClickCode(code.code, $code); }).on('dblclick', function () { cs.fn.onDblClickCode(code.code, $code); }).find('.CodeDesc').text(code.desc).end();
|
||||
if (selected) $codesSelec.append($code);
|
||||
else $codesAvail.append($code);
|
||||
}
|
||||
}
|
||||
cs.fn.onClickCode = function (code)
|
||||
cs.fn.onClickCode = function (code, $code)
|
||||
{
|
||||
$('.sax-panel-item.Code').removeClass('sel');
|
||||
$('.sax-panel-item.Code[aria-code="' + code + '"]').addClass('sel');
|
||||
$code.addClass('sel');
|
||||
}
|
||||
cs.fn.onDblClickCode = function (code)
|
||||
cs.fn.onDblClickCode = function (code, $code)
|
||||
{
|
||||
let codeIdx = cs.selectedCodes.indexOf(code);
|
||||
//sax.debug('onDblClickCode', code, codeIdx);
|
||||
if (codeIdx >= 0) cs.selectedCodes.splice(codeIdx, 1); else cs.selectedCodes.push(code)
|
||||
cs.fn.displayCodes(cs.cfg.codes)
|
||||
$('.sax-panel-item.Code[aria-code="' + code + '"]').addClass('sel');
|
||||
$code.addClass('sel');
|
||||
}
|
||||
cs.fn.onClickSelect = function ()
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
(function (win, doc, undef)
|
||||
{
|
||||
"use strict";
|
||||
let se = sax.sportExperience = { fn: {}, $pnl: {}, $frm: {}, $dlg: {} };
|
||||
let se = sax.sportExperience = { fn: {}, ajax: {}, data: {}, $pnl: {}, $frm: {}, $dlg: {} };
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.showSportExperience = function (usrSpt)
|
||||
@@ -19,11 +19,11 @@
|
||||
$('.UserSportId', se.$frm.sportExp).val(usrSpt.id);
|
||||
se.fn.refreshResults();
|
||||
}
|
||||
se.fn.refreshResults = function()
|
||||
se.fn.refreshResults = function ()
|
||||
{
|
||||
let frm = $('#frmProfileSportId');
|
||||
sax.ajax.sportExperiences = sax.ajax.sportExperiences || { url: sax.url.base + 'UserSport/Ajax/GetExperienceList', formId: frm.prop('id'), callbackFn: se.fn.handleSportExperiencesResponse };
|
||||
sax.doAjaxRequest(sax.ajax.sportExperiences, 50);
|
||||
se.ajax.sportExperiences = se.ajax.sportExperiences || { url: sax.url.base + 'UserSport/Ajax/GetExperienceList', formId: frm.prop('id'), callbackFn: se.fn.handleSportExperiencesResponse };
|
||||
sax.doAjaxRequest(se.ajax.sportExperiences, 50);
|
||||
}
|
||||
se.fn.handleSportExperiencesResponse = function (response)
|
||||
{
|
||||
@@ -41,8 +41,7 @@
|
||||
{
|
||||
let item = items[itemIdx];
|
||||
item.idx = ++se.idx;
|
||||
let $item = se.fn.getItemTemplate(item.idx);
|
||||
//sax.debug(item, $item);
|
||||
let $item = se.fn.getItemTemplate();
|
||||
$('.ExperiencePeriod', $item).text(item.period);
|
||||
$('.ExperienceSummary', $item).text(item.summary);
|
||||
$('.ExperienceTeam', $item).text(item.team);
|
||||
@@ -58,17 +57,13 @@
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
se.fn.getItemId = function (idx)
|
||||
{
|
||||
return 'SptExp_' + idx;
|
||||
}
|
||||
se.fn.getItemActionTemplate = function ()
|
||||
{
|
||||
return $('.sax-panel-item-template ul.sax-dropdown-menu.SportExperience li', se.$pnl.results).clone();
|
||||
}
|
||||
se.fn.getItemTemplate = function (idx)
|
||||
{
|
||||
return $('.sax-panel-item-template .sax-panel-item.SportExperience', se.$pnl.results).clone().prop('id', se.fn.getItemId(idx));
|
||||
return $('.sax-panel-item-template .sax-panel-item.SportExperience', se.$pnl.results).clone();
|
||||
}
|
||||
se.fn.getMenuOption = function ($opt, lbl, fn, cls)
|
||||
{
|
||||
@@ -92,8 +87,8 @@
|
||||
//sax.debug('updateSportExperience', item);
|
||||
let frm = se.$frm.sportExpId;
|
||||
$('.UserSportExperienceId', se.$frm.sportExpId).val(item.id);
|
||||
sax.ajax.sportExp = sax.ajax.sportExp || { url: sax.url.base + 'UserSport/Ajax/GetExperience', formId: frm.prop('id'), callbackFn: se.fn.doUpdateSportExperience };
|
||||
sax.doAjaxRequest(sax.ajax.sportExp, 50);
|
||||
se.ajax.sportExp = se.ajax.sportExp || { url: sax.url.base + 'UserSport/Ajax/GetExperience', formId: frm.prop('id'), callbackFn: se.fn.doUpdateSportExperience };
|
||||
sax.doAjaxRequest(se.ajax.sportExp, 50);
|
||||
}
|
||||
se.fn.doUpdateSportExperience = function (response)
|
||||
{
|
||||
@@ -118,8 +113,8 @@
|
||||
{
|
||||
//sax.debug('storeSportExperience');
|
||||
let frm = se.$frm.sportExp;
|
||||
sax.ajax.storeSportExp = sax.ajax.storeSportExp || { url: sax.url.base + 'UserSport/Ajax/StoreExperience', formId: frm.prop('id'), callbackFn: se.fn.onStoreSportExperience };
|
||||
sax.doAjaxRequest(sax.ajax.storeSportExp, 50);
|
||||
se.ajax.storeSportExp = se.ajax.storeSportExp || { url: sax.url.base + 'UserSport/Ajax/StoreExperience', formId: frm.prop('id'), callbackFn: se.fn.onStoreSportExperience };
|
||||
sax.doAjaxRequest(se.ajax.storeSportExp, 50);
|
||||
}
|
||||
se.fn.onStoreSportExperience = function (response)
|
||||
{
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
(function (win, doc, undef)
|
||||
{
|
||||
"use strict";
|
||||
let ps = sax.mdl.profileSports = sax.mdl.profileSports || {};
|
||||
let $pnl = ps.$pnl = {}, $dlg = ps.$dlg = {}, $frm = ps.$frm = {};
|
||||
ps.data = { };
|
||||
let ps = sax.mdl.profileSports = { ajax: {}, data: {}, $pnl: {}, $dlg: {}, $frm: {} };
|
||||
let $pnl = ps.$pnl, $dlg = ps.$dlg, $frm = ps.$frm;
|
||||
ps.data = {};
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.refreshProfileSportsInfo = function (delay)
|
||||
@@ -21,9 +21,9 @@
|
||||
{
|
||||
//sax.debug('refreshProfileSports');
|
||||
delete sax.page.profileSportsChanged;
|
||||
sax.ajax.profileSports = sax.ajax.profileSports || { url: sax.url.base + 'Account/Ajax/GetProfileSports', formId: 'frmNavigate', noWaitIcon: true };
|
||||
sax.ajax.profileSports.callbackFn = callbackFn;
|
||||
sax.doAjaxRequest(sax.ajax.profileSports, 50);
|
||||
ps.ajax.profileSports = ps.ajax.profileSports || { url: sax.url.base + 'Account/Ajax/GetProfileSports', formId: 'frmNavigate', noWaitIcon: true };
|
||||
ps.ajax.profileSports.callbackFn = callbackFn;
|
||||
sax.doAjaxRequest(ps.ajax.profileSports, 50);
|
||||
}
|
||||
ps.onRefreshProfileSportsInfo = function (response)
|
||||
{
|
||||
@@ -39,9 +39,9 @@
|
||||
{
|
||||
let item = items[itemIdx];
|
||||
sax.profile.sports.Ids.push(item.sportId);
|
||||
let $item = $tmpl.clone().prop('id', 'ProSpt_' + item.id);
|
||||
$('.sax-header .sax-action.sax-edit', $item).on('click', function (evt) { ps.updateProfileSport(item.id); });
|
||||
$('.sax-content', $item).on('dblclick', function (evt) { ps.updateProfileSport(item.id); });
|
||||
let $item = $tmpl.clone();
|
||||
$('.sax-header .sax-action.sax-edit', $item).on('click', function (evt) { ps.updateProfileSport(item); });
|
||||
$('.sax-content', $item).on('dblclick', function (evt) { ps.updateProfileSport(item); });
|
||||
$('.sax-header .sax-action.sax-experience', $item).on('click', function (evt) { sax.showSportExperience(item); });
|
||||
$('.SportName', $item).text(item.sportName);
|
||||
$('.SportParticipationValue', $item).text(item.sportParticipation);
|
||||
@@ -63,12 +63,12 @@
|
||||
dlg.dialog('option', 'title', sax.dlg.title.addUserSport);
|
||||
sax.openDialog(dlg, 640, 480);
|
||||
}
|
||||
ps.updateProfileSport = function (id)
|
||||
ps.updateProfileSport = function (item)
|
||||
{
|
||||
//sax.debug('updateProfileSport', id);
|
||||
$('#frmProfileSportId .UserSportId').val(id);
|
||||
sax.ajax.profileSport = sax.ajax.profileSport || { url: sax.url.base + 'Account/Ajax/GetProfileSport', formId: 'frmProfileSportId', callbackFn: ps.doUpdateProfileSport };
|
||||
sax.doAjaxRequest(sax.ajax.profileSport, 50);
|
||||
//sax.debug('updateProfileSport', item);
|
||||
$('#frmProfileSportId .UserSportId').val(item.id);
|
||||
ps.ajax.profileSport = ps.ajax.profileSport || { url: sax.url.base + 'Account/Ajax/GetProfileSport', formId: 'frmProfileSportId', callbackFn: ps.doUpdateProfileSport };
|
||||
sax.doAjaxRequest(ps.ajax.profileSport, 50);
|
||||
}
|
||||
ps.doUpdateProfileSport = function (response)
|
||||
{
|
||||
@@ -101,8 +101,8 @@
|
||||
{
|
||||
//sax.debug('storeProfileSport');
|
||||
sax.clearControlErrors();
|
||||
sax.ajax.storeProfileSport = sax.ajax.storeProfileSport || { url: sax.url.base + 'Account/Ajax/StoreProfileSport', formId: 'frmProfileSport', callbackFn: ps.onStoreProfileSport };
|
||||
sax.doAjaxRequest(sax.ajax.storeProfileSport, 50);
|
||||
ps.ajax.storeProfileSport = ps.ajax.storeProfileSport || { url: sax.url.base + 'Account/Ajax/StoreProfileSport', formId: 'frmProfileSport', callbackFn: ps.onStoreProfileSport };
|
||||
sax.doAjaxRequest(ps.ajax.storeProfileSport, 50);
|
||||
}
|
||||
ps.onStoreProfileSport = function (response)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user