コード例 #1
0
        //make sure you treat like a single instance... no expiring, etc.
        private static bool IsDuplicate(Models.Localization localization)
        {
            var items = Repository.Current.GetResources <Models.Localization>(localization.Type.ToString(), localization.Key,
                                                                              l => l.Data.Locale == localization.Locale && l.Data.PortalId == localization.PortalId && l.Data.Namespace == localization.Namespace);

            return(items.Exists(l => l.Id != localization.Id));
            //    ).Exists(l => l.Id != localization.Id);
            //&& l.Data.Type != LocalizationType.WidgetContent).Exists(l => l.Id != localization.Id);
        }
コード例 #2
0
        public static string Import(string portalId, Models.Localization localization, string userId = null)
        {
            userId = string.IsNullOrEmpty(userId) ? Account.AuditId : userId;

            if (localization.Type == LocalizationType.Portal)
            {
                localization.Namespace = portalId;   //type portal uses portalid as namespace
            }
            var existing = Localization.Get(portalId, localization.Type, localization.Namespace, localization.Key, localization.Locale);

            localization.PortalId = portalId;
            localization.Id       = existing != null ? existing.Id : null;
            return(Save(localization, userId));
        }
コード例 #3
0
 public static string Save(Models.Localization localization, string userId = null)
 {
     userId = string.IsNullOrEmpty(userId) ? Account.AuditId : userId;
     localization.PortalId = string.IsNullOrEmpty(localization.PortalId) ? Services.Portal.CurrentPortalId : localization.PortalId;
     if (!IsDuplicate(localization))
     {
         var res = Repository.Current.StoreResource(localization.Type.ToString(), localization.Key, localization, userId);
         return(res.Id);
     }
     else
     {
         throw new Exception(GetExceptionText("DuplicateResource.Error", "{0} already exists.   Duplicates Not Allowed.", "Localization"));
     }
 }
        public static void SeedDatabase(LocalizationDatabaseContext context)
        {
            // update value if exists throughout
            var localizations = Translations.TranslationFile.GetAllSupportedTranslations();

            foreach (var localization in localizations)
            {
                var localizationQuery      = context.Localizations.Where(a => a.Code.Equals(localization.Abbreviation));
                var localizationQueryCount = localizationQuery.Count();
                if (localizationQueryCount > 1)
                {
                    throw new Exception(@"Localization Database Seed Error - Localization Query Count is > 1");
                }
                Models.Localization dbLocalization = null;
                if (localizationQueryCount.Equals(0))
                {
                    dbLocalization = new Models.Localization
                    {
                        Code = localization.Abbreviation,
                        Name = localization.Name
                    };
                    context.Localizations.Add(dbLocalization);
                    context.SaveChanges();
                }
                else
                {
                    dbLocalization = localizationQuery.First();
                }

                // check keys and update values
                foreach (var keyValuePair in localization.Translations)
                {
                    Key key           = null;
                    var keyQuery      = context.Keys.Where(a => a.KeyName.Equals(keyValuePair.Key));
                    var keyQueryCount = keyQuery.Count();
                    if (keyQueryCount > 1)
                    {
                        throw new Exception(@"Localization Database Seed Error - Key Query Count is > 1");
                    }
                    if (keyQueryCount.Equals(0))
                    {
                        key = new Key {
                            KeyName = keyValuePair.Key
                        };
                        context.Keys.Add(key);
                        context.SaveChanges();
                    }
                    else
                    {
                        key = keyQuery.First();
                    }

                    Value value           = null;
                    var   valueQuery      = context.Values.Where(a => a.Localization.Equals(dbLocalization) && a.Key.Equals(key));
                    var   valueQueryCount = valueQuery.Count();
                    if (valueQueryCount > 1)
                    {
                        throw new Exception(@"Localization Database Seed Error - Value Query Count is > 1");
                    }
                    if (valueQueryCount.Equals(0))
                    {
                        value = new Value
                        {
                            Key                  = key,
                            Localization         = dbLocalization,
                            KeyLocalizationValue = keyValuePair.Value
                        };
                        context.Values.Add(value);
                        context.SaveChanges();
                    }
                    else
                    {
                        value = valueQuery.First();
                        if (!value.KeyLocalizationValue.Equals(keyValuePair.Value))
                        {
                            value.KeyLocalizationValue = keyValuePair.Value;
                        }
                        context.SaveChanges();
                    }
                }
            }
        }