Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Добавить или править
        /// </summary>
        /// <param name="ReferenceCountry"></param>
        /// <returns></returns>
        public int SaveReferenceCountry(ReferenceCountry ReferenceCountry)
        {
            ReferenceCountry dbEntry;

            if (ReferenceCountry.IDCountry == 0)
            {
                dbEntry = new ReferenceCountry()
                {
                    IDCountry = 0,
                    Country   = ReferenceCountry.Country,
                    Code      = ReferenceCountry.Code
                };
                context.ReferenceCountry.Add(dbEntry);
            }
            else
            {
                dbEntry = context.ReferenceCountry.Find(ReferenceCountry.IDCountry);
                if (dbEntry != null)
                {
                    dbEntry.Country = ReferenceCountry.Country;
                    dbEntry.Code    = ReferenceCountry.Code;
                }
            }
            try
            {
                context.SaveChanges();
            }
            catch (Exception e)
            {
                LogRW.LogError(e, "SaveReferenceCountry", eventID);
                return(-1);
            }
            return(dbEntry.IDCountry);
        }
        public void Add_ValidCountryNotExists_FetchNewCountry()
        {
            var notExistsCountryCode = PreDefinedData.GetNotExistsCountryCode();
            var newReferenceCountry  = new ReferenceCountry
            {
                Code     = notExistsCountryCode,
                LongName = notExistsCountryCode
            };

            UnitOfWork.ReferenceCountries.Add(newReferenceCountry);
            UnitOfWork.Complete();

            var result = UnitOfWork.ReferenceCountries.Get(newReferenceCountry.Id);

            Assert.That(result, Is.Not.Null);

            AssertHelper.AreObjectsEqual(newReferenceCountry, result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Удалить
        /// </summary>
        /// <param name="IDCountry"></param>
        /// <returns></returns>
        public ReferenceCountry DeleteReferenceCountry(int IDCountry)
        {
            ReferenceCountry dbEntry = context.ReferenceCountry.Find(IDCountry);

            if (dbEntry != null)
            {
                context.ReferenceCountry.Remove(dbEntry);
                try
                {
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    LogRW.LogError(e, "DeleteReferenceCountry", eventID);
                    return(null);
                }
            }
            return(dbEntry);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Сохранить
 /// </summary>
 /// <param name="reference_country"></param>
 /// <returns></returns>
 public int SaveReferenceCountry(ReferenceCountry reference_country)
 {
     return(this.rep_country.SaveReferenceCountry(reference_country));
 }