private void SaveMemberAddress(Guid memberId, string address, string workPhone, string homePhone, string fax, string otherPhone, string pager, Guid addressType) { using (var ctx = new EF6.RT2020Entities()) { string query = "MemberId = '" + memberId.ToString() + "' AND AddressTypeId = '" + addressType.ToString() + "'"; var objAddress = ctx.MemberAddress.Where(x => x.MemberId == memberId && x.AddressTypeId == addressType).FirstOrDefault(); if (objAddress == null) { objAddress = new EF6.MemberAddress(); objAddress.AddressId = Guid.NewGuid(); objAddress.AddressTypeId = addressType; objAddress.MemberId = memberId; ctx.MemberAddress.Add(objAddress); } objAddress.Address = address; objAddress.PostalCode = string.Empty; objAddress.CountryId = Guid.Empty; objAddress.ProvinceId = Guid.Empty; objAddress.CityId = Guid.Empty; objAddress.District = string.Empty; objAddress.Mailing = false; objAddress.PhoneTag1 = PhoneTagEx.GetPhoneTagIdByPriority(1); objAddress.PhoneTag1Value = workPhone; objAddress.PhoneTag2 = PhoneTagEx.GetPhoneTagIdByPriority(2); objAddress.PhoneTag2Value = homePhone; objAddress.PhoneTag3 = PhoneTagEx.GetPhoneTagIdByPriority(3); objAddress.PhoneTag3Value = fax; objAddress.PhoneTag4 = PhoneTagEx.GetPhoneTagIdByPriority(4); objAddress.PhoneTag4Value = otherPhone; objAddress.PhoneTag5 = PhoneTagEx.GetPhoneTagIdByPriority(5); objAddress.PhoneTag5Value = pager; ctx.SaveChanges(); } }
private bool DoPromote() { bool result = false; using (var ctx = new EF6.RT2020Entities()) { using (var scope = ctx.Database.BeginTransaction()) { try { foreach (var item in dsMemberList) { var id = Guid.Empty; #region Save Member Core Data var member = ctx.Member.Where(x => x.MemberNumber == item.VIPNO).FirstOrDefault(); if (member == null) { #region add new Member member = new EF6.Member(); member.MemberId = Guid.NewGuid(); member.MemberNumber = item.VIPNO; member.Status = (int)EnumHelper.Status.Active; member.CreatedBy = ConfigHelper.CurrentUserId; member.CreatedOn = DateTime.Now; member.Retired = false; ctx.Member.Add(member); #endregion } #region Check the temp vip DLFLAG if (item.DLFLAG.Trim().Length > 0) { switch (item.DLFLAG.Trim().ToUpper()) { case "A": case "": default: member.Status = (int)EnumHelper.Status.Active; break; case "M": member.Status = (int)EnumHelper.Status.Modified; break; case "D": member.Status = (int)EnumHelper.Status.Deleted; break; case "I": member.Status = (int)EnumHelper.Status.Inactive; break; } } else { member.Status = ctx.Entry(member).State == EntityState.Added ? (int)EnumHelper.Status.Active : (int)EnumHelper.Status.Modified; } #endregion #region Option 2. Migrate Temporary VIP to Permanent VIP With Delete //if (canDelete) //{ // member.Status = (int)EnumHelper.Status.Deleted; //} #endregion #region update Member core data member.WorkplaceId = Guid.Empty; member.ClassId = MemberHelper.GetClassId(item.PHONEBOOK); //Class member.GroupId = MemberHelper.GetGroupId(item.GROUP); member.MemberInitial = item.NNAME; // Nick Name member.SalutationId = MemberHelper.GetSaluteId(item.SALUTE); member.FirstName = item.FNAME; // First Name member.LastName = item.LNAME; // Last Name member.FullName = item.FNAME + "," + item.LNAME; // Full Name member.FullName_Chs = item.CNAME; // Chinese Name (S) member.FullName_Cht = item.CNAME; // Chinese Name (T) member.JobTitleId = JobTitleEx.GetJobTitleIdByName(item.TITLE); member.AssignedTo = Guid.Empty; member.Remarks = item.REMARKS; member.NormalDiscount = (decimal)item.NRDISC; member.DownloadToPOS = true; member.ModifiedBy = ConfigHelper.CurrentUserId; member.ModifiedOn = DateTime.Now; if (member.Status == (int)EnumHelper.Status.Deleted || member.Status == (int)EnumHelper.Status.Inactive) { member.Retired = false; member.RetiredBy = Guid.Empty; member.RetiredOn = new DateTime(1900, 1, 1); } #endregion ctx.SaveChanges(); id = member.MemberId; #endregion #region SaveMemberAddresses(memberId, item); #region English Address var enAddressTypeId = MemberAddressTypeEx.GetIdByCode("ADDR_EN"); string enAddress = item.ADDRESS1 + Environment.NewLine + item.ADDRESS2 + Environment.NewLine + item.ADDRESS3 + Environment.NewLine + item.ADDRESS4; var addressEn = ctx.MemberAddress.Where(x => x.MemberId == id && x.AddressTypeId == enAddressTypeId).FirstOrDefault(); if (addressEn == null) { addressEn = new EF6.MemberAddress(); addressEn.AddressId = Guid.NewGuid(); addressEn.AddressTypeId = enAddressTypeId; addressEn.MemberId = id; ctx.MemberAddress.Add(addressEn); } addressEn.Address = enAddress; addressEn.PostalCode = string.Empty; addressEn.CountryId = Guid.Empty; addressEn.ProvinceId = Guid.Empty; addressEn.CityId = Guid.Empty; addressEn.District = string.Empty; addressEn.Mailing = false; addressEn.PhoneTag1 = PhoneTagEx.GetPhoneTagIdByPriority(1); addressEn.PhoneTag1Value = item.TELW; addressEn.PhoneTag2 = PhoneTagEx.GetPhoneTagIdByPriority(2); addressEn.PhoneTag2Value = item.TELH; addressEn.PhoneTag3 = PhoneTagEx.GetPhoneTagIdByPriority(3); addressEn.PhoneTag3Value = item.FAX; addressEn.PhoneTag4 = PhoneTagEx.GetPhoneTagIdByPriority(4); addressEn.PhoneTag4Value = item.TELOTHER; addressEn.PhoneTag5 = PhoneTagEx.GetPhoneTagIdByPriority(5); addressEn.PhoneTag5Value = item.TELP; ctx.SaveChanges(); #endregion #region Chinese Address var cnAddressTypeId = MemberAddressTypeEx.GetIdByCode("ADDR_CN"); string cnAddress = item.ADDRESS1C + Environment.NewLine + item.ADDRESS2C + Environment.NewLine + item.ADDRESS3C + Environment.NewLine + item.ADDRESS4C; var addressCn = ctx.MemberAddress.Where(x => x.MemberId == id && x.AddressTypeId == cnAddressTypeId).FirstOrDefault(); if (addressCn == null) { addressCn = new EF6.MemberAddress(); addressCn.AddressId = Guid.NewGuid(); addressCn.AddressTypeId = cnAddressTypeId; addressCn.MemberId = id; ctx.MemberAddress.Add(addressCn); } addressCn.Address = cnAddress; addressCn.PostalCode = string.Empty; addressCn.CountryId = Guid.Empty; addressCn.ProvinceId = Guid.Empty; addressCn.CityId = Guid.Empty; addressCn.District = string.Empty; addressCn.Mailing = false; addressCn.PhoneTag1 = PhoneTagEx.GetPhoneTagIdByPriority(1); addressCn.PhoneTag1Value = item.TELW; addressCn.PhoneTag2 = PhoneTagEx.GetPhoneTagIdByPriority(2); addressCn.PhoneTag2Value = item.TELH; addressCn.PhoneTag3 = PhoneTagEx.GetPhoneTagIdByPriority(3); addressCn.PhoneTag3Value = item.FAX; addressCn.PhoneTag4 = PhoneTagEx.GetPhoneTagIdByPriority(4); addressCn.PhoneTag4Value = item.TELOTHER; addressCn.PhoneTag5 = PhoneTagEx.GetPhoneTagIdByPriority(5); addressCn.PhoneTag5Value = item.TELP; ctx.SaveChanges(); #endregion #endregion #region SaveMemberSmartTags(memberId, item); HACK: 呢部份係 hard coded,如果 dbo.SmartTag4Member 唔一樣就會出事 #region 1.Grade //SaveMemberSmartTag(memberId, GetSmartTagId("Grade", 1), objTempVip.GRADE); // 2021.01.28 paulus: 由 GetIdByTagCodeAndPriority 改為 GetIdByPriority,咁樣日後個 TagCode 改咗都照 update 倒 var tagId = SmartTag4MemberEx.GetIdByPriority(1); if (tagId != Guid.Empty) { var oTag1 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag1 == null) { oTag1 = new EF6.MemberSmartTag(); oTag1.SmartTagId = Guid.NewGuid(); oTag1.MemberId = id; oTag1.TagId = tagId; ctx.MemberSmartTag.Add(oTag1); } oTag1.SmartTagValue = item.GRADE; ctx.SaveChanges(); } #endregion #region 2.Sex //SaveMemberSmartTag(memberId, GetSmartTagId("Sex", 2), objTempVip.SEX); tagId = SmartTag4MemberEx.GetIdByPriority(2); if (tagId != Guid.Empty) { var oTag2 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag2 == null) { oTag2 = new EF6.MemberSmartTag(); oTag2.SmartTagId = Guid.NewGuid(); oTag2.MemberId = id; oTag2.TagId = tagId; ctx.MemberSmartTag.Add(oTag2); } oTag2.SmartTagValue = item.SEX; ctx.SaveChanges(); } #endregion #region 3.Race //SaveMemberSmartTag(memberId, GetSmartTagId("Race", 3), objTempVip.RACE); tagId = SmartTag4MemberEx.GetIdByPriority(3); if (tagId != Guid.Empty) { var oTag3 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag3 == null) { oTag3 = new EF6.MemberSmartTag(); oTag3.SmartTagId = Guid.NewGuid(); oTag3.MemberId = id; oTag3.TagId = tagId; ctx.MemberSmartTag.Add(oTag3); } oTag3.SmartTagValue = item.RACE; ctx.SaveChanges(); } #endregion #region 4.Age Group //SaveMemberSmartTag(memberId, GetSmartTagId("Age Group", 4), objTempVip.AGE_GROUP); tagId = SmartTag4MemberEx.GetIdByPriority(4); if (tagId != Guid.Empty) { var oTag4 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag4 == null) { oTag4 = new EF6.MemberSmartTag(); oTag4.SmartTagId = Guid.NewGuid(); oTag4.MemberId = id; oTag4.TagId = tagId; ctx.MemberSmartTag.Add(oTag4); } oTag4.SmartTagValue = item.AGE_GROUP; ctx.SaveChanges(); } #endregion #region 5.CodeNumber //this.SaveMemberSmartTag(memberId, GetSmartTagId("CodeNumber", 5), objTempVip.CODENUM); tagId = SmartTag4MemberEx.GetIdByPriority(5); if (tagId != Guid.Empty) { var oTag5 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag5 == null) { oTag5 = new EF6.MemberSmartTag(); oTag5.SmartTagId = Guid.NewGuid(); oTag5.MemberId = id; oTag5.TagId = tagId; ctx.MemberSmartTag.Add(oTag5); } oTag5.SmartTagValue = item.CODENUM; ctx.SaveChanges(); } #endregion #region 6.LoyaltyNum //this.SaveMemberSmartTag(memberId, GetSmartTagId("LoyaltyNum", 6), objTempVip.LOYALTYNUM); tagId = SmartTag4MemberEx.GetIdByPriority(6); if (tagId != Guid.Empty) { var oTag6 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag6 == null) { oTag6 = new EF6.MemberSmartTag(); oTag6.SmartTagId = Guid.NewGuid(); oTag6.MemberId = id; oTag6.TagId = tagId; ctx.MemberSmartTag.Add(oTag6); } oTag6.SmartTagValue = item.LOYALTYNUM; ctx.SaveChanges(); } #endregion #region 7.Profile //this.SaveMemberSmartTag(memberId, GetSmartTagId("Profile", 7), objTempVip.PROFILE); tagId = SmartTag4MemberEx.GetIdByPriority(7); if (tagId != Guid.Empty) { var oTag7 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag7 == null) { oTag7 = new EF6.MemberSmartTag(); oTag7.SmartTagId = Guid.NewGuid(); oTag7.MemberId = id; oTag7.TagId = tagId; ctx.MemberSmartTag.Add(oTag7); } oTag7.SmartTagValue = item.PROFILE; ctx.SaveChanges(); } #endregion #region 8.DOB //this.SaveMemberSmartTag(memberId, GetSmartTagId("DOB", 8), objTempVip.DATE_BIRTH.Value.ToString("yyyy-MM-dd")); tagId = SmartTag4MemberEx.GetIdByPriority(8); if (tagId != Guid.Empty) { var oTag8 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag8 == null) { oTag8 = new EF6.MemberSmartTag(); oTag8.SmartTagId = Guid.NewGuid(); oTag8.MemberId = id; oTag8.TagId = tagId; ctx.MemberSmartTag.Add(oTag8); } oTag8.SmartTagValue = item.DATE_BIRTH.HasValue ? item.DATE_BIRTH.Value.ToString("yyyy-MM-dd") : ""; ctx.SaveChanges(); } #endregion #region 9.DOR //this.SaveMemberSmartTag(memberId, GetSmartTagId("DOR", 9), objTempVip.DATE_REGIS.Value.ToString("yyyy-MM-dd")); tagId = SmartTag4MemberEx.GetIdByPriority(9); if (tagId != Guid.Empty) { var oTag9 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag9 == null) { oTag9 = new EF6.MemberSmartTag(); oTag9.SmartTagId = Guid.NewGuid(); oTag9.MemberId = id; oTag9.TagId = tagId; ctx.MemberSmartTag.Add(oTag9); } oTag9.SmartTagValue = item.DATE_REGIS.HasValue ? item.DATE_REGIS.Value.ToString("yyyy-MM-dd") : ""; ctx.SaveChanges(); } #endregion #region 10.HKID //this.SaveMemberSmartTag(memberId, GetSmartTagId("HKID", 10), objTempVip.ID_NO); tagId = SmartTag4MemberEx.GetIdByPriority(10); if (tagId != Guid.Empty) { var oTag10 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag10 == null) { oTag10 = new EF6.MemberSmartTag(); oTag10.SmartTagId = Guid.NewGuid(); oTag10.MemberId = id; oTag10.TagId = tagId; ctx.MemberSmartTag.Add(oTag10); } oTag10.SmartTagValue = item.ID_NO; ctx.SaveChanges(); } #endregion #region 11.Nationalit //this.SaveMemberSmartTag(memberId, GetSmartTagId("Nationalit", 11), objTempVip.NATION); tagId = SmartTag4MemberEx.GetIdByPriority(11); if (tagId != Guid.Empty) { var oTag11 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag11 == null) { oTag11 = new EF6.MemberSmartTag(); oTag11.SmartTagId = Guid.NewGuid(); oTag11.MemberId = id; oTag11.TagId = tagId; ctx.MemberSmartTag.Add(oTag11); } oTag11.SmartTagValue = item.NATION; ctx.SaveChanges(); } #endregion #region 12.Email //this.SaveMemberSmartTag(memberId, GetSmartTagId("Email", 12), objTempVip.EMAIL); tagId = SmartTag4MemberEx.GetIdByPriority(12); if (tagId != Guid.Empty) { var oTag12 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag12 == null) { oTag12 = new EF6.MemberSmartTag(); oTag12.SmartTagId = Guid.NewGuid(); oTag12.MemberId = id; oTag12.TagId = tagId; ctx.MemberSmartTag.Add(oTag12); } oTag12.SmartTagValue = item.EMAIL; ctx.SaveChanges(); } #endregion #region 13.ComName EN //this.SaveMemberSmartTag(memberId, GetSmartTagId("ComName EN", 13), objTempVip.COMPNAME); tagId = SmartTag4MemberEx.GetIdByPriority(13); if (tagId != Guid.Empty) { var oTag13 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag13 == null) { oTag13 = new EF6.MemberSmartTag(); oTag13.SmartTagId = Guid.NewGuid(); oTag13.MemberId = id; oTag13.TagId = tagId; ctx.MemberSmartTag.Add(oTag13); } oTag13.SmartTagValue = item.COMPNAME; ctx.SaveChanges(); } #endregion #region 14.ComName CN //this.SaveMemberSmartTag(memberId, GetSmartTagId("ComName CN", 14), objTempVip.COMPNAMEC); tagId = SmartTag4MemberEx.GetIdByPriority(14); if (tagId != Guid.Empty) { var oTag14 = ctx.MemberSmartTag.Where(x => x.MemberId == id && x.TagId == tagId).FirstOrDefault(); if (oTag14 == null) { oTag14 = new EF6.MemberSmartTag(); oTag14.SmartTagId = Guid.NewGuid(); oTag14.MemberId = id; oTag14.TagId = tagId; ctx.MemberSmartTag.Add(oTag14); } oTag14.SmartTagValue = item.COMPNAMEC; ctx.SaveChanges(); } #endregion #endregion #region SaveMemberVip(memberId, item); var oVip = ctx.MemberVipData.Where(x => x.MemberId == id).FirstOrDefault(); if (oVip == null) { oVip = new EF6.MemberVipData(); oVip.MemberVipId = Guid.NewGuid(); oVip.MemberId = id; oVip.VipNumber = item.VIPNO; ctx.MemberVipData.Add(oVip); } oVip.CARD_ISSUE = item.CARD_ISSUE; oVip.CARD_EXPIRE = item.CARD_EXPIRE; oVip.CARD_NAME = item.CARD_NAME; oVip.CARD_RECEIVE = item.CARD_RECEIVE.Value; oVip.CARD_ACTIVE = item.CARD_ACTIVE.Value; oVip.FORMER_PPNO = item.FORMER_PPNO; oVip.MigrationDate = item.DATE_MIGRATE; oVip.CommencementDate = item.DATE_COMM; oVip.CreditLimit = item.ACREDIT; oVip.CreditTerms = item.TERMS; oVip.PaymentDiscount = (decimal)item.PYDISC; oVip.AddOnDiscount = item.BADDONDISC == "Y" ? true : false; oVip.StaffQuota = item.STAFF_QUOTA; ctx.SaveChanges(); var memberVipId = oVip.MemberVipId; #region this.UpdateLoo(oVip.MemberVipId, item); var oVipLoo = ctx.MemberVipLineOfOperation.Where(x => x.MemberVipId == memberVipId).FirstOrDefault(); if (oVipLoo == null) { oVipLoo = new EF6.MemberVipLineOfOperation(); oVipLoo.VipLooId = Guid.NewGuid(); oVipLoo.VipLooId = System.Guid.NewGuid(); oVipLoo.MemberVipId = memberVipId; oVipLoo.LineOfOperationId = LineOfOperationEx.GetLineOfOperationIdByName(item.LOOID); ctx.MemberVipLineOfOperation.Add(oVipLoo); } oVipLoo.NormalDiscount = (decimal)item.NRDISC; oVipLoo.PromotionDiscount = (decimal)item.PRO_DISC; ctx.SaveChanges(); #endregion #region this.UpdateSupplement(oVip.MemberVipId, item); var oSupplement = ctx.MemberVipSupplement.Where(x => x.MemberVipId == memberVipId).FirstOrDefault(); if (oSupplement == null) { oSupplement = new EF6.MemberVipSupplement(); oSupplement.VipSupplementId = Guid.NewGuid(); oSupplement.VipSupplementId = System.Guid.NewGuid(); oSupplement.MemberVipId = memberVipId; oSupplement.CustomerNumber = item.CUSTNUM; oSupplement.BRANCH = item.BRANCH; ctx.MemberVipSupplement.Add(oSupplement); } oSupplement.Remarks1 = item.R1; oSupplement.Remarks2 = item.R2; oSupplement.Remarks3 = item.R3; oSupplement.Nature = item.NATURE; oSupplement.Memo = item.MEMO; oSupplement.Photo = item.PHOTO; oSupplement.MostVisitedMalls1 = item.MALL1; oSupplement.MostVisitedMalls2 = item.MALL2; oSupplement.MostVisitedMalls3 = item.MALL3; oSupplement.MostBoughtBrands1 = item.BRAND1; oSupplement.MostBoughtBrands2 = item.BRAND2; oSupplement.MostBoughtBrands3 = item.BRAND3; oSupplement.MostReadMagazine1 = item.MAGAZINE1; oSupplement.MostReadMagazine2 = item.MAGAZINE2; oSupplement.MostReadMagazine3 = item.MAGAZINE3; oSupplement.MostUsedCreditCards1 = item.CARD1; oSupplement.MostUsedCreditCards2 = item.CARD2; oSupplement.MostUsedCreditCards3 = item.CARD3; ctx.SaveChanges(); #endregion #endregion #endregion ctx.MemberApply4TempVip.Remove(item); ctx.SaveChanges(); } scope.Commit(); result = true; } catch (Exception ex) { scope.Rollback(); } } } return(result); }
private void Save(MemberTemplate member) { using (var ctx = new EF6.RT2020Entities()) { using (var scope = ctx.Database.BeginTransaction()) { try { #region save member core data var oMember = ctx.Member.Where(x => x.MemberNumber == member.VIPNO).FirstOrDefault(); if (oMember == null) { oMember = new EF6.Member(); oMember.MemberId = Guid.NewGuid(); oMember.MemberNumber = member.VIPNO; oMember.CreatedBy = ConfigHelper.CurrentUserId; oMember.CreatedOn = DateTime.Now; ctx.Member.Add(oMember); } oMember.WorkplaceId = System.Guid.Empty; oMember.ClassId = MemberClassEx.GetIdByCode(member.PHONEBOOK); oMember.GroupId = MemberGroupEx.GetIdByCode(member.GROUP); oMember.MemberInitial = member.NNAME; oMember.SalutationId = SalutationEx.GetIdByCode(member.SALUTE); oMember.FirstName = member.FNAME; oMember.LastName = member.LNAME; oMember.FullName = member.LNAME + ", " + member.FNAME; oMember.FullName_Chs = member.CNAME; oMember.FullName_Cht = member.CNAME; oMember.JobTitleId = JobTitleEx.GetJobTitleIdByName(member.TITLE); oMember.AssignedTo = System.Guid.Empty; oMember.Remarks = member.REMARKS; oMember.NormalDiscount = member.NRDISC; oMember.Status = Convert.ToInt32(EnumHelper.Status.Active.ToString("d")); oMember.ModifiedBy = ConfigHelper.CurrentUserId; oMember.ModifiedOn = DateTime.Now; ctx.SaveChanges(); #endregion var memberId = oMember.MemberId; #region SaveSmartTag(oMember.MemberId, member); var tagId = Guid.Empty; string sql = "MemberId = '" + memberId.ToString() + "' AND TagId = '{0}'"; #region Grade tagId = GetSmartTagId("1"); var oGradeTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oGradeTag == null) { oGradeTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oGradeTag.MemberId = memberId; oGradeTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oGradeTag.SmartTagValue = member.GRADE; #endregion #region Sex tagId = GetSmartTagId("2"); var oSexTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oSexTag == null) { oSexTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oSexTag.MemberId = memberId; oSexTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oSexTag.SmartTagValue = member.SEX; #endregion #region Race tagId = GetSmartTagId("3"); var oRaceTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oRaceTag == null) { oRaceTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oRaceTag.MemberId = memberId; oRaceTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oRaceTag.SmartTagValue = member.RACE; #endregion #region AgeGroup tagId = GetSmartTagId("4"); var oAgeGroupTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oAgeGroupTag == null) { oAgeGroupTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oAgeGroupTag.MemberId = memberId; oAgeGroupTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oAgeGroupTag.SmartTagValue = member.AGE_GROUP; #endregion #region CodeCardNumber tagId = GetSmartTagId("5"); var oCodeCardNumberTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oCodeCardNumberTag == null) { oCodeCardNumberTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oCodeCardNumberTag.MemberId = memberId; oCodeCardNumberTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oCodeCardNumberTag.SmartTagValue = member.CODENUM; #endregion #region LoyaltyNumber tagId = GetSmartTagId("6"); var oLoyaltyNumberTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oLoyaltyNumberTag == null) { oLoyaltyNumberTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oLoyaltyNumberTag.MemberId = memberId; oLoyaltyNumberTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oLoyaltyNumberTag.SmartTagValue = member.LOYALTYNUM; #endregion #region Profile tagId = GetSmartTagId("7"); var oProfileTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oProfileTag == null) { oProfileTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oProfileTag.MemberId = memberId; oProfileTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oProfileTag.SmartTagValue = member.PROFILE; #endregion #region DateOfBirth tagId = GetSmartTagId("8"); var oDateOfBirthTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oDateOfBirthTag == null) { oDateOfBirthTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oDateOfBirthTag.MemberId = memberId; oDateOfBirthTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oDateOfBirthTag.SmartTagValue = DateTimeHelper.DateTimeToString(member.DATE_BIRTH, false); #endregion #region DateOfRegister tagId = GetSmartTagId("9"); var oDateOfRegisterTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oDateOfRegisterTag == null) { oDateOfRegisterTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oDateOfRegisterTag.MemberId = memberId; oDateOfRegisterTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oDateOfRegisterTag.SmartTagValue = DateTimeHelper.DateTimeToString(member.DATE_REGIS, false); #endregion #region HKID tagId = GetSmartTagId("10"); var oHKIDTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oHKIDTag == null) { oHKIDTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oHKIDTag.MemberId = memberId; oHKIDTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oHKIDTag.SmartTagValue = member.ID_NO; #endregion #region Nationality tagId = GetSmartTagId("11"); var oNationalityTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oNationalityTag == null) { oNationalityTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oNationalityTag.MemberId = memberId; oNationalityTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oNationalityTag.SmartTagValue = member.NATION; #endregion #region Email tagId = GetSmartTagId("12"); var oEmailTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oEmailTag == null) { oEmailTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oEmailTag.MemberId = memberId; oEmailTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oEmailTag.SmartTagValue = member.EMAIL; #endregion #region Company tagId = GetSmartTagId("13"); var oCompanyTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oCompanyTag == null) { oCompanyTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oCompanyTag.MemberId = memberId; oCompanyTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oCompanyTag.SmartTagValue = member.COMPNAME; #endregion #region CompanyName_Ch tagId = GetSmartTagId("14"); var oCompanyName_ChTag = ctx.MemberSmartTag.Where(x => x.MemberId == memberId && x.TagId == tagId).FirstOrDefault(); if (oCompanyName_ChTag == null) { oCompanyName_ChTag = new EF6.MemberSmartTag(); oGradeTag.SmartTagId = Guid.NewGuid(); oCompanyName_ChTag.MemberId = memberId; oCompanyName_ChTag.TagId = tagId; ctx.MemberSmartTag.Add(oGradeTag); } oCompanyName_ChTag.SmartTagValue = member.COMPNAMEC; #endregion ctx.SaveChanges(); #endregion #region SaveAddress(oMember.MemberId, member); //string sql = "MemberId = '" + memberId.ToString() + "' AND AddressTypeId = '" + GetAddressTypeId().ToString() + "'"; var addressTypeId = GetAddressTypeId(); var oAddress = ctx.MemberAddress.Where(x => x.MemberId == memberId && x.AddressTypeId == addressTypeId).FirstOrDefault(); if (oAddress == null) { oAddress = new EF6.MemberAddress(); oAddress.AddressId = Guid.NewGuid(); oAddress.MemberId = memberId; oAddress.AddressTypeId = GetAddressTypeId(); ctx.MemberAddress.Add(oAddress); } oAddress.Address = member.ADDRESS4; oAddress.PostalCode = string.Empty; oAddress.CountryId = CountryEx.GetCountryIdByName(member.ADDRESS1); oAddress.ProvinceId = ProvinceEx.GetProvinceIdByName(member.ADDRESS2); oAddress.CityId = GetCityId(member.ADDRESS3); oAddress.District = string.Empty; oAddress.Mailing = true; oAddress.PhoneTag1 = PhoneTagEx.GetPhoneTagIdByPriority(1); oAddress.PhoneTag1Value = member.TELW; oAddress.PhoneTag2 = PhoneTagEx.GetPhoneTagIdByPriority(2); oAddress.PhoneTag2Value = member.TELH; oAddress.PhoneTag3 = PhoneTagEx.GetPhoneTagIdByPriority(3); oAddress.PhoneTag3Value = member.FAX; oAddress.PhoneTag4 = PhoneTagEx.GetPhoneTagIdByPriority(4); oAddress.PhoneTag4Value = member.TELOTHER; ctx.SaveChanges(); #endregion #region SaveVipData(oMember.MemberId, member); //string sql = "MemberId = '" + memberId.ToString() + "'"; var oVip = ctx.MemberVipData.Where(x => x.MemberId == memberId).FirstOrDefault(); if (oVip == null) { oVip = new EF6.MemberVipData(); oVip.MemberVipId = Guid.NewGuid(); oVip.MemberId = memberId; oVip.VipNumber = member.VIPNO; ctx.MemberVipData.Add(oVip); } oVip.FORMER_PPNO = member.FORMER_PPNO; oVip.CARD_ACTIVE = (string.IsNullOrEmpty(member.CARD_ACTIVE)) ? false : Convert.ToBoolean(member.CARD_ACTIVE); oVip.CARD_RECEIVE = (string.IsNullOrEmpty(member.CARD_RECEIVE)) ? false : Convert.ToBoolean(member.CARD_RECEIVE); oVip.CARD_NAME = member.CARD_NAME; oVip.CARD_EXPIRE = member.CARD_EXPIRE; oVip.CARD_ISSUE = member.CARD_ISSUE; /** * oVip.SetMetadata("CardInfo_CommencementDate", member.DATE_COMM.ToString("yyyy-MM-dd HH:mm:ss")); * oVip.SetMetadata("CardInfo_MigrationDate", member.DATE_MIGRATE.ToString("yyyy-MM-dd HH:mm:ss")); * * // Others Info * oVip.SetMetadata("OthersInfo_CreditLimit", member.ACREDIT.ToString()); * oVip.SetMetadata("OthersInfo_CreditTerms", member.TERMS); * oVip.SetMetadata("OthersInfo_PaymentDiscount", member.PYDISC.ToString()); * oVip.SetMetadata("OthersInfo_CustomerInfo_1", member.CUSTNUM); * oVip.SetMetadata("OthersInfo_CustomerInfo_2", member.BRANCH); * oVip.SetMetadata("OthersInfo_PromotionDiscount", member.PRO_DISC.ToString()); * oVip.SetMetadata("OthersInfo_AddOnDiscount", member.BADDONDISC); * oVip.SetMetadata("OthersInfo_StaffQuota", member.STAFF_QUOTA.ToString()); * oVip.SetMetadata("OthersInfo_Remarks1", member.R1); * oVip.SetMetadata("OthersInfo_Remarks2", member.R2); * oVip.SetMetadata("OthersInfo_Remarks3", member.R3); * oVip.SetMetadata("OthersInfo_Nature", member.NATURE); * * oVip.SetMetadata("OthersInfo_Age", member.AGE); * oVip.SetMetadata("OthersInfo_DL_Flag", member.DLFLAG); * oVip.SetMetadata("OthersInfo_LOOCode", member.LOOID); * oVip.SetMetadata("OthersInfo_AmountPurchased", member.ATDAMTPUR.ToString()); * oVip.SetMetadata("OthersInfo_AmountPaied", member.ATDAMTPAY.ToString()); * oVip.SetMetadata("OthersInfo_AmountReturned", member.ATDAMTRET.ToString()); * oVip.SetMetadata("OthersInfo_AmountDiscounted", member.ATDAMTDIS.ToString()); * oVip.SetMetadata("OthersInfo_Memo", member.MEMO); * * // Marketing Info * oVip.SetMetadata("MarketingInfo_MostVisitedMalls_1", member.MALL1); * oVip.SetMetadata("MarketingInfo_MostVisitedMalls_2", member.MALL2); * oVip.SetMetadata("MarketingInfo_MostVisitedMalls_3", member.MALL3); * * oVip.SetMetadata("MarketingInfo_MostBoughtBrands_1", member.BRAND1); * oVip.SetMetadata("MarketingInfo_MostBoughtBrands_2", member.BRAND2); * oVip.SetMetadata("MarketingInfo_MostBoughtBrands_3", member.BRAND3); * * oVip.SetMetadata("MarketingInfo_MostReadMagazine_1", member.MAGAZINE1); * oVip.SetMetadata("MarketingInfo_MostReadMagazine_2", member.MAGAZINE2); * oVip.SetMetadata("MarketingInfo_MostReadMagazine_3", member.MAGAZINE3); * * oVip.SetMetadata("MarketingInfo_MostUsedCreditCards_1", member.CARD1); * oVip.SetMetadata("MarketingInfo_MostUsedCreditCards_2", member.CARD2); * oVip.SetMetadata("MarketingInfo_MostUsedCreditCards_3", member.CARD3); * * // Photo * oVip.SetMetadata("MiscInfo_Photo", member.PHOTO); * * // Contact * oVip.SetMetadata("Address_Phone_Pager", member.TELP); * oVip.SetMetadata("Address_Chinese_1", member.ADDRESS1C); * oVip.SetMetadata("Address_Chinese_2", member.ADDRESS2C); * oVip.SetMetadata("Address_Chinese_3", member.ADDRESS3C); * oVip.SetMetadata("Address_Chinese_4", member.ADDRESS4C); */ ctx.SaveChanges(); #endregion scope.Commit(); } catch (Exception ex) { scope.Rollback(); } } } }