From 5a3a6ff4b2e1d68d12c36290a07109cb8414fe1c Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 6 Sep 2018 22:30:17 +0000 Subject: [PATCH] --- devdocs/todo.txt | 2 ++ server/AyaNova/Controllers/TagController.cs | 3 ++- server/AyaNova/biz/TagBiz.cs | 15 ++++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/devdocs/todo.txt b/devdocs/todo.txt index 434863cd..869546b2 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -30,6 +30,8 @@ IMMEDIATE ITEMS: - Tag groups (modify tags already coded) + - X Modify tag to bring combined list of groups with tag picklist (NOPE, let the UI query both separately and integrate them at the UI level) + - Modify tag to remove itself from tagroupmap if deleted - Retag: code to tag an item should take into account if it's already tagged and not make a new record, just return existing - Localized text - ** DEVISE a system to ensure no unused keys are brought forward to raven diff --git a/server/AyaNova/Controllers/TagController.cs b/server/AyaNova/Controllers/TagController.cs index a904d02c..555cfe92 100644 --- a/server/AyaNova/Controllers/TagController.cs +++ b/server/AyaNova/Controllers/TagController.cs @@ -125,7 +125,6 @@ namespace AyaNova.Api.Controllers } - /// /// Post TAG /// @@ -352,6 +351,8 @@ namespace AyaNova.Api.Controllers //Instantiate the business object handler TagBiz biz = new TagBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + //NOTE: ct.SaveChanges not required after this call + //Delete will look after it as it also needs to delete related records manull that are not mapped in EF Core if (!biz.Delete(dbObj)) { return BadRequest(new ApiErrorResponse(biz.Errors)); diff --git a/server/AyaNova/biz/TagBiz.cs b/server/AyaNova/biz/TagBiz.cs index eef6e317..b1286dd4 100644 --- a/server/AyaNova/biz/TagBiz.cs +++ b/server/AyaNova/biz/TagBiz.cs @@ -32,7 +32,7 @@ namespace AyaNova.Biz } - + //////////////////////////////////////////////////////////////////////////////////////////////// //CREATE @@ -190,7 +190,7 @@ namespace AyaNova.Biz internal bool Delete(Tag dbObj) { - //Determine if the object can be deleted, do the deletion tentatively + //Determine if the object can be deleted, do the deletion and related objects ValidateCanDelete(dbObj); if (HasErrors) @@ -228,7 +228,7 @@ namespace AyaNova.Biz //Can delete? private void ValidateCanDelete(Tag inObj) { - //whatever needs to be check to delete this object + //whatever needs to be checked to delete this object //See if any tagmaps exist with this tag in which case it's not deleteable if (ct.TagMap.Any(e => e.TagId == inObj.Id)) @@ -236,6 +236,11 @@ namespace AyaNova.Biz AddError(ValidationErrorType.ReferentialIntegrity, "object", "Can't be deleted while has relations"); } + if (ct.TagGroupMap.Any(e => e.TagId == inObj.Id)) + { + AddError(ValidationErrorType.ReferentialIntegrity, "TagGroup", "Can't be deleted while has TagGroup relations"); + } + } @@ -394,13 +399,13 @@ namespace AyaNova.Biz TagMap tm = new TagMap(); tm.TagToObjectId = RavenUserId; - tm.TagToObjectType=AyaType.User; + tm.TagToObjectType = AyaType.User; tm.TagId = RavenTagId; tm.OwnerId = Creator; ct.TagMap.Add(tm); } ct.SaveChanges(); - + #endregion } break;