From 6c17128f32810d89e550bfdd6aeeeabdeb68ca36 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 17 Mar 2020 15:22:32 +0000 Subject: [PATCH] --- devdocs/todo.txt | 4 +-- server/AyaNova/biz/PickListBiz.cs | 43 +++++++++++++++++++------------ 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/devdocs/todo.txt b/devdocs/todo.txt index 1d3e7870..9aeb8561 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -7,9 +7,7 @@ //PICKLISTS: -todo: User objects need Tags (as will all CORE objects for sure) - - Also make sure SEEDER seeds them with the same range of sample tags as for the Widgets - + todo: all template routes and actual backing code and also validation, needs to validate templates todo: clean out unneeded leftovers from AyaPickListFieldDefinition todo: add pickers for all CORE objects (User...?) diff --git a/server/AyaNova/biz/PickListBiz.cs b/server/AyaNova/biz/PickListBiz.cs index b31f1dfe..0a63dbb2 100644 --- a/server/AyaNova/biz/PickListBiz.cs +++ b/server/AyaNova/biz/PickListBiz.cs @@ -143,28 +143,28 @@ namespace AyaNova.Biz //put internal async Task ReplaceAsync(AyaType ayaType, string template) { - throw new System.NotImplementedException(); - // //preserve the owner ID if none was specified - // if (inObj.UserId == 0) - // inObj.UserId = dbObj.UserId; - // //Replace the db object with the PUT object - // CopyObject.Copy(inObj, dbObj, "Id"); - // //Set "original" value of concurrency token to input token - // //this will allow EF to check it out - // ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken; - // await ValidateAsync(dbObj, false); - // if (HasErrors) - // return false; - // await ct.SaveChangesAsync(); + var o = await ct.PickListTemplate.FirstOrDefaultAsync(m => m.Id == (long)ayaType); + if (o == null) + { + o = new PickListTemplate(); + } + o.Id = (long)ayaType; + o.Template = template; - // //Log modification and save context - // await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct); + + Validate(o); + if (HasErrors) + return false; + await ct.SaveChangesAsync(); + + //Log modification and save context + await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, o.Id, BizType, AyaEvent.Modified), ct); - //return true; + return true; } @@ -206,9 +206,18 @@ namespace AyaNova.Biz // //Can save or update? - private async Task ValidateAsync(DataListView inObj, bool isNew) + private void Validate(PickListTemplate inObj) { + + //validate that the template is valid, the type is legit etc + var TemplateType = (AyaType)inObj.Id; + if (!TemplateType.HasAttribute(typeof(CoreBizObjectAttribute))) + { + AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "AyaType", "AyaType specified is not a core object type and doesn't support pick list templates"); + return; + } + // //UserId required // if (!isNew) // {