This commit is contained in:
2018-08-31 17:02:09 +00:00
parent b7c46370f8
commit 9b3cc74f2a
4 changed files with 29 additions and 17 deletions

View File

@@ -40,13 +40,7 @@ namespace AyaNova.Biz
//CREATE
internal async Task<Tag> CreateAsync(string inObj)
{
//Must be lowercase per rules
//This may be naive when we get international customers but for now supporting utf-8 and it appears it's safe to do this with unicode
inObj = inObj.ToLowerInvariant();
//No spaces in tags, replace with dashes
inObj = inObj.Replace(" ", "-");
inObj = CleanTagName(inObj);
Validate(inObj, true);
if (HasErrors)
return null;
@@ -65,6 +59,22 @@ namespace AyaNova.Biz
}
}
private static string CleanTagName(string inObj)
{
//Must be lowercase per rules
//This may be naive when we get international customers but for now supporting utf-8 and it appears it's safe to do this with unicode
inObj = inObj.ToLowerInvariant();
//No spaces in tags, replace with dashes
inObj = inObj.Replace(" ", "-");
//Remove multiple dash sequences
inObj = System.Text.RegularExpressions.Regex.Replace(inObj, "-+", "-");
//Ensure doesn't start or end with a dash
inObj = inObj.Trim('-');
//No longer than 35 characters
inObj = StringUtil.MaxLength(inObj, 35);
return inObj;
}
////////////////////////////////////////////////////////////////////////////////////////////////
/// GET
@@ -142,6 +152,8 @@ namespace AyaNova.Biz
//put
internal bool Put(Tag dbObj, Tag inObj)
{
//Ensure it follows the rules
inObj.Name = CleanTagName(inObj.Name);
//Replace the db object with the PUT object
CopyObject.Copy(inObj, dbObj, "Id");
@@ -149,10 +161,6 @@ namespace AyaNova.Biz
//this will allow EF to check it out
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
//Must be lowercase per rules
//This may be naive when we get international customers but for now supporting utf-8 and it appears it's safe to do this with unicode
dbObj.Name = dbObj.Name.ToLowerInvariant();
Validate(dbObj.Name, false);
if (HasErrors)
return false;
@@ -166,7 +174,8 @@ namespace AyaNova.Biz
//Do the patching
objectPatch.ApplyTo(dbObj);
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = concurrencyToken;
dbObj.Name = dbObj.Name.ToLowerInvariant();
//Ensure it follows the rules
dbObj.Name = CleanTagName(dbObj.Name);
Validate(dbObj.Name, false);
if (HasErrors)
return false;
@@ -251,8 +260,8 @@ namespace AyaNova.Biz
var NewTagName = j["Name"].Value<string>();
var OldV7Id = new Guid(j["ID"].Value<string>());
//In RAVEN tags can only be 35 characters
NewTagName = StringUtil.MaxLength(NewTagName, 35);
//Ensure it follows the rules
NewTagName = CleanTagName(NewTagName);
//There might already be a tag of the same name since so many different types of V7 objects are becoming tags
//Weighed the pros and cons of uniquifying by object type versus just using the same name for different object types:

View File

@@ -436,7 +436,7 @@ namespace AyaNova.Biz
i.UserType = UserType.Subcontractor;
}
i.Active = j["Active"].Value<bool>();
i.Active = false;//Ignore incoming value and set all imports to false so that there's no chance of licensing getting circumvented; users all need to be edited anyway for pw and login
i.EmployeeNumber = j["EmployeeNumber"].Value<string>();
i.Notes = j["Notes"].Value<string>();