/// <summary> /// /// </summary> /// <param name="registerPromotionRequest"></param> /// <returns></returns> public MemberPromotion RegisterPromotion(MemberPromotion registerPromotionRequest) { List <int> segmentList = null; string promotionID = registerPromotionRequest.PromotionID; string loyaltyCardNumber = registerPromotionRequest.LoyaltyCardNumber; iRetalixServices = new CallRetalixServices(); // Get the Segment list for the given Promotion segmentList = GetSegmentsForPromotion(promotionID); // Continue only if there is a segment found for the given promotion if (segmentList?.Count > 0) { // Verify the segment is found at member or household segment level bool isMemberAuthorized = VerifyMemberIsAuthorized(loyaltyCardNumber, segmentList); // if found, then register the promotion in LMS if (isMemberAuthorized) { var registerResult = iRetalixServices.RegisterPromotion(loyaltyCardNumber, promotionID); // if failed to register promotion, check if promotion is already registered or Activated by calling GetMemberPromotion if (!registerResult.IsSuccess) { int promoCheck = CheckPromotionActivated(loyaltyCardNumber, promotionID); // TODO : Assign the Actual Error codes instead of 0,1,2 for the below conditions if (promoCheck == -1) { // Failed registerPromotionRequest.IsSuccess = false; registerPromotionRequest.RegistrationResult = "Promotion Registration Failed"; } else if (promoCheck == 0) { // Registered Successfully , Promotion Not Activated or Not Used registerPromotionRequest.IsSuccess = true; registerPromotionRequest.RegistrationResult = "Registered Successfully , Promotion Not Activated or Not Used"; } else if (promoCheck > 0) { // Already Registered Successfully and Promotion Activate / Used registerPromotionRequest.IsSuccess = true; registerPromotionRequest.RegistrationResult = "Already Registered Successfully and Promotion Activate"; } } else { // Registered Successfully registerPromotionRequest.IsSuccess = true; registerPromotionRequest.RegistrationResult = "Promotion Registeration Successfull"; } } else { registerPromotionRequest.IsSuccess = false; registerPromotionRequest.RegistrationResult = AppConstants.DisplayMessages.MemberNotAuthorizedForPromotion; } } else { registerPromotionRequest.IsSuccess = false; registerPromotionRequest.RegistrationResult = AppConstants.DisplayMessages.SegmentNotFound; } return(registerPromotionRequest); }
/// <summary> /// Method to Register Promotion /// </summary> /// <param name="registerPromotionRequest"></param> /// <returns></returns> public MemberPromotion RegisterPromotion(MemberPromotion registerPromotionRequest) { _logMsg.MethodName = MethodBase.GetCurrentMethod().Name; ProcessEmailCampaignManager processEmailCampaignManager = new ProcessEmailCampaignManager(); // Set the registration flag to default as failed int registrationStatusCode = 0; List <int> segmentList = null; string promotionID = registerPromotionRequest.PromotionID; string loyaltyCardNumber = registerPromotionRequest.LoyaltyCardNumber; string houseHoldId = loyaltyCardNumber.Substring(4, 9); string individualId = loyaltyCardNumber.Substring(13, 2); iRetalixServices = new CallRetalixServices(); //Check if promotion is found in OPE bool checkpromotionInOPE = CheckPromotionInOPE(promotionID); if (checkpromotionInOPE) { //Get Segments configured for the promotion segmentList = GetSegmentsForPromotion(promotionID); if (segmentList?.Count > 0) { // Verify the segment is found at member or household segment level bool isMemberAuthorized = VerifyMemberIsAuthorized(loyaltyCardNumber, segmentList); if (isMemberAuthorized) { //Register promotion in LMS var registerResult = iRetalixServices.RegisterPromotion(loyaltyCardNumber, promotionID); if (!registerResult.IsSuccess) { DBLogging.Warn(_logMsg, "Register Promotion Failed", "Loyalty Card Number :" + loyaltyCardNumber + ", Promotion Id :" + promotionID, registerResult.ResDescription); processEmailCampaignManager.LogLoyaltyTransaction("Promotion Registration in Retalix Failed for the given Member", individualId, loyaltyCardNumber, houseHoldId); registerPromotionRequest.IsSuccess = false; registerPromotionRequest.RegistrationResult = registerResult.ResDescription; } else { var synchHouseholdBonus = processEmailCampaignManager.SyncHouseholdBonus(AppConstants.ConstantValues.ActionCodeA, individualId, houseHoldId, loyaltyCardNumber, promotionID); if (synchHouseholdBonus < 1) { DBLogging.Warn(_logMsg, "Sync Household Bonuses Failed", "Action Code : R" + ", Household Id :" + houseHoldId + ", Individual Id :" + individualId + ", Loyalty Card Number :" + loyaltyCardNumber + ", MOD Promotion Id :" + promotionID, AppConstants.DisplayMessages.SyncToMobillaFailed); registerPromotionRequest.IsSuccess = false; registerPromotionRequest.RegistrationResult = AppConstants.DisplayMessages.SyncToMobillaFailed; } registerPromotionRequest.IsSuccess = true; registerPromotionRequest.RegistrationResult = "Promotion Registeration Successfull"; } } else { registerPromotionRequest.IsSuccess = false; registerPromotionRequest.RegistrationResult = AppConstants.DisplayMessages.MemberNotAuthorizedForPromotion; } } else { registerPromotionRequest.IsSuccess = false; registerPromotionRequest.RegistrationResult = AppConstants.DisplayMessages.SegmentNotFound; } } else { registerPromotionRequest.IsSuccess = false; registerPromotionRequest.RegistrationResult = "Promotion Not Found in OPE"; } registerPromotionRequest.RegistrationResult = registrationStatusCode.ToString(); return(registerPromotionRequest); }