This commit is contained in:
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System;
|
using System;
|
||||||
using AyaNova.Util;
|
using AyaNova.Util;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
|
|
||||||
namespace AyaNova.Biz
|
namespace AyaNova.Biz
|
||||||
@@ -51,20 +52,64 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
if (newTags.Count == 0 && (originalTags == null || originalTags.Count == 0)) return;
|
if (newTags.Count == 0 && (originalTags == null || originalTags.Count == 0)) return;
|
||||||
|
|
||||||
List<string> deleteTags=new List<string>();
|
List<string> deleteTags = new List<string>();
|
||||||
List<string> addTags=new List<string>();
|
List<string> addTags = new List<string>();
|
||||||
|
|
||||||
if(originalTags!=null){
|
if (originalTags != null)
|
||||||
|
{
|
||||||
//Update
|
//Update
|
||||||
//This logic is supposed to only come up with CHANGES, if the item is in both lists then it should disappear and not need to be dealt with
|
//This logic is supposed to only come up with CHANGES, if the item is in both lists then it should disappear and not need to be dealt with
|
||||||
//testing will validate it
|
//testing will validate it
|
||||||
deleteTags=originalTags.Except(newTags).ToList();
|
deleteTags = originalTags.Except(newTags).ToList();
|
||||||
addTags=newTags.Except(originalTags).ToList();
|
addTags = newTags.Except(originalTags).ToList();
|
||||||
HERE
|
|
||||||
|
|
||||||
}else{
|
|
||||||
//Add
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Add
|
||||||
|
addTags = newTags;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//ADD / INCREMENT TAGS
|
||||||
|
|
||||||
|
foreach (string s in addTags)
|
||||||
|
{
|
||||||
|
bool bDone = false;
|
||||||
|
//Keep on trying until there is success
|
||||||
|
//this allows for concurrency issues
|
||||||
|
do
|
||||||
|
{
|
||||||
|
//START: Get tag word and concurrency token and count
|
||||||
|
var ExistingTag = ct.Tag.FirstOrDefault(x => x.Name == s);
|
||||||
|
//if not present, then add it with a count of 0
|
||||||
|
if (ExistingTag == null)
|
||||||
|
{
|
||||||
|
ct.Tag.Add(new Tag() { Name = s, RefCount = 1 });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Update the refcount
|
||||||
|
ExistingTag.RefCount += 1;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ct.SaveChanges();
|
||||||
|
bDone = true;
|
||||||
|
}
|
||||||
|
catch (Exception ex) when(ex is DbUpdateConcurrencyException )
|
||||||
|
{
|
||||||
|
//allow others to flow past
|
||||||
|
string sss=ex.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//If that fails due to others added it or works, either way go back to START:
|
||||||
|
//UPDATE: INCREMENT the refcount and update the record
|
||||||
|
//If that fails due to a concurrency exception go to START:
|
||||||
|
} while (bDone == false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Add / increase reference count for added tags
|
//Add / increase reference count for added tags
|
||||||
//remove / decrease reference count for removed tags
|
//remove / decrease reference count for removed tags
|
||||||
@@ -98,13 +143,7 @@ WHERE name = 'bill'
|
|||||||
//Create table tags, word varchar 255, refcount longint, concurrency token
|
//Create table tags, word varchar 255, refcount longint, concurrency token
|
||||||
//so do this:
|
//so do this:
|
||||||
|
|
||||||
//ADD / INCREMENT TAGS
|
|
||||||
|
|
||||||
//START: Get tag word and concurrency token and count
|
|
||||||
//if not present, then add it with a count of 0
|
|
||||||
//If that fails due to others added it or works, either way go back to START:
|
|
||||||
//UPDATE: INCREMENT the refcount and update the record
|
|
||||||
//If that fails due to a concurrency exception go to START:
|
|
||||||
|
|
||||||
|
|
||||||
//REMOVE / DECREMENT TAGS
|
//REMOVE / DECREMENT TAGS
|
||||||
|
|||||||
Reference in New Issue
Block a user