Esempio n. 1
0
    private bool DeleteGroup()
    {
        CMS.AMS.Models.CustomerGroupConditions cusconditions = m_CustGroupCondition.GetOfferCustomerCondition(hdnOfferID.Value.ConvertToLong(), hdnEngineID.Value.ConvertToInt32());
        if (cusconditions.IncludeCondition.Count <= 1 && hdnEngineID.Value.ConvertToInt32() != 0) //Exception for CM Engine
        {
            ////Only one Default condition exists, need to chcek if other conditions exists or not
            //if (m_Offer.IsOtherOfferConditionsExistsExceptCustomer(hdnOfferID.Value.ConvertToLong(), hdnEngineID.Value.ConvertToInt32()))
            //{
            infobar.InnerText = PhraseLib.Lookup("OptInGroup-DeleteGroup", LanguageID);
            infobar.Visible   = true;
            return(false);
            //}
        }


        m_Offer.DeleteOfferEligibleConditions(hdnOfferID.Value.ConvertToLong(), hdnEngineID.Value.ConvertToInt32());
        if (DefaultCustomerGroup != null)
        {
            m_Offer.DeleteCustomerConditionByGroupID(hdnOfferID.Value.ConvertToLong(), hdnEngineID.Value.ConvertToInt32(), DefaultCustomerGroup.CustomerGroupID);

            m_CustGroup.DeleteCustomerGroup(DefaultCustomerGroup.CustomerGroupID);
            historyString = PhraseLib.Lookup("cgroup-edit.delete", LanguageID) + ": " + DefaultCustomerGroup.CustomerGroupID;
            WriteToActivityLog();
        }
        ClientScript.RegisterStartupScript(this.GetType(), "pageclose", "<script>CloseModel()</script>");
        return(true);
    }
 private void GetOfferEligibleCustomerCondition()
 {
     if (ConditionID == 0)
     {
         OfferEligibileCustomerGroupCondition = new CMS.AMS.Models.CustomerGroupConditions();
         OfferEligibileCustomerGroupCondition.IncludeCondition = new List <CMS.AMS.Models.CustomerConditionDetails>();
         OfferEligibileCustomerGroupCondition.ExcludeCondition = new List <CMS.AMS.Models.CustomerConditionDetails>();
         OfferEligibileCustomerGroupCondition.ConditionTypeID  = m_CustCondition.GetCustomerGroupConditionTypeID(EngineID);
         OfferEligibileCustomerGroupCondition.EngineID         = EngineID;
     }
     else
     {
         OfferEligibileCustomerGroupCondition = m_CustCondition.GetConditionByID(ConditionID);
         if (OfferEligibileCustomerGroupCondition == null)
         {
             throw new Exception("Invalid ConditionID");
         }
     }
 }
    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;
        }
    }