cleans protocol to check for duplicate alias prior to saving
This commit is contained in:
@ -818,20 +818,24 @@
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(_aliasname))
|
if (!string.IsNullOrEmpty(_aliasname))
|
||||||
{
|
{
|
||||||
|
// Remove 'http://' and 'https://' from the alias name
|
||||||
|
string cleanedAliasName = _aliasname.Replace("http://", "").Replace("https://", "");
|
||||||
|
|
||||||
var aliases = await AliasService.GetAliasesAsync();
|
var aliases = await AliasService.GetAliasesAsync();
|
||||||
var alias = aliases.Where(item => item.Name == _aliasname).FirstOrDefault();
|
// Check if the cleaned alias name exists in the database
|
||||||
|
var alias = aliases.Where(item => item.Name == cleanedAliasName).FirstOrDefault();
|
||||||
bool unique = (alias == null || alias.AliasId == _aliasid);
|
bool unique = (alias == null || alias.AliasId == _aliasid);
|
||||||
if (unique)
|
if (unique)
|
||||||
{
|
{
|
||||||
if (_aliasid == 0)
|
if (_aliasid == 0)
|
||||||
{
|
{
|
||||||
alias = new Alias { SiteId = PageState.Site.SiteId, TenantId = PageState.Site.TenantId, Name = _aliasname, IsDefault = bool.Parse(_defaultalias) };
|
alias = new Alias { SiteId = PageState.Site.SiteId, TenantId = PageState.Site.TenantId, Name = cleanedAliasName, IsDefault = bool.Parse(_defaultalias) };
|
||||||
await AliasService.AddAliasAsync(alias);
|
await AliasService.AddAliasAsync(alias);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
alias = _aliases.Single(item => item.AliasId == _aliasid);
|
alias = _aliases.Single(item => item.AliasId == _aliasid);
|
||||||
alias.Name = _aliasname;
|
alias.Name = cleanedAliasName;
|
||||||
alias.IsDefault = bool.Parse(_defaultalias);
|
alias.IsDefault = bool.Parse(_defaultalias);
|
||||||
await AliasService.UpdateAliasAsync(alias);
|
await AliasService.UpdateAliasAsync(alias);
|
||||||
}
|
}
|
||||||
@ -839,6 +843,7 @@
|
|||||||
else // duplicate alias
|
else // duplicate alias
|
||||||
{
|
{
|
||||||
AddModuleMessage(Localizer["Message.Aliases.Taken"], MessageType.Warning);
|
AddModuleMessage(Localizer["Message.Aliases.Taken"], MessageType.Warning);
|
||||||
|
await ScrollToPageTop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await GetAliases();
|
await GetAliases();
|
||||||
|
Reference in New Issue
Block a user