Пример #1
0
        private void CheckAddressData(CU_B_ADDRESS Item, CU_B_ADDRESS_EXT_AUS ItemExt)
        {
            short? cityCounter;
            string errorMessage;
            string areaCode = Item.AREA_CODE;
            string zipCode  = Item.ZIP_CODE;

            if (FoxDataService.CheckAddressCityData(ItemExt.STATE_CODE, Item.CITY_NAME, ref areaCode, ref zipCode, out cityCounter, out errorMessage))
            {
                Item.AREA_CODE    = areaCode;
                Item.ZIP_CODE     = zipCode;
                Item.CITY_COUNTER = cityCounter;
            }
            else
            {
                throw new InvalidOperationException(errorMessage);
            }

            if (ItemExt.STATE_CODE != null)
            {
                CM_S_STATE_EXT_AUS state = DBContext.CM_S_STATE_EXT_AUS.FirstOrDefault(E => E.STATE_CODE == ItemExt.STATE_CODE);
                if (state == null)
                {
                    throw new InvalidOperationException("State Code is not correct");
                }
            }
        }
Пример #2
0
        private void CreateAddressEntity(Address value, ref int?addressCounter, string customerCode = null)
        {
            CU_B_ADDRESS         Item    = EntityMapper.CreateEntity <CU_B_ADDRESS>();
            CU_B_ADDRESS_EXT_AUS ItemExt = EntityMapper.CreateEntity <CU_B_ADDRESS_EXT_AUS>();

            Item.CUSTOMER_CODE = ItemExt.CUSTOMER_CODE = value.CustomerCode ?? customerCode;

            IQueryable <CU_B_ADDRESS> qryAddresses = DBContext.CU_B_ADDRESS.Where(E => E.CUSTOMER_CODE == Item.CUSTOMER_CODE);

            addressCounter = qryAddresses.Any() ? Math.Max(qryAddresses.Max(E => E.ADDRESS_COUNTER) + 1, addressCounter.GetValueOrDefault(1)) : addressCounter.GetValueOrDefault(1);

            Item.ADDRESS_COUNTER = ItemExt.ADDRESS_COUNTER = addressCounter.Value;
            addressCounter       = addressCounter.Value + 1;
            Item.ROWGUID         = ItemExt.ROWGUID = Guid.NewGuid();

            EntityMapper.UpdateEntity(value, Item, ItemExt);
            CheckAddressData(Item, ItemExt);

            DBContext.CU_B_ADDRESS.Add(Item);
            DBContext.CU_B_ADDRESS_EXT_AUS.Add(ItemExt);
        }