diff --git a/server/AyaNova/biz/LocaleBiz.cs b/server/AyaNova/biz/LocaleBiz.cs index 49e153cf..1f45ffbd 100644 --- a/server/AyaNova/biz/LocaleBiz.cs +++ b/server/AyaNova/biz/LocaleBiz.cs @@ -271,6 +271,12 @@ namespace AyaNova.Biz return v.First(); } + public static long LocaleNameToIdStatic(string localeName, AyContext ct) + { + var v = ct.Locale.Where(c => c.Name == localeName).Select(x => x.Id); + if (v.Count() < 1) return ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID; + return v.First(); + } public bool LocaleExists(string localeName) { @@ -360,7 +366,7 @@ namespace AyaNova.Biz default: if (!LocaleExists(ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE)) { - throw new System.Exception($"E1015: stock locale French (fr) not found in database!"); + throw new System.Exception($"E1015: stock locale {ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE} not found in database!"); } break; @@ -376,11 +382,6 @@ namespace AyaNova.Biz /// IMPORT v7 implementation public async Task ImportV7Async(JObject j, List importMap, Guid jobId) { - //TODO: when locales are imported that's when it should take a pass over users collection and then set the correct locale accordingly - //or default if it's missing - //v7 users locale json element: - //var V7Locale=j["DefaultLanguage"].Value(); - //some types need to import from more than one source hence the seemingly redundant switch statement for futureproofing switch (j["V7_TYPE"].Value()) { diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index 24de20dd..62cdf9b4 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -387,7 +387,7 @@ namespace AyaNova.Biz "VendorID": "06e502c2-69ba-4e88-8efb-5b53c1687740", "RegionID": "f856423a-d468-4344-b7b8-121e466738c6", "DispatchZoneID": "00000000-0000-0000-0000-000000000000", - "SubContractor": false, + "SubContractor": false,//This is not actually a feature in v7, you can just pick a vendorId for subcontractor but still be of type technician "DefaultWarehouseID": "d45eab37-b6e6-4ad2-9163-66d7ba83a98c", "Custom1": "", "Custom2": "", @@ -419,11 +419,17 @@ namespace AyaNova.Biz User i = new User(); i.Name = j["FirstName"].Value() + " " + j["LastName"].Value(); i.UserType = j["UserType"].Value(); - i.Active = j["Active"].Value(); - //TODO: i.LocaleId - //when locales are imported that's when it should take a pass over users and set them as per here - //var V7Locale=j["DefaultLanguage"].Value(); + //If there is a vendorId set then this user is actually a subcontractor in v7 so set accordingly + var VendorId = new Guid(j["VendorID"].Value()); + if (VendorId != Guid.Empty) + { + i.UserType = UserType.Subcontractor; + } + + i.Active = j["Active"].Value(); + i.EmployeeNumber = j["EmployeeNumber"].Value(); + i.Notes = j["Notes"].Value(); User o = await CreateAsync(i); if (HasErrors) @@ -451,15 +457,64 @@ namespace AyaNova.Biz //EventLogProcessor.AddEntry(new Event(userId, o.Id, AyaType.User, AyaEvent.Created), ct); //MODIFIED HERE // await ct.SaveChangesAsync(); - throw new System.NotImplementedException(); + } - //break; + break; case "GZTW.AyaNova.BLL.User-locale": { - //handle locale entries for users now that we have the locales created - throw new System.NotImplementedException(); + //handle locale entries for users now that we have the locales created + var V7Locale = j["DefaultLanguage"].Value(); + + //Get the RAVEN locale name and id instead + switch (V7Locale) + { + case "Français": + break; + case "Español": + break; + case "Deutsch": + break; + case "English": + break; + default: + { + //It's a custom locale, translate it from v7 original format to imported name format + //make lower and replace spaces with dashes + V7Locale = V7Locale.ToLowerInvariant().Replace(" ", "-"); + + //ensure each character is a valid path character + foreach (char c in System.IO.Path.GetInvalidFileNameChars()) + { + V7Locale = V7Locale.Replace(c, '_'); + } + + } + break; + + } + // if (!LocaleExists("en")) + // { + // throw new System.Exception($"E1015: stock locale English (en) not found in database!"); + // } + // if (!LocaleExists("es")) + // { + // throw new System.Exception($"E1015: stock locale Spanish (es) not found in database!"); + // } + // if (!LocaleExists("de")) + // { + // throw new System.Exception($"E1015: stock locale German (de) not found in database!"); + // } + // if (!LocaleExists("fr")) + + + + //"Español",?? + //Find the matching ID number for this locale + // LocaleBiz.LocaleExistsStatic + + } - // break; + break; case "GZTW.AyaNova.BLL.User-scheduleableusergrouptags": { //handle tag entries for users now that we have the SUG tags created