private void SetAvailableData() { GetAllCustomerGroup(); AvailableFilteredCustomerGroup = AllGroups.Where(p => !IncludedGroup.Any(inc => inc.CustomerGroupID == p.CustomerGroupID)) .Where(p => !ExcludedGroup.Any(exc => exc.CustomerGroupID == p.CustomerGroupID)).ToList(); //Hide regular excluded customer groups for new condition if (ConditionID == 0 && ExcludedConditionGroup != null && ExcludedConditionGroup.Count > 0) { AvailableFilteredCustomerGroup = AvailableFilteredCustomerGroup.Where(p => !ExcludedConditionGroup.Any(inc => inc.CustomerGroupID == p.CustomerGroupID)).ToList(); } string strFilter = functioninput.Text; if (functionradio1.Checked) { AvailableFilteredCustomerGroup = AvailableFilteredCustomerGroup.Where(p => p.Name.StartsWith(strFilter, StringComparison.OrdinalIgnoreCase)).ToList(); } else { AvailableFilteredCustomerGroup = AvailableFilteredCustomerGroup.Where(p => p.Name.IndexOf(strFilter, StringComparison.OrdinalIgnoreCase) >= 0).ToList(); } lstSelected.DataSource = IncludedGroup; lstSelected.DataBind(); lstExcluded.DataSource = ExcludedGroup; lstExcluded.DataBind(); lstAvailable.DataSource = AvailableFilteredCustomerGroup; lstAvailable.DataBind(); }
private void Save() { bool isNewCondition = false; string strIncludedGroup = string.Empty; string strExcludedGroup = string.Empty; try { if (OfferEligibileCustomerGroupCondition.ConditionID == 0) { isNewCondition = true; } if (chkDisallow_Edit.Visible) { OfferEligibileCustomerGroupCondition.DisallowEdit = chkDisallow_Edit.Checked; } if (spnHouseHold.Visible) { OfferEligibileCustomerGroupCondition.HouseHoldEnabled = chkHouseHold.Checked; } if (spnOffline.Visible) { OfferEligibileCustomerGroupCondition.EvaluateOfflineCustomer = chkOffline.Checked; } //Updated Include List var deletedlist = OfferEligibileCustomerGroupCondition.IncludeCondition.Where(p => !IncludedGroup.Any(inc => inc.CustomerGroupID == p.CustomerGroupID)); foreach (CMS.AMS.Models.CustomerConditionDetails custdetail in deletedlist) { custdetail.Deleted = true; } historyString = PhraseLib.Lookup("history.con-customer-edit", LanguageID) + ": "; foreach (CMS.AMS.Models.CustomerGroup CustGroup in IncludedGroup) { if (!OfferEligibileCustomerGroupCondition.IncludeCondition.Exists(p => p.CustomerGroupID == CustGroup.CustomerGroupID)) { CMS.AMS.Models.CustomerConditionDetails condetail = new CMS.AMS.Models.CustomerConditionDetails(); condetail.CustomerGroupID = CustGroup.CustomerGroupID; OfferEligibileCustomerGroupCondition.IncludeCondition.Add(condetail); strIncludedGroup = strIncludedGroup + CustGroup.CustomerGroupID.ToString() + ","; } } historyString = historyString + strIncludedGroup.TrimEnd(','); //Update Exclude List exc var deletedexclist = OfferEligibileCustomerGroupCondition.ExcludeCondition.Where(p => !ExcludedGroup.Any(exc => exc.CustomerGroupID == p.CustomerGroupID)); foreach (CMS.AMS.Models.CustomerConditionDetails custdetail in deletedexclist) { custdetail.Deleted = true; } bool IsExcludedExist = false; foreach (CMS.AMS.Models.CustomerGroup CustGroup in ExcludedGroup) { if (!OfferEligibileCustomerGroupCondition.ExcludeCondition.Exists(p => p.CustomerGroupID == CustGroup.CustomerGroupID)) { CMS.AMS.Models.CustomerConditionDetails condetail = new CMS.AMS.Models.CustomerConditionDetails(); condetail.CustomerGroupID = CustGroup.CustomerGroupID; strExcludedGroup = strExcludedGroup + CustGroup.CustomerGroupID.ToString() + ","; OfferEligibileCustomerGroupCondition.ExcludeCondition.Add(condetail); IsExcludedExist = true; } } if (ExcludedConditionGroup != null) { //if it is a new condition then add excluded customer groups which are currently exist in regualr customer condition if (isNewCondition) { foreach (CMS.AMS.Models.CustomerGroup CustGroup in ExcludedConditionGroup) { if (!OfferEligibileCustomerGroupCondition.ExcludeCondition.Exists(p => p.CustomerGroupID == CustGroup.CustomerGroupID)) { CMS.AMS.Models.CustomerConditionDetails condetail = new CMS.AMS.Models.CustomerConditionDetails(); condetail.CustomerGroupID = CustGroup.CustomerGroupID; strExcludedGroup = strExcludedGroup + CustGroup.CustomerGroupID.ToString() + ","; OfferEligibileCustomerGroupCondition.ExcludeCondition.Add(condetail); IsExcludedExist = true; } } } else { //if it is an existing eligibility condition and user attempt to remove group from excluded condition which is exist in regular excluded condition then ask user to delete remove the same from regualr condition as well var mustExcludedList = deletedexclist.Where(p => ExcludedConditionGroup.Any(exc => exc.CustomerGroupID == p.CustomerGroupID)).Select(z => z.CustomerGroup); List <long> ExcludedGroupIds = new List <long>(); foreach (CustomerGroup item in mustExcludedList) { ExcludedGroupIds.Add(item.CustomerGroupID); } if (ExcludedGroupIds.Count > 0) { //Delete the excluded condition m_CustCondition.DeleteRegulerExcludedConditionsByCustomerGroupIDs(OfferID, EngineID, ExcludedGroupIds); } } } if (IsExcludedExist) { historyString = historyString + " " + PhraseLib.Lookup("term.excluding", LanguageID) + " " + strExcludedGroup.TrimEnd(','); } m_offer.CreateUpdateOfferEligibleCustomerCondition(OfferID, EngineID, OfferEligibileCustomerGroupCondition); if (isNewCondition) { CMS.AMS.Models.CustomerGroup CustomerGroup = new CMS.AMS.Models.CustomerGroup(); CustomerGroup.Name = string.Format(Constants.DEFAULT_OFFER_GROUP_NAME, hdnOfferName.Value); CustomerGroup.IsOptinGroup = true; m_CustGroup.CreateOptInCustomerGroup(CustomerGroup); CMS.AMS.Models.CustomerGroupConditions CustomerCondition = new CMS.AMS.Models.CustomerGroupConditions(); CustomerCondition.DisallowEdit = OfferEligibileCustomerGroupCondition.DisallowEdit; CustomerCondition.RequiredFromTemplate = OfferEligibileCustomerGroupCondition.RequiredFromTemplate; CustomerCondition.IncludeCondition = new List <CMS.AMS.Models.CustomerConditionDetails>(); CustomerCondition.IncludeCondition.Add(new CMS.AMS.Models.CustomerConditionDetails()); CustomerCondition.IncludeCondition[0].CustomerGroupID = CustomerGroup.CustomerGroupID; m_offer.CreateDefaultCustomerCondition(OfferID, EngineID, CustomerCondition); } m_offer.UpdateOfferStatusToModified(OfferID, EngineID, CurrentUser.AdminUser.ID); m_OAWService.ResetOfferApprovalStatus(OfferID); WriteToActivityLog(); ScriptManager.RegisterStartupScript(this, this.GetType(), "Close", "CloseModel()", true); } catch (Exception ex) { infobar.InnerText = ErrorHandler.ProcessError(ex); infobar.Visible = true; } }
protected void btnSave_Click(object sender, EventArgs e) { if (!(lstSelected.Items.Count > 0)) { infobar.InnerText = PhraseLib.Lookup("term-validateincludedgroupset", LanguageID).Replace("'", "'"); infobar.Visible = true; return; } if (OfferEligibileCustomerGroupCondition.ConditionID == 0) { if (IsDefaultGroupNameExsits()) { infobar.Visible = true; infobar.InnerText = String.Format(String.Format(PhraseLib.Lookup("OfferEligibilityCustomerCondition.validatedefaultgroupname", LanguageID), Constants.DEFAULT_OFFER_GROUP_NAME), hdnOfferName.Value).Replace("'", "'"); return; } } var deletedexclist = OfferEligibileCustomerGroupCondition.ExcludeCondition.Where(p => !ExcludedGroup.Any(exc => exc.CustomerGroupID == p.CustomerGroupID)); if (OfferEligibileCustomerGroupCondition.ConditionID != 0) { //if it is an existing eligibility condition and user attempt to remove group from excluded condition which is exist in regular excluded condition then ask user to delete remove the same from regualr condition as well var mustExcludedList = deletedexclist.Where(p => ExcludedConditionGroup.Any(exc => exc.CustomerGroupID == p.CustomerGroupID)).Select(z => z.CustomerGroup); string strGroups = String.Empty; foreach (CustomerGroup item in mustExcludedList) { if (strGroups != "") { strGroups = strGroups + ","; } strGroups = strGroups + item.Name; } if (strGroups != String.Empty) { ScriptManager.RegisterStartupScript(this, this.GetType(), "RegulerConditionDelete", "ConfirmRegulerConditionDelete('" + String.Format(PhraseLib.Lookup("offer-eligibility-deconfirmation", LanguageID), strGroups) + "');", true); } else { Save(); } } else { Save(); } }