Exemple #1
0
        /// <summary>
        /// Generate dbo.Country. Write your time consuming task here
        /// </summary>
        /// <param name="s"></param>
        public void LTT_CountryCode(string s)
        {
            using (var ctx = new RT2020Entities())
            {
                ctx.Configuration.LazyLoadingEnabled = false;

                #region Generate missing dbo.Country from VWG.Community.Util.CountryCodes
                var dboCounttries = ctx.Country.ToList();
                var ccodes        = new CountryCodes();
                var codelist      = ccodes.GetList();
                OpenCC.Load();

                using (var scope = ctx.Database.BeginTransaction())
                {
                    try
                    {
                        foreach (var item in codelist)
                        {
                            //! CountryCode = ISO3166_1_Alpha_2,CountryName = CLDR_displayname
                            if (item.ISO3166_1_Alpha_2 == String.Empty)
                            {
                                continue;
                            }

                            // 2020.11.25 paulus: 再改番用 ISO3166_1_Alpha_2
                            //var exist = ctx.Country.Where(x => x.CountryCode == item.FIPS).FirstOrDefault();
                            var exist = ctx.Country.Where(x => x.CountryCode == item.ISO3166_1_Alpha_2).FirstOrDefault();
                            if (exist == null)
                            {
                                exist             = new Country();
                                exist.CountryId   = Guid.NewGuid();
                                exist.CountryCode = item.ISO3166_1_Alpha_2;
                                exist.CountryName = item.CLDR_displayname;
                                if (!String.IsNullOrEmpty(item.official_name_cn))
                                {
                                    exist.CountryName_Chs = item.official_name_cn;
                                    exist.CountryName_Cht = OpenCC.Convert(item.official_name_cn, OpenCCType.s2hk.ToString("g"));
                                }
                                ctx.Country.Add(exist);
                                ctx.SaveChanges();
                            }
                            else
                            {
                                exist.CountryName     = item.CLDR_displayname;
                                exist.CountryName_Chs = item.official_name_cn;
                                exist.CountryName_Cht = OpenCC.Convert(item.official_name_cn, OpenCCType.s2hk.ToString("g"));
                                ctx.SaveChanges();
                            }
                            _CurrentItem = exist.CountryName;
                        }
                        scope.Commit();
                    }
                    catch
                    {
                        scope.Rollback();
                    }
                }
                #endregion
            }
        }
Exemple #2
0
            public bool SaveJsondata()
            {
                bool result = false;

                if (this.Id != Guid.Empty)
                {
                    using (var ctx = new RT2020Entities())
                    {
                        try
                        {
                            var item = ctx.WorkplaceZone.Find(this.Id);
                            if (item != null)
                            {
                                item.MetadataXml = JsonConvert.SerializeObject(this.JsonData);
                                ctx.SaveChanges();
                                result = true;
                            }
                        }
                        catch { }
                    }
                }

                return(result);
            }