diff --git a/devdocs/todo.txt b/devdocs/todo.txt index ee2e21ea..c0659bb1 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -27,10 +27,11 @@ Once that is done then can steam ahead on the biz objects but until I have the c IMMEDIATE ITEMS: ================ - Happy monday Radiant Maiden ;) + - Need an ObjectExists type object for checking if something exists when specified by type and ID - Could this be a combined method to get the name as well just to save time? - - Or should that be another method (YES, first code a translator to translate types to db tables (however the fuck that works with EF), then can use it in turn to verify existance and get name separately) + - Or should that be another method (YES, first code a translator to translate types to db tables (however the fuck that works with EF), + then can use it in turn to verify existance and get name separately) - Once we have that go back into any code that accepts a typeandid and add to Validation code to check for it - Localized text - ** DEVISE a system to ensure no unused keys are brought forward to raven diff --git a/server/AyaNova/biz/AyaType.cs b/server/AyaNova/biz/AyaType.cs index 229876fc..aa40325c 100644 --- a/server/AyaNova/biz/AyaType.cs +++ b/server/AyaNova/biz/AyaType.cs @@ -2,6 +2,8 @@ namespace AyaNova.Biz { + + /// /// All AyaNova types and their attributes indicating what features that type will support (tagging, attachments etc) /// @@ -25,10 +27,16 @@ namespace AyaNova.Biz AyaNova7Import = 10, TrialSeeder = 11, Metrics = 12, - Locale = 13, - UserOptions=14, - TagGroup = 15, - TagGroupMap = 16 + Locale = 13, + UserOptions = 14, + TagGroup = 15, + TagGroupMap = 16 + + + //NOTE: New objects added here need to also be added to the following classes: + //AyaNova.Biz.BizObjectExistsInDatabase + //AyaNova.Biz.BizObjectFactory + //AyaNova.Biz.BizRoles } diff --git a/server/AyaNova/biz/BizObjectExistsInDatabase.cs b/server/AyaNova/biz/BizObjectExistsInDatabase.cs new file mode 100644 index 00000000..42482d6a --- /dev/null +++ b/server/AyaNova/biz/BizObjectExistsInDatabase.cs @@ -0,0 +1,65 @@ +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.JsonPatch; +using EnumsNET; +using AyaNova.Util; +using AyaNova.Api.ControllerHelpers; +using AyaNova.Biz; +using AyaNova.Models; + + +namespace AyaNova.Biz +{ + + + //TODO: UNTESTED, UNUSED (SO FAR)CODE + //This was just blocked out because I know I will need it in future + internal static class BizObjectExistsInDatabase + { + + internal static bool Exists(AyaTypeId tid) + { + return Exists(tid.ObjectType, tid.ObjectId); + } + + + //Returns existance status of object type and id specified in database + internal static bool Exists(AyaType aytype, long id, AyContext ct = null) + { + //new up a context?? + if (ct == null) + { + ct = ServiceProviderProvider.DBContext; + } + switch (aytype) + { + case AyaType.User: + return ct.User.Any(m => m.Id == id); + case AyaType.Widget: + return ct.Widget.Any(m => m.Id == id); + case AyaType.Tag: + return ct.Tag.Any(m => m.Id == id); + case AyaType.TagGroup: + return ct.TagGroup.Any(m => m.Id == id); + + + + default: + throw new System.NotSupportedException($"AyaNova.BLL.BizObjectExistsInDatabase::Exists type {aytype.ToString()} is not supported"); + } + + } + + + + + + ///////////////////////////////////////////////////////////////////// + + }//eoc + + +}//eons + diff --git a/server/AyaNova/biz/BizObjectNameFetcher.cs b/server/AyaNova/biz/BizObjectNameFetcher.cs new file mode 100644 index 00000000..9db56dd2 --- /dev/null +++ b/server/AyaNova/biz/BizObjectNameFetcher.cs @@ -0,0 +1,62 @@ +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.JsonPatch; +using EnumsNET; +using AyaNova.Util; +using AyaNova.Api.ControllerHelpers; +using AyaNova.Biz; +using AyaNova.Models; + + +namespace AyaNova.Biz +{ + + //TODO: UNTESTED, UNUSED (SO FAR)CODE + //This was just blocked out because I know I will need it in future + internal static class BizObjectNameFetcher + { + + internal static string Name(AyaTypeId tid) + { + return Name(tid.ObjectType, tid.ObjectId); + } + + + //Returns existance status of object type and id specified in database + internal static string Name(AyaType aytype, long id, AyContext ct = null) + { + //new up a context?? + if (ct == null) + { + ct = ServiceProviderProvider.DBContext; + } + switch (aytype) + { + case AyaType.User: + return ct.User.Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault(); + case AyaType.Widget: + return ct.Widget.Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault(); + case AyaType.Tag: + return ct.Tag.Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault(); + case AyaType.TagGroup: + return ct.TagGroup.Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault(); + + default: + throw new System.NotSupportedException($"AyaNova.BLL.BizObjectNameFetcher::Name type {aytype.ToString()} is not supported"); + } + + } + + + + + + ///////////////////////////////////////////////////////////////////// + + }//eoc + + +}//eons +