This commit is contained in:
40
server/AyaNova/biz/TagUtil.cs
Normal file
40
server/AyaNova/biz/TagUtil.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using AyaNova.Util;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
public static class TagUtil
|
||||
{
|
||||
public static List<string> NormalizeTags(List<string> inTags)
|
||||
{
|
||||
if (inTags==null || inTags.Count == 0) return inTags;
|
||||
|
||||
List<string> outTags = new List<string>();
|
||||
foreach (var tag in inTags)
|
||||
{
|
||||
outTags.Add(CleanTagName(tag));
|
||||
}
|
||||
return outTags;
|
||||
}
|
||||
|
||||
|
||||
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 255 characters
|
||||
inObj = StringUtil.MaxLength(inObj, 255);
|
||||
return inObj;
|
||||
}
|
||||
|
||||
|
||||
}//eoc
|
||||
}//ens
|
||||
@@ -87,6 +87,7 @@ namespace AyaNova.Biz
|
||||
//Test get serial id visible id number from generator
|
||||
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
|
||||
|
||||
outObj.Tags = TagUtil.NormalizeTags(outObj.Tags);
|
||||
|
||||
await ct.Widget.AddAsync(outObj);
|
||||
await ct.SaveChangesAsync();
|
||||
@@ -118,6 +119,7 @@ namespace AyaNova.Biz
|
||||
outObj.OwnerId = UserId;
|
||||
//Test get serial id visible id number from generator
|
||||
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
|
||||
outObj.Tags = TagUtil.NormalizeTags(outObj.Tags);
|
||||
|
||||
TempContext.Widget.Add(outObj);
|
||||
TempContext.SaveChanges();
|
||||
@@ -272,10 +274,14 @@ namespace AyaNova.Biz
|
||||
|
||||
//Replace the db object with the PUT object
|
||||
CopyObject.Copy(inObj, dbObj, "Id,Serial");
|
||||
|
||||
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
|
||||
|
||||
//Set "original" value of concurrency token to input token
|
||||
//this will allow EF to check it out
|
||||
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
|
||||
|
||||
|
||||
Validate(dbObj, false);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
@@ -298,6 +304,9 @@ namespace AyaNova.Biz
|
||||
|
||||
//Do the patching
|
||||
objectPatch.ApplyTo(dbObj);
|
||||
|
||||
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
|
||||
|
||||
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = concurrencyToken;
|
||||
Validate(dbObj, false);
|
||||
if (HasErrors)
|
||||
|
||||
@@ -26,6 +26,10 @@ namespace AyaNova.Models
|
||||
public int Count {get;set;}
|
||||
public List<string> Tags { get; set; }
|
||||
|
||||
public Widget(){
|
||||
Tags=new List<string>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user