This commit is contained in:
2019-12-09 19:24:53 +00:00
parent a7ad14b52a
commit 3cba0dde51

View File

@@ -26,7 +26,7 @@ namespace AyaNova.Biz
internal static FormCustomBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext)
{
return new FormCustomBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
}
@@ -89,17 +89,31 @@ namespace AyaNova.Biz
//Get one
internal async Task<FormCustom> GetAsync(string formKey)
{
TODO: this must create the formCustom record if it doesn't already exist
//Step 1: check if exists, if it does then just return it
if (await ExistsAsync(formKey))
{
return await ct.FormCustom.SingleOrDefaultAsync(m => m.FormKey == formKey);
}
//If it doesn't exist, vet the form key name is ok by checking with this list
//FormAvailableFields.AvailableFormKeys
// and if it is then create it, save to db and then return it
if (!FormAvailableFields.AvailableFormKeys.Contains(formKey))
{
//Nope, whatever it is, it's not valid
return null;
}
// Name is valid, make a new formcustom for the name specified, save to db and then return it
//NOTE: This assumes that the client will make it a legal form custom and so it doesn't include any pre-defined stock fields that are required etc
//this just makes an empty template suitable for the client to work with
var fc = new FormCustom()
{
FormKey = formKey,
Template = @"[]"
};
//Create and save to db
return await CreateAsync(fc);
var ret = await ct.FormCustom.SingleOrDefaultAsync(m => m.FormKey == formKey);
//Do not log this, it's going to be called a zillion times anyway
return ret;
}