コード例 #1
0
        public override void SaveData <T>(DbContext context, dynamic entity)
        {
            base.SaveData <T>(context, (T)entity);
            CustomersContext DBContext = (CustomersContext)context;
            CU_B_PROFILE     Profile   = DBContext.CU_B_PROFILE.FirstOrDefault(E => E.CUSTOMER_CODE == ID);

            if (Profile == null)
            {
                Profile = EntityMapper.CreateEntity <CU_B_PROFILE>();
                Profile.CUSTOMER_CODE = ID;
                DBContext.CU_B_PROFILE.Add(Profile);
            }
            Profile.FLG_OTHERCONTACT = IsOtherContactPreferred ? "Y" : "N";

            CU_B_PROFILE_ATTRIBUTE_LOOKUP ProfileAttribute = DBContext.CU_B_PROFILE_ATTRIBUTE_LOOKUP.FirstOrDefault(E => E.CUSTOMER_CODE == ID && E.ATTRIBUTE_CODE == "SMF");

            if (ProfileAttribute != null)
            {
                DBContext.CU_B_PROFILE_ATTRIBUTE_LOOKUP.Remove(ProfileAttribute);
            }

            ProfileAttribute = EntityMapper.CreateEntity <CU_B_PROFILE_ATTRIBUTE_LOOKUP>();
            ProfileAttribute.CUSTOMER_CODE  = ID;
            ProfileAttribute.ATTRIBUTE_CODE = "SMF";
            ProfileAttribute.VALUE_CODE     = EnumHelper.GetEnumValue <PreferredContactMethods>(PreferredContactMethod);
            DBContext.CU_B_PROFILE_ATTRIBUTE_LOOKUP.Add(ProfileAttribute);

            CU_B_PROFILE_ATTRIBUTE_LOOKUP OtheContactIsPrimaryAttribute = DBContext.CU_B_PROFILE_ATTRIBUTE_LOOKUP.FirstOrDefault(E => E.CUSTOMER_CODE == ID && E.ATTRIBUTE_CODE == "PCT");

            if (OtheContactIsPrimaryAttribute != null)
            {
                DBContext.CU_B_PROFILE_ATTRIBUTE_LOOKUP.Remove(OtheContactIsPrimaryAttribute);
            }

            OtheContactIsPrimaryAttribute = EntityMapper.CreateEntity <CU_B_PROFILE_ATTRIBUTE_LOOKUP>();
            OtheContactIsPrimaryAttribute.CUSTOMER_CODE  = ID;
            OtheContactIsPrimaryAttribute.ATTRIBUTE_CODE = "PCT";
            OtheContactIsPrimaryAttribute.VALUE_CODE     = IsOtherContactPreferred ? "02" : "01";
            DBContext.CU_B_PROFILE_ATTRIBUTE_LOOKUP.Add(OtheContactIsPrimaryAttribute);

            CU_B_PROFILE_ATTRIBUTE_LOOKUP PreferredTimeOfContactAttribute = DBContext.CU_B_PROFILE_ATTRIBUTE_LOOKUP.FirstOrDefault(E => E.CUSTOMER_CODE == ID && E.ATTRIBUTE_CODE == "CTP");

            if (PreferredTimeOfContactAttribute != null)
            {
                DBContext.CU_B_PROFILE_ATTRIBUTE_LOOKUP.Remove(PreferredTimeOfContactAttribute);
            }

            PreferredTimeOfContactAttribute = EntityMapper.CreateEntity <CU_B_PROFILE_ATTRIBUTE_LOOKUP>();
            PreferredTimeOfContactAttribute.CUSTOMER_CODE  = ID;
            PreferredTimeOfContactAttribute.ATTRIBUTE_CODE = "CTP";
            PreferredTimeOfContactAttribute.VALUE_CODE     = PreferredTimeOfContactCode ?? "06";
            DBContext.CU_B_PROFILE_ATTRIBUTE_LOOKUP.Add(PreferredTimeOfContactAttribute);
        }
コード例 #2
0
        public override void LoadData <T>(DbContext context, dynamic entity)
        {
            base.LoadData <T>(context, (T)entity);

            if (entity is CU_B_ADDRESS_BOOK)
            {
                CustomersContext DBContext = (CustomersContext)context;
                CU_B_PROFILE_ATTRIBUTE_LOOKUP ProfileAttribute = DBContext.CU_B_PROFILE_ATTRIBUTE_LOOKUP.FirstOrDefault(E => E.CUSTOMER_CODE == ID && E.ATTRIBUTE_CODE == "SMF");
                PreferredContactMethod = EnumHelper.GetEnumFromValue <PreferredContactMethods>(ProfileAttribute?.VALUE_CODE, PreferredContactMethods.Any);
                CU_B_PROFILE_ATTRIBUTE_LOOKUP Attribute = DBContext.CU_B_PROFILE_ATTRIBUTE_LOOKUP.FirstOrDefault(E => E.CUSTOMER_CODE == ID && E.ATTRIBUTE_CODE == "PCT");
                IsOtherContactPreferred = Attribute?.VALUE_CODE == "02";
                CU_B_PROFILE_ATTRIBUTE_LOOKUP PreferredTimeOfContactAttribute = DBContext.CU_B_PROFILE_ATTRIBUTE_LOOKUP.FirstOrDefault(E => E.CUSTOMER_CODE == ID && E.ATTRIBUTE_CODE == "CTP");
                PreferredTimeOfContactCode = PreferredTimeOfContactAttribute?.VALUE_CODE ?? "06";

                List <Address> Addrs = new List <Address>();
                foreach (CU_B_ADDRESS Item in ((CU_B_ADDRESS_BOOK)entity).CU_B_ADDRESS.OrderBy(E => E.ADDRESS_COUNTER))
                {
                    try
                    {
                        Addrs.Add(new Address(Item));
                    }
                    catch
                    {
                    }
                }
                Addresses = Addrs.ToArray();
            }
            else if (entity is CU_B_LEAD_EXT_AUS)
            {
                CustomersContext DBContext = (CustomersContext)context;
                string           XID       = entity.XID;
                List <Address>   Addrs     = new List <Address>();
                int AddressCounter         = 1;
                foreach (CU_B_LEAD_ADDRESS_EXT_AUS Item in DBContext.CU_B_LEAD_ADDRESS_EXT_AUS.Where(E => E.XID == XID).OrderBy(E => E.ADDRESSTYPE))
                {
                    try
                    {
                        Address address = EntityMapper.Map <Address, CU_B_LEAD_ADDRESS_EXT_AUS>(DBContext, Item);
                        if (Item.ADDRESSTYPE == "1")                         //Residential
                        {
                            address.IsHomeAddress    = true;
                            address.IsMailingDefault = true;
                            address.IsInvoiceDefault = true;
                        }
                        else if (Item.ADDRESSTYPE == "2")                         //Postal
                        {
                            address.IsHomeAddress    = false;
                            address.IsMailingDefault = true;
                        }

                        address.AddressCounter = AddressCounter++;
                        Addrs.Add(address);
                    }
                    catch
                    {
                    }
                }

                //Ensure existance of the home address
                if (Addrs.Count == 1 || (Addrs.Count > 0 && !Addrs.Any(E => E.IsHomeAddress)))
                {
                    Addrs[0].IsHomeAddress    = true;
                    Addrs[0].IsMailingDefault = true;
                    Addrs[0].IsInvoiceDefault = true;
                }

                Address HomeAddress    = Addrs.FirstOrDefault(E => E.IsHomeAddress);
                Address MailingAddress = Addrs.FirstOrDefault(E => !E.IsHomeAddress && E.IsMailingDefault);
                HomeAddress.IsMailingDefault = (MailingAddress == null);

                Addresses = Addrs.ToArray();
            }
        }