Example #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");
                }
            }
        }
Example #2
0
 public Address(CU_B_ADDRESS Entity) : base(Entity)
 {
     try
     {
         IsHomeVisitDefault   = Entity.CU_B_ADDRESS_EXT_AUS?.FLG_HOME_VISIT_DEFAULT == "Y";
         HomeVisitContactName = Entity.CU_B_ADDRESS_EXT_AUS?.HOMEVISIT_CONTACTNAME;
         StateCode            = Entity.CU_B_ADDRESS_EXT_AUS?.STATE_CODE;
     }
     catch
     {
     }
 }
 public AddressExtended(CU_B_ADDRESS Entity) : base(Entity)
 {
     try
     {
         //This cause EF doesn't support FK on multiple nullable fields
         StateDescription = StateCode;
         //StateDescription = Entity.CU_B_ADDRESS_EXT_AUS?.CM_S_STATE_EXT_AUS?.STATE_NAME;
     }
     catch (Exception)
     {
     }
 }
Example #4
0
        public void AddressPut(Guid rowId, [FromBody] Address value)
        {
            CU_B_ADDRESS Item = DBContext.CU_B_ADDRESS.SingleOrDefault(E => E.ROWGUID == rowId);

            if (Item == null)
            {
                throw new NotFoundException($"No address found with RowId:{rowId}");
            }

            EntityMapper.UpdateEntity(value, Item, Item.CU_B_ADDRESS_EXT_AUS);
            EntityMapper.CheckEntityRowId(Item, Item.CU_B_ADDRESS_EXT_AUS, rowId);

            DBContext.SaveChanges();
        }
 public AddressBase(CU_B_ADDRESS Entity) : base(Entity.ROWGUID)
 {
     CustomerCode     = Entity.CUSTOMER_CODE;
     AddressCounter   = Entity.ADDRESS_COUNTER;
     IsHomeAddress    = (AddressCounter == 1);
     IsMailingDefault = (Entity.FLG_LETTER_DEFAULT == "Y");
     IsInvoiceDefault = (Entity.FLG_INVOICE_DEFAULT == "Y");
     IsOtherContact   = (Entity.FLG_OTHER_CONTACT == "Y");
     Address          = new string[] { Entity.ADDRESS_LINE1, Entity.ADDRESS_LINE2, Entity.ADDRESS_LINE3, Entity.ADDRESS_LINE4 };
     CountryCode      = Entity.COUNTRY_CODE;
     AreaCode         = Entity.AREA_CODE;
     ZipCode          = Entity.ZIP_CODE;
     City             = Entity.CITY_NAME;
     Locality         = Entity.LOCALITY;
     POBox            = Entity.PO_BOX;
     Phones           = new string[] { Entity.PHONE1, Entity.PHONE2, Entity.PHONE3 };
     Mobile           = Entity.MOBILE;
     EMail            = Entity.EMAIL;
 }
        public override void LoadData <T>(DbContext context, dynamic entity)
        {
            base.LoadData <T>(context, (T)entity);
            CustomersContext DBContext = (CustomersContext)context;

            GenderDescription     = DBContext.SY_GENDER.FirstOrDefault(E => E.GENDER_CODE == GenderCode)?.GENDER_DESCR;
            SalutationDescription = DBContext.CU_S_SALUTATION.FirstOrDefault(E => E.SALUTATION_CODE == SalutationCode)?.SALUTATION_DESCR;
            StatusDescription     = DBContext.CU_S_STATUS.FirstOrDefault(E => E.STATUS_CODE == StatusCode)?.STATUS_DESCR?.Trim();          //CU_S_STATUS


            if (entity is CU_B_ADDRESS_BOOK || (entity is LEAD_CUSTOMER && entity.IS_LEAD == 0))
            {
                CU_B_ADDRESS ADDR = DBContext.CU_B_ADDRESS.FirstOrDefault(E => E.CUSTOMER_CODE == ID && E.ADDRESS_COUNTER == 1);
                if (ADDR != null)
                {
                    MainAddress = new Address(ADDR);
                }

                LastHAItemHistory = LoadLastHAItems(DBContext, entity);
            }
        }
Example #7
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);
        }
Example #8
0
        public ActionResult <CustomerExtended> Put(string id, [FromBody] Customer value)
        {
            CheckCustomerAge(value?.Birthday);
            CU_B_ADDRESS_BOOK Item = DBContext.CU_B_ADDRESS_BOOK.SingleOrDefault(E => E.COMPANY_CODE == Settings.Value.CompanyCode && E.DIVISION_CODE == Settings.Value.DivisionCode && E.CUSTOMER_CODE == id);

            if (Item == null)
            {
                throw new NotFoundException($"No customer found with id:{id}");
            }

            if (string.IsNullOrWhiteSpace(value.ID))
            {
                value.ID = id;
            }

            EntityMapper.UpdateEntity(value, Item, Item.CU_B_ADDRESS_BOOK_EXT_AUS);

            value.SaveData <CU_B_ADDRESS_BOOK>(DBContext, Item);

            if (value.Addresses != null)
            {
                int?         AddressCounter   = null;
                CU_B_ADDRESS AddressEntity    = null;
                Address      HomeAddr         = value.Addresses.FirstOrDefault(E => E.IsHomeAddress);
                Address      InvoiceAddr      = value.Addresses.FirstOrDefault(E => !E.IsHomeAddress && E.IsInvoiceDefault);
                Address      MailingAddr      = value.Addresses.FirstOrDefault(E => !E.IsHomeAddress && E.IsMailingDefault);
                Address      OtherContactAddr = value.Addresses.FirstOrDefault(E => !E.IsHomeAddress && E.IsOtherContact);
                Address      HomeVisitAddr    = value.Addresses.FirstOrDefault(E => !E.IsHomeAddress && E.IsHomeVisitDefault);

                if (HomeAddr != null)
                {
                    HomeAddr.IsInvoiceDefault   = (InvoiceAddr == null);
                    HomeAddr.IsMailingDefault   = (MailingAddr == null);
                    HomeAddr.IsHomeVisitDefault = (HomeVisitAddr == null);
                    if (HomeAddr.RowGuid != Guid.Empty)
                    {
                        AddressEntity = DBContext.CU_B_ADDRESS.FirstOrDefault(E => E.ROWGUID == HomeAddr.RowGuid);
                    }

                    if (AddressEntity == null)
                    {
                        CreateAddressEntity(HomeAddr, ref AddressCounter, Item.CUSTOMER_CODE);
                    }
                    else
                    {
                        EntityMapper.UpdateEntity(HomeAddr, AddressEntity, AddressEntity.CU_B_ADDRESS_EXT_AUS);
                        CheckAddressData(AddressEntity, AddressEntity.CU_B_ADDRESS_EXT_AUS);
                        AddressCounter = AddressEntity.ADDRESS_COUNTER + 1;
                    }
                }

                if (InvoiceAddr != null)
                {
                    AddressEntity = null;
                    if (InvoiceAddr.RowGuid != Guid.Empty)
                    {
                        AddressEntity = DBContext.CU_B_ADDRESS.FirstOrDefault(E => E.ROWGUID == InvoiceAddr.RowGuid);
                    }

                    if (AddressEntity == null)
                    {
                        CreateAddressEntity(InvoiceAddr, ref AddressCounter, Item.CUSTOMER_CODE);
                    }
                    else
                    {
                        EntityMapper.UpdateEntity(InvoiceAddr, AddressEntity, AddressEntity.CU_B_ADDRESS_EXT_AUS);
                        CheckAddressData(AddressEntity, AddressEntity.CU_B_ADDRESS_EXT_AUS);
                        AddressCounter = AddressEntity.ADDRESS_COUNTER + 1;
                    }
                }

                if (MailingAddr != null)
                {
                    AddressEntity = null;
                    if (MailingAddr.RowGuid != Guid.Empty)
                    {
                        AddressEntity = DBContext.CU_B_ADDRESS.FirstOrDefault(E => E.ROWGUID == MailingAddr.RowGuid);
                    }

                    if (AddressEntity == null)
                    {
                        CreateAddressEntity(MailingAddr, ref AddressCounter, Item.CUSTOMER_CODE);
                    }
                    else
                    {
                        EntityMapper.UpdateEntity(MailingAddr, AddressEntity, AddressEntity.CU_B_ADDRESS_EXT_AUS);
                        CheckAddressData(AddressEntity, AddressEntity.CU_B_ADDRESS_EXT_AUS);
                        AddressCounter = AddressEntity.ADDRESS_COUNTER + 1;
                    }
                }

                if (OtherContactAddr != null)
                {
                    AddressEntity = null;
                    if (OtherContactAddr.RowGuid != Guid.Empty)
                    {
                        AddressEntity = DBContext.CU_B_ADDRESS.FirstOrDefault(E => E.ROWGUID == OtherContactAddr.RowGuid);
                    }

                    if (AddressEntity == null)
                    {
                        CreateAddressEntity(OtherContactAddr, ref AddressCounter, Item.CUSTOMER_CODE);
                    }
                    else
                    {
                        EntityMapper.UpdateEntity(OtherContactAddr, AddressEntity, AddressEntity.CU_B_ADDRESS_EXT_AUS);
                        AddressCounter = AddressEntity.ADDRESS_COUNTER + 1;
                    }
                }

                if (HomeVisitAddr != null)
                {
                    AddressEntity = null;
                    if (HomeVisitAddr.RowGuid != Guid.Empty)
                    {
                        AddressEntity = DBContext.CU_B_ADDRESS.FirstOrDefault(E => E.ROWGUID == HomeVisitAddr.RowGuid);
                    }

                    if (AddressEntity == null)
                    {
                        CreateAddressEntity(HomeVisitAddr, ref AddressCounter, Item.CUSTOMER_CODE);
                    }
                    else
                    {
                        EntityMapper.UpdateEntity(HomeVisitAddr, AddressEntity, AddressEntity.CU_B_ADDRESS_EXT_AUS);
                        CheckAddressData(AddressEntity, AddressEntity.CU_B_ADDRESS_EXT_AUS);
                        AddressCounter = AddressEntity.ADDRESS_COUNTER + 1;
                    }
                }
            }

            DBContext.SaveChanges();

            return(Get(id));
        }