/// <summary> /// Send Message to Customer when Customer's zip code matches with shops zip code. /// Shop this may send multiple messages depending on how much shops added this zip code into zip code configuration list, /// the message can be configured by shop user using On-demand-Campaign /// </summary> /// <param name="objBodyShop"></param> /// <param name="objUser"></param> private void SendZipCodeMatchesShopSMS(Int32 iUserId, String strZipCode, Int32 iPrivateLabelId) { try { List <BodyShopZipCodeBL> lstBodyShopZipCode = BodyShopZipCodeBL.getDataByZipCode(strZipCode); if (lstBodyShopZipCode != null && lstBodyShopZipCode.Count > 0) { List <BodyShopPrivateLabelBL> lstBodyShopPrivateLabel = new List <BodyShopPrivateLabelBL>(); if (iPrivateLabelId != 0) { lstBodyShopPrivateLabel = BodyShopPrivateLabelBL.GetShopListByPrivateLabelId(iPrivateLabelId); if (lstBodyShopPrivateLabel != null && lstBodyShopPrivateLabel.Count > 0) { lstBodyShopZipCode.RemoveAll(objBodyShopZipCode => lstBodyShopPrivateLabel.Exists(objBodyShopPrivateLabel => objBodyShopPrivateLabel.iShopID != objBodyShopZipCode.iShopId)); } } UserBL objUser = UserBL.getByActivityId(iUserId); foreach (BodyShopZipCodeBL objBodyShopZipCode in lstBodyShopZipCode) { #region Opted-out Code //Check that user has opted-out for send sms if (objUser.bIsOptedOutForMobileMessage == true) { continue; } #endregion CampaignBL objCampaign = CampaignBL.GetZipCodeMatchesMessageByShopId(objBodyShopZipCode.iShopId); if (objCampaign != null && !String.IsNullOrEmpty(objCampaign.strMessage) && !String.IsNullOrEmpty(objUser.strPhone) && !String.IsNullOrEmpty(objCampaign.strMessage)) { SMS objSMS = new SMS(); string strMessage = objCampaign.strMessage.Replace("[[ID]]", iUserId.ToString()); objSMS.SendSMS(objUser.strPhone, strMessage, objUser.ID, FromAppSection.NewRepairProspect, objBodyShopZipCode.iShopId); } } } } catch (Exception) { } }
private bool setUserPrefferedShop(Int32 iUserId, out Int32 iShopId, out Boolean hasGroupOfPrivateShops, out Boolean bPerfromOperation) { iShopId = 0; hasGroupOfPrivateShops = false; bPerfromOperation = true; UserPreferredShopBL objPrefferedShop = UserPreferredShopBL.getShopByUserId(iUserId); Int32 iPrivateShopId = 0; if (Request.QueryString[Constants.QUERYSTRING_PRIVATELABELSHOPID] != null) { iPrivateShopId = Convert.ToInt32(Request.QueryString[Constants.QUERYSTRING_PRIVATELABELSHOPID]); } else if (Request.Form[Constants.QUERYSTRING_PRIVATELABELSHOPID] != null) { iPrivateShopId = Convert.ToInt32(Request.Form[Constants.QUERYSTRING_PRIVATELABELSHOPID]); } if (iPrivateShopId > 0) { BodyShopBL objShop = null; List <BodyShopPrivateLabelBL> lstBodyShopPrivateLabelBL = new List <BodyShopPrivateLabelBL>(); lstBodyShopPrivateLabelBL = BodyShopPrivateLabelBL.GetShopListByPrivateLabelId(iPrivateShopId); //Check that more than one shop within this private labeling group? if yes then don't assign preferred shop if (lstBodyShopPrivateLabelBL.Count > 1) { //This privateLabelId exist for a group of shops; user need to select preferred shop from "Select Preferred Shop" page hasGroupOfPrivateShops = true; return(false); } else { objShop = BodyShopBL.getShopById(Convert.ToInt32(lstBodyShopPrivateLabelBL[0].iShopID)); } if (objShop != null) { if (objPrefferedShop == null) { objPrefferedShop = new UserPreferredShopBL(); } else { //If user has alredy set same preferred shop then return. if (objShop.ID == objPrefferedShop.iShopId) { bPerfromOperation = false; return(false); } MessageBL objMesssage = MessageBL.getDataByUserShopIdAndType(iUserId, objShop.ID, Constants.REGISTRATIONMESSAGTYPE); if (objMesssage != null) { objMesssage.Delete(); } } objPrefferedShop.iShopId = objShop.ID; objPrefferedShop.iUserId = iUserId; if (objPrefferedShop.Save()) { iShopId = objShop.ID; return(true); } else { return(false); } } } return(false); }
private bool saveMessage(Int32 iUserId) { Int32 iShopId; Boolean hasGroupOfPrivateShops; Boolean bPerformOperation; Boolean bHasShop = setUserPrefferedShop(iUserId, out iShopId, out hasGroupOfPrivateShops, out bPerformOperation); if (hasGroupOfPrivateShops || !(bPerformOperation)) { return(false); } if (bHasShop) { DeletedUsersFromRepairProspectBL objDeletedUsersFromRepairProspectBL = DeletedUsersFromRepairProspectBL.getDataByShopId(iShopId, iUserId); if (objDeletedUsersFromRepairProspectBL != null) { objDeletedUsersFromRepairProspectBL.Delete(); } UnreadUsersFromRepairProspectBL OldPrefferedShop = UnreadUsersFromRepairProspectBL.getDataByUserId(iUserId); if (OldPrefferedShop != null) { if (OldPrefferedShop.ShopID != iShopId) { OldPrefferedShop.Delete(); } } UnreadUsersFromRepairProspectBL objOldEntry = UnreadUsersFromRepairProspectBL.getDataByShopId(iShopId, iUserId); if (objOldEntry == null) { UnreadUsersFromRepairProspectBL objUnreadUsersFromRepairProspectBL = new UnreadUsersFromRepairProspectBL(); objUnreadUsersFromRepairProspectBL.User_id = iUserId; objUnreadUsersFromRepairProspectBL.ShopID = iShopId; objUnreadUsersFromRepairProspectBL.Save(); } } try { Int32 iPrivateLabelId = 0; if (Request.QueryString[Constants.QUERYSTRING_PRIVATELABELSHOPID] != null) { Int32.TryParse(Request.QueryString[Constants.QUERYSTRING_PRIVATELABELSHOPID], out iPrivateLabelId); } else if (Request.Form[Constants.QUERYSTRING_PRIVATELABELSHOPID] != null) { Int32.TryParse(Request.Form[Constants.QUERYSTRING_PRIVATELABELSHOPID], out iPrivateLabelId); } if (iPrivateLabelId == 0) { return(false); } List <BodyShopPrivateLabelBL> lstBodyShopPrivateLabel = BodyShopPrivateLabelBL.GetShopListByPrivateLabelId(iPrivateLabelId); if (lstBodyShopPrivateLabel == null || lstBodyShopPrivateLabel.Count == 0) { return(false); } List <MessageBL> lstMessage = MessageBL.getDataByUserIdAndType(iUserId, Constants.REGISTRATIONMESSAGTYPE); Boolean bFound = false; if (lstMessage != null && lstMessage.Count > 0) { foreach (MessageBL objMessage in lstMessage) { if (objMessage.iShopID == null) { objMessage.bIsRead = true; objMessage.strMessage = Constants.REGISTRATIONMESSAGE; if (iPrivateLabelId != 0) { objMessage.iPrivateLabelID = iPrivateLabelId; } } else { objMessage.bIsRead = false; objMessage.iShopID = iShopId; objMessage.strMessage = Constants.PREFFEREDSHOPMESSAGE; bFound = true; } objMessage.Save(); } } else { MessageBL objMessage = new MessageBL(); objMessage.iPhoneUserID = iUserId; objMessage.iType = Constants.REGISTRATIONMESSAGTYPE; objMessage.strMessage = Constants.REGISTRATIONMESSAGE; objMessage.bIsRead = false; objMessage.dtMessageTime = DateTime.Now; if (iPrivateLabelId != 0) { objMessage.iPrivateLabelID = iPrivateLabelId; } objMessage.Save(); MessageBL _objMessage = new MessageBL(); _objMessage.iShopID = iShopId; _objMessage.iPhoneUserID = iUserId; _objMessage.iType = Constants.REGISTRATIONMESSAGTYPE; _objMessage.strMessage = Constants.PREFFEREDSHOPMESSAGE; _objMessage.bIsRead = false; _objMessage.dtMessageTime = DateTime.Now; _objMessage.Save(); bFound = true; } if (!bFound) { MessageBL _objMessage = new MessageBL(); _objMessage.iShopID = iShopId; _objMessage.iPhoneUserID = iUserId; _objMessage.iType = Constants.REGISTRATIONMESSAGTYPE; _objMessage.strMessage = Constants.PREFFEREDSHOPMESSAGE; _objMessage.bIsRead = false; _objMessage.dtMessageTime = DateTime.Now; _objMessage.Save(); } } catch (Exception ex) { } return(false); }