Example #1
0
        /// <summary>
        /// Получить id страны из справочника
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        protected int DefinitionIDCountry(Code_Country code)
        {
            if (code == null)
            {
                return(0);
            }
            if (code.Code <= 0)
            {
                return(0);
            }
            ReferenceCountry ref_code = g_ref.GetReferenceCountryOfCode(code.Code);

            if (ref_code == null)
            {
                ReferenceCountry new_rc = new ReferenceCountry()
                {
                    IDCountry = 0,
                    Country   = code.Country,
                    Code      = code.Code,
                };
                int res = g_ref.SaveReferenceCountry(new_rc);
                if (res > 0)
                {
                    return(res);
                }
                else
                {
                    return(0);
                }
            }
            return(ref_code.IDCountry);
        }
Example #2
0
        /// <summary>
        /// Получить id страны по коду СНГ и стран балтии
        /// </summary>
        /// <param name="code_country_sng"></param>
        /// <returns></returns>
        public int DefinitionIDCountrySNG(int code_country_sng)
        {
            Code_Country code = rw_ref.GetCountryOfCodeSNG(code_country_sng);

            return(DefinitionIDCountry(code));
            //if (code != null)
            //{
            //    if (code.Code > 0)
            //    {
            //        ReferenceCountry ref_code = g_ref.GetReferenceCountryOfCode(code.Code);
            //        if (ref_code == null)
            //        {
            //            ReferenceCountry new_rc = new ReferenceCountry() {
            //                IDCountry = 0,
            //                Country = code.Country,
            //                Code = code.Code,
            //            };
            //            int res = g_ref.SaveReferenceCountry(new_rc);
            //            if (res > 0) { return res; }
            //            else return 0;
            //        }
            //        return ref_code.IDCountry;
            //    }
            //}
            //return 0;
        }
Example #3
0
        /// <summary>
        /// Добавить строку ISO3166
        /// </summary>
        /// <param name="Code_Country"></param>
        /// <returns></returns>
        public int SaveCode_Country(Code_Country Code_Country)
        {
            Code_Country dbEntry;

            if (Code_Country.ID == 0)
            {
                dbEntry = new Code_Country()
                {
                    ID         = 0,
                    Country    = Code_Country.Country,
                    Alpha_2    = Code_Country.Alpha_2,
                    Alpha_3    = Code_Country.Alpha_3,
                    Code       = Code_Country.Code,
                    ISO3166_2  = Code_Country.ISO3166_2,
                    IDState    = Code_Country.IDState,
                    CodeEurope = Code_Country.CodeEurope
                };
                context.Code_Country.Add(dbEntry);
            }
            else
            {
                dbEntry = context.Code_Country.Find(Code_Country.ID);
                if (dbEntry != null)
                {
                    dbEntry.Country    = Code_Country.Country;
                    dbEntry.Alpha_2    = Code_Country.Alpha_2;
                    dbEntry.Alpha_3    = Code_Country.Alpha_3;
                    dbEntry.Code       = Code_Country.Code;
                    dbEntry.ISO3166_2  = Code_Country.ISO3166_2;
                    dbEntry.IDState    = Code_Country.IDState;
                    dbEntry.CodeEurope = Code_Country.CodeEurope;
                }
            }
            try
            {
                context.SaveChanges();
            }
            catch (Exception e)
            {
                LogRW.LogError(e, "SaveCode_Country", eventID);
                return(-1);
            }
            return(dbEntry.ID);
        }
Example #4
0
        /// <summary>
        /// Удалить строку ISO3166
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public Code_Country DeleteCode_Country(int ID)
        {
            Code_Country dbEntry = context.Code_Country.Find(ID);

            if (dbEntry != null)
            {
                context.Code_Country.Remove(dbEntry);
                try
                {
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    LogRW.LogError(e, "DeleteCode_Country", eventID);
                    return(null);
                }
            }
            return(dbEntry);
        }
Example #5
0
        /// <summary>
        /// Получить id страны по коду iso
        /// </summary>
        /// <param name="code_iso"></param>
        /// <returns></returns>
        public int DefinitionIDCountryCode(int code_iso)
        {
            Code_Country code = rw_ref.GetCountryOfCode(code_iso);

            return(DefinitionIDCountry(code));
        }