Esempio n. 1
0
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <param name="context">The context.</param>
        public void SaveChanges(IDictionary context)
        {
            ExpressionDto dto = (ExpressionDto)context[_ExpressionDtoString];

            ExpressionDto.ExpressionRow row = null;

            if (dto.Expression.Count > 0)
            {
                row          = dto.Expression[0];
                row.Modified = DateTime.UtcNow;
            }
            else
            {
                row = dto.Expression.NewExpressionRow();
                row.ApplicationId = MarketingConfiguration.Instance.ApplicationId;
                row.Category      = ddlExpressionCategory.SelectedValue;
                row.Created       = DateTime.UtcNow;
            }

            row.Name          = tbExpressionName.Text;
            row.Description   = tbDescription.Text;
            row.ExpressionXml = tbXml.Text;
            row.ModifiedBy    = Page.User.Identity.Name;

            if (row.RowState == DataRowState.Detached)
            {
                dto.Expression.Rows.Add(row);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the Expression dto, checks permissions and caches results.
        /// </summary>
        /// <param name="expressionId">The expression id.</param>
        /// <returns></returns>
        public static ExpressionDto GetExpressionDto(int expressionId)
        {
            // Assign new cache key, specific for site guid and response groups requested
            //string cacheKey = MarketingCache.CreateCacheKey("Expression", ExpressionId.ToString());

            ExpressionDto dto = null;

            // check cache first
            //object cachedObject = MarketingCache.Get(cacheKey);

            //if (cachedObject != null)
            //  dto = (ExpressionDto)cachedObject;

            // Load the object
            if (dto == null)
            {
                ExpressionAdmin Expression = new ExpressionAdmin();
                Expression.Load(expressionId);
                dto = Expression.CurrentDto;

                // Insert to the cache collection
                //MarketingCache.Insert(cacheKey, dto, MarketingConfiguration.CacheConfig.ExpressionCollectionTimeout);
            }

            dto.AcceptChanges();

            return(dto);
        }
Esempio n. 3
0
        /// <summary>
        /// Loads the context.
        /// </summary>
        private void LoadContext()
        {
            if (ExpressionId > 0)
            {
                ExpressionDto expression = null;
                if (!this.IsPostBack && (!this.Request.QueryString.ToString().Contains("Callback=yes"))) // load fresh on initial load
                {
                    expression = LoadFresh();
                }
                else // load from session
                {
                    expression = (ExpressionDto)Session[_ExpressionDtoEditSessionKey];

                    if (expression == null)
                    {
                        expression = LoadFresh();
                    }
                }

                // Put a dictionary key that can be used by other tabs
                IDictionary dic = new ListDictionary();
                dic.Add(_ExpressionDtoString, expression);

                // Call tabs load context
                ViewControl.LoadContext(dic);

                _Expression = expression;
            }
        }
Esempio n. 4
0
        private RuleSet GetPromotionRuleSet(string expressionPlace, string expressionKey)
        {
            RuleSet retVal = null;

            int expressionId = Int32.Parse(expressionKey);

            if (expressionId > 0)
            {
                if (DataSource == null)
                {
                    throw new NullReferenceException("DataSource is null");
                }

                ExpressionDto dto = GetDataSourceDto(DataSource);
                ExpressionDto.ExpressionRow row = dto.Expression.FindByExpressionId(expressionId);

                if (row != null)                 // new one
                {
                    StringReader             stringReader = new StringReader(row.ExpressionXml);
                    XmlTextReader            reader       = new XmlTextReader(stringReader);
                    WorkflowMarkupSerializer serializer   = new WorkflowMarkupSerializer();
                    retVal = serializer.Deserialize(reader) as RuleSet;
                }
            }

            return(retVal);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates the expression row.
        /// </summary>
        /// <param name="expressionDto">The expression dto.</param>
        /// <returns></returns>
        public ExpressionDto.ExpressionRow CreateExpressionRow(ref ExpressionDto expressionDto)
        {
            PromotionDto.PromotionConditionRow row           = null;
            ExpressionDto.ExpressionRow        expressionRow = null;

            if (_PromotionDto.PromotionCondition.Count == 0)
            {
                row                         = _PromotionDto.PromotionCondition.NewPromotionConditionRow();
                row.PromotionId             = _PromotionDto.Promotion[0].PromotionId;
                expressionRow               = expressionDto.Expression.NewExpressionRow();
                expressionRow.ApplicationId = MarketingConfiguration.Instance.ApplicationId;
                expressionRow.Category      = ExpressionCategory.CategoryKey.Promotion.ToString();
                expressionRow.Created       = DateTime.UtcNow;
            }
            else
            {
                row           = _PromotionDto.PromotionCondition[0];
                expressionDto = ExpressionManager.GetExpressionDto(row.ExpressionId);
                expressionRow = expressionDto.Expression[0];
            }

            expressionRow.ModifiedBy  = Page.User.Identity.Name;
            expressionRow.Description = _Config.Description;
            expressionRow.Name        = _Config.Type;

            row.ExpressionId = expressionRow.ExpressionId;

            if (row.RowState == DataRowState.Detached)
            {
                PromotionDto.PromotionCondition.Rows.Add(row);
            }

            return(expressionRow);
        }
Esempio n. 6
0
        /// <summary>
        /// Loads the context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void LoadContext(IDictionary context)
        {
            _segment    = (SegmentDto)context[_SegmentDtoString];
            _expression = (ExpressionDto)context[_ExpressionDtoString];

            RulesEditorCtrl.LoadContext(context);
        }
Esempio n. 7
0
        /// <summary>
        /// Loads the expressions.
        /// </summary>
        /// <param name="iStartIndex">Start index of the i.</param>
        /// <param name="iNumItems">The i num items.</param>
        /// <param name="sFilter">The s filter.</param>
        private void LoadExpressions(int iStartIndex, int iNumItems, string sFilter)
        {
            ExpressionDto dto = ExpressionManager.GetExpressionDto(ExpressionCategory.GetExpressionCategory(ExpressionCategory.CategoryKey.Promotion).Key);

            ExpressionFilter.DataSource = dto.Expression;
            ExpressionFilter.DataBind();
        }
Esempio n. 8
0
        /// <summary>
        /// Loads the expressions.
        /// </summary>
        private void LoadExpressions()
        {
            ExpressionDto dto = ExpressionManager.GetExpressionDto(ExpressionCategory.GetExpressionCategory(ExpressionCategory.CategoryKey.Policy).Key);

            ddlExpression.DataSource = dto;
            ddlExpression.DataBind();
        }
Esempio n. 9
0
        /// <summary>
        /// Processes the delete command.
        /// </summary>
        /// <param name="items">The items.</param>
        void ProcessDeleteCommand(string[] items)
        {
            for (int i = 0; i < items.Length; i++)
            {
                string[] keys = EcfListView.GetPrimaryKeyIdStringItems(items[i]);
                if (keys != null)
                {
                    string     id             = keys[0];
                    List <int> expressionList = new List <int>();

                    SegmentDto dto = SegmentManager.GetSegmentDto(Int32.Parse(id));
                    if (dto.Segment.Count > 0)
                    {
                        SegmentDto.SegmentRow segmentRow = dto.Segment[0];
                        foreach (SegmentDto.SegmentConditionRow condition in segmentRow.GetSegmentConditionRows())
                        {
                            expressionList.Add(condition.ExpressionId);
                        }
                        dto.Segment[0].Delete();
                        SegmentManager.SaveSegment(dto);
                    }

                    // Delete corresponding expressions
                    foreach (int expressionId in expressionList)
                    {
                        ExpressionDto expressionDto = ExpressionManager.GetExpressionDto(expressionId);
                        if (expressionDto != null && expressionDto.Expression.Count > 0)
                        {
                            expressionDto.Expression[0].Delete();
                            ExpressionManager.SaveExpression(expressionDto);
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            _ExpressionDto = (ExpressionDto)HttpContext.Current.Session[_ExpressionDtoEditSessionKey];
            _SegmentDto    = HttpContext.Current.Session[_SegmentDtoEditSessionKey] as SegmentDto;
            if (_ExpressionDto == null || _SegmentDto == null)  // close the window
            {
                CommandParameters cp = new CommandParameters(_RuleEditCommandString);
                CommandHandler.RegisterCloseOpenedFrameScript(this.Page, cp.ToString());
                ExprFilter.Visible = false;
            }


            if (!this.IsPostBack)
            {
                if (_ExpressionDto != null)
                {
                    //Request for create expresion
                    if (IsCreateExpression)
                    {
                        //Add new ExpressionCollection to session
                        ExpressionFilters.Add(new FilterExpressionNodeCollection());
                        //Change iterator position to new collections
                        ExpressionIndex = ExpressionFilters.Count - 1;
                    }
                    else
                    {
                        BindForm();
                    }
                    BindExpressionEditor(ExpressionFilter);
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            ExpressionDto expression = (ExpressionDto)Session[_ExpressionDtoEditSessionKey];             //null;

            if (ExpressionId > 0 && expression == null)
            {
                expression = ExpressionManager.GetExpressionDto(ExpressionId);                 //Int32.Parse(Parameters["ExpressionId"].ToString()));
            }
            else if (ExpressionId == 0)
            {
                expression = new ExpressionDto();
            }

            IDictionary context = new ListDictionary();

            context.Add(_ExpressionDtoString, expression);

            ViewControl.SaveChanges(context);

            if (expression.HasChanges())
            {
                ExpressionManager.SaveExpression(expression);
            }

            // we don't need to store Dto in session any more
            Session.Remove(_ExpressionDtoEditSessionKey);
        }
Esempio n. 12
0
        /// <summary>
        /// Saves the expression.
        /// </summary>
        /// <param name="dto">The dto.</param>
        public static void SaveExpression(ExpressionDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException("dto", String.Format("ExpressionDto can not be null"));
            }

            //TODO: check concurrency when updating the records

            //TODO: need to check security roles here,
            // The procedure will be following:
            // 1. Retrieve the record from the database for each category that is about to be updated
            // 2. Check Write permissions (if failed generate the error and exit)
            // 3. Otherwise proceed to update
            // Continue with security checks and other operations

            /*
             * foreach (ExpressionDto.ExpressionRow row in dto.Expression.Rows)
             * {
             *  // Check Security
             *  IDataReader reader = DataHelper.CreateDataReader(dto.ExpressionSecurity, String.Format("ExpressionId = -1 or ExpressionId = {0}", row.ExpressionId));
             *  PermissionRecordSet recordSet = new PermissionRecordSet(PermissionHelper.ConvertReaderToRecords(reader));
             *  if (!PermissionManager.CheckPermission(ExpressionScope.Expression, Permission.Read, recordSet))
             *  {
             *      row.Delete();
             *      continue;
             *  }
             * }
             * */


            ExpressionAdmin admin = new ExpressionAdmin(dto);

            admin.Save();
        }
Esempio n. 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MarketingHelper"/> class.
 /// </summary>
 /// <param name="campaigns">The campaigns.</param>
 /// <param name="expressions">The expressions.</param>
 /// <param name="policies">The policies.</param>
 /// <param name="promotions">The promotions.</param>
 /// <param name="segments">The segments.</param>
 public MarketingHelper(CampaignDto campaigns, ExpressionDto expressions, PolicyDto policies, PromotionDto promotions, SegmentDto segments)
 {
     _Campaigns   = campaigns;
     _Expressions = expressions;
     _Policies    = policies;
     _Promotions  = promotions;
     _Segments    = segments;
 }
Esempio n. 14
0
        public override global::System.Data.DataSet Clone()
        {
            ExpressionDto cln = ((ExpressionDto)(base.Clone()));

            cln.InitVars();
            cln.SchemaSerializationMode = this.SchemaSerializationMode;
            return(cln);
        }
Esempio n. 15
0
        /// <summary>
        /// Loads the fresh.
        /// </summary>
        /// <returns></returns>
        private ExpressionDto LoadFresh()
        {
            ExpressionDto expression = ExpressionManager.GetExpressionDto(ExpressionId);

            // persist in session
            Session[_ExpressionDtoEditSessionKey] = expression;

            return(expression);
        }
        /// <summary>
        /// Saves the expression.
        /// </summary>
        /// <param name="set">The set.</param>
        /// <param name="expressionId">The expression id.</param>
        protected virtual void SaveExpression(RuleSet set, int expressionId)
        {
            if (set == null)
            {
                throw new ArgumentNullException("RuleSet");
            }

            if (DataSource == null)
            {
                throw new ArgumentNullException("DataSource");
            }

            ExpressionDto dto = GetDataSourceDto(DataSource);

            ExpressionDto.ExpressionRow row = dto.Expression.FindByExpressionId(expressionId);

            if (row == null /*&& (expressionId == 0 || dto.Expression.Count == 0)*/)             // new one
            {
                row               = dto.Expression.NewExpressionRow();
                row.Name          = set.Name;
                row.Description   = String.Empty;
                row.ApplicationId = MarketingConfiguration.Instance.ApplicationId;
                row.Category      = ExpressionCategory.CategoryKey.Segment.ToString();
                row.Created       = DateTime.UtcNow;
            }
            else
            {
                row.Modified = DateTime.UtcNow;
            }

            // Serialize ruleset
            StringBuilder ruleDefinition = new StringBuilder();

            #region Serialize

            StringWriter             stringWriter = new StringWriter(ruleDefinition, CultureInfo.InvariantCulture);
            XmlTextWriter            writer       = new XmlTextWriter(stringWriter);
            WorkflowMarkupSerializer serializer   = new WorkflowMarkupSerializer();
            serializer.Serialize(writer, set);
            #endregion

            #region Cleanup

            writer.Flush();
            writer.Close();
            stringWriter.Flush();
            stringWriter.Close();
            #endregion

            row.ExpressionXml = ruleDefinition.ToString();

            if (row.RowState == System.Data.DataRowState.Detached)
            {
                dto.Expression.Rows.Add(row);
            }
        }
Esempio n. 17
0
        protected override Expression Visit(ExpressionDto expression)
        {
            if (this.expressions.ContainsKey(expression))
            {
                return(this.expressions[expression]);
            }
            var result = base.Visit(expression);

            this.expressions.Add(expression, result);
            return(result);
        }
Esempio n. 18
0
        public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs)
        {
            ExpressionDto ds = new ExpressionDto();

            global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
            global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
            global::System.Xml.Schema.XmlSchemaAny         any      = new global::System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                try {
                    global::System.Xml.Schema.XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                    {
                        schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) &&
                                    (s1.ReadByte() == s2.ReadByte()));)
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return(type);
                            }
                        }
                    }
                }
                finally {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return(type);
        }
Esempio n. 19
0
        /// <summary>
        /// Loads the data and data bind.
        /// </summary>
        /// <param name="sortExpression">The sort expression.</param>
        private void LoadDataAndDataBind(string sortExpression)
        {
            ExpressionDto dto = ExpressionManager.GetExpressionDto(ExpressionCategory);

            if (dto.Expression != null)
            {
                DataView view = dto.Expression.DefaultView;
                view.Sort             = sortExpression;
                MyListView.DataSource = view;
            }

            MyListView.CurrentListView.PrimaryKeyId = EcfListView.MakePrimaryKeyIdString("ExpressionId");
            MyListView.DataBind();
        }
Esempio n. 20
0
        public void Add()
        {
            var collection = db.GetCollection <ExpressionDto>(_table);

            foreach (var expression in _store)
            {
                var expressionDto = new ExpressionDto()
                {
                    Infix  = string.Join("", expression.InfixNotationValue),
                    Result = expression.Result
                };

                collection.InsertOne(expressionDto);
            }
        }
Esempio n. 21
0
    /// <summary>
    /// Saves the changes.
    /// </summary>
    /// <param name="context">The context.</param>
    public override void SaveChanges(IDictionary context)
    {
        base.SaveChanges(context);

        // Populate setting
        Settings settings = new Settings();

        settings.EntryXFilter   = EntryXFilter.SelectedEntryCode;
        settings.EntryYFilter   = EntryYFilter.SelectedEntryCode;
        settings.SourceQuantity = Decimal.Parse(SourceQuantity.Text);
        settings.TargetQuantity = Decimal.Parse(TargetQuantity.Text);
        settings.AmountOff      = Decimal.Parse(OfferAmount.Text);
        int offerType = Int32.Parse(OfferType.SelectedValue);

        settings.AmountType = offerType == 1 ? PromotionRewardAmountType.Percentage : PromotionRewardAmountType.Value;
        settings.RewardType = PromotionRewardType.EachAffectedEntry;

        // Create custom expression from template
        string expr = Replace(Config.Expression, settings);

        // save properties for promotion
        PromotionDto.PromotionRow promotion = PromotionDto.Promotion[0];
        promotion.OfferAmount = Decimal.Parse(OfferAmount.Text);
        promotion.OfferType   = Int32.Parse(OfferType.SelectedValue);
        promotion.Params      = SerializeSettings(settings);

        // Create or modify expression
        ExpressionDto expressionDto = new ExpressionDto();

        //PromotionDto.PromotionConditionRow row = null;

        ExpressionDto.ExpressionRow expressionRow = CreateExpressionRow(ref expressionDto);
        expressionRow.Category      = ExpressionCategory.CategoryKey.Promotion.ToString();
        expressionRow.ExpressionXml = expr;
        if (expressionRow.RowState == DataRowState.Detached)
        {
            expressionDto.Expression.Rows.Add(expressionRow);
        }

        // Save expression
        ExpressionManager.SaveExpression(expressionDto);

        // Assign expression id to our new condition
        PromotionDto.PromotionCondition[0].ExpressionId = expressionRow.ExpressionId;

        //if (row.RowState == DataRowState.Detached)
        //PromotionDto.PromotionCondition.Rows.Add(row);
    }
Esempio n. 22
0
        /// <summary>
        /// Gets the expression dto.
        /// </summary>
        /// <param name="segmentId">The segment id.</param>
        /// <returns></returns>
        public static ExpressionDto GetExpressionBySegmentDto(int segmentId)
        {
            ExpressionDto dto = null;

            // Load the object
            if (dto == null)
            {
                ExpressionAdmin Expression = new ExpressionAdmin();
                Expression.LoadBySegment(segmentId);
                dto = Expression.CurrentDto;
            }

            dto.AcceptChanges();

            return(dto);
        }
Esempio n. 23
0
        /// <summary>
        /// Gets the ExpressionDto by category. The supported categories now are "Promotion", "Segment", "Policy".
        /// </summary>
        /// <param name="category">The category.</param>
        /// <returns></returns>
        public static ExpressionDto GetExpressionDto(string category)
        {
            ExpressionDto dto = null;

            // Load the object
            if (dto == null)
            {
                ExpressionAdmin Expression = new ExpressionAdmin();
                Expression.LoadByCategory(category);
                dto = Expression.CurrentDto;
            }

            dto.AcceptChanges();

            return(dto);
        }
Esempio n. 24
0
    /// <summary>
    /// Saves the changes.
    /// </summary>
    /// <param name="context">The context.</param>
    public override void SaveChanges(IDictionary context)
    {
        base.SaveChanges(context);

        // Populate setting
        Settings settings = new Settings();

        settings.TargetExpression    = ApplyConditionFilter.NodeCollection[0].ChildNodes;
        settings.ConditionExpression = ConditionFilter.NodeCollection[0].ChildNodes;


        // save properties for promotion
        PromotionDto.PromotionRow promotion = PromotionDto.Promotion[0];
        promotion.Params = SerializeSettingsBinary(settings);

        //// Create custom expression from template
        //string expr = Replace(Config.Expression, settings);

        //// Create or modify expression
        ExpressionDto expressionDto = new ExpressionDto();

        ExpressionDto.ExpressionRow expressionRow = CreateExpressionRow(ref expressionDto);
        expressionRow.Category      = ExpressionCategory.CategoryKey.Promotion.ToString();
        expressionRow.ExpressionXml = string.Empty;
        if (expressionRow.RowState == DataRowState.Detached)
        {
            expressionDto.Expression.Rows.Add(expressionRow);
        }
        //Change DataSource from FilterNodeCollection  to ExpressionDto
        ConditionFilter.Provider.DataSource = expressionDto;
        ConditionFilter.Provider.SaveFilters("PromotionCondition", expressionRow.ExpressionId.ToString(),
                                             settings.ConditionExpression);

        //// Save expression
        ExpressionManager.SaveExpression(expressionDto);

        ApplyConditionFilter.DataSource = expressionDto;
        ApplyConditionFilter.Provider.SaveFilters("PromotionAction", expressionRow.ExpressionId.ToString(),
                                                  settings.TargetExpression);


        //// Save expression
        ExpressionManager.SaveExpression(expressionDto);

        //// Assign expression id to our new condition
        PromotionDto.PromotionCondition[0].ExpressionId = expressionRow.ExpressionId;
    }
Esempio n. 25
0
        /// <summary>
        /// Processes the delete command.
        /// </summary>
        /// <param name="items">The items.</param>
        void ProcessDeleteCommand(string[] items)
        {
            for (int i = 0; i < items.Length; i++)
            {
                string[] keys = EcfListView.GetPrimaryKeyIdStringItems(items[i]);
                if (keys != null)
                {
                    int id = Int32.Parse(keys[0]);

                    ExpressionDto dto = ExpressionManager.GetExpressionDto(id);
                    if (dto.Expression.Count > 0)
                    {
                        dto.Expression[0].Delete();
                        ExpressionManager.SaveExpression(dto);
                    }
                }
            }
        }
Esempio n. 26
0
        private ExpressionDto LoadFreshExpression()
        {
            ExpressionDto expression = null;

            if (SegmentId == 0)
            {
                // Create an empty expression
                expression = new ExpressionDto();
            }
            else
            {
                expression = ExpressionManager.GetExpressionBySegmentDto(SegmentId);
            }

            // persist in session
            Session[_ExpressionDtoEditSessionKey] = expression;

            return(expression);
        }
Esempio n. 27
0
        public void Upsert(Guid id, IExpressionSubject expression)
        {
            var collectioin = db.GetCollection <ExpressionDto>(_table);
            var filter      = Builders <ExpressionDto> .Filter.Eq("Id", id);

            var expressionDto = new ExpressionDto()
            {
                Infix  = string.Join("", expression.InfixNotationValue),
                Result = expression.Result
            };

            collectioin.ReplaceOne(
                filter,
                expressionDto,
                new ReplaceOptions()
            {
                IsUpsert = true
            });
        }
Esempio n. 28
0
        /// <summary>
        /// Processes the delete command.
        /// </summary>
        /// <param name="items">The items.</param>
        void ProcessDeleteCommand(string[] items)
        {
            for (int i = 0; i < items.Length; i++)
            {
                string[] keys = EcfListView.GetPrimaryKeyIdStringItems(items[i]);
                if (keys != null)
                {
                    string id = keys[0];

                    using (TransactionScope scope = new TransactionScope())
                    {
                        // delete selected sites
                        PromotionDto dto            = PromotionManager.GetPromotionDto(Int32.Parse(id));
                        List <int>   expressionList = new List <int>();
                        if (dto.Promotion.Count > 0)
                        {
                            PromotionDto.PromotionRow promotionRow = dto.Promotion[0];
                            foreach (PromotionDto.PromotionConditionRow condition in promotionRow.GetPromotionConditionRows())
                            {
                                expressionList.Add(condition.ExpressionId);
                            }
                            dto.Promotion[0].Delete();
                            PromotionManager.SavePromotion(dto);

                            // Delete corresponding expressions
                            foreach (int expressionId in expressionList)
                            {
                                ExpressionDto expressionDto = ExpressionManager.GetExpressionDto(expressionId);
                                if (expressionDto != null && expressionDto.Expression.Count > 0)
                                {
                                    expressionDto.Expression[0].Delete();
                                    ExpressionManager.SaveExpression(expressionDto);
                                }
                            }
                        }

                        scope.Complete();
                    }
                }
            }
        }
Esempio n. 29
0
    /// <summary>
    /// Saves the changes.
    /// </summary>
    /// <param name="context">The context.</param>
    public override void SaveChanges(IDictionary context)
    {
        base.SaveChanges(context);

        // Populate setting
        Settings settings = new Settings();

        settings.EntryXFilter = EntryXFilter.SelectedEntryCode;
        settings.EntryYFilter = EntryYFilter.SelectedEntryCode;
        // Create custom expression from template
        string expr = Replace(Config.Expression, settings);

        // save properties for promotion
        PromotionDto.PromotionRow promotion = PromotionDto.Promotion[0];
        promotion.OfferAmount = 100;
        promotion.OfferType   = 0; //undef not use
        promotion.Params      = SerializeSettings(settings);

        // Create or modify expression
        ExpressionDto expressionDto = new ExpressionDto();

        //PromotionDto.PromotionConditionRow row = null;

        ExpressionDto.ExpressionRow expressionRow = CreateExpressionRow(ref expressionDto);
        expressionRow.Category      = ExpressionCategory.CategoryKey.Promotion.ToString();
        expressionRow.ExpressionXml = expr;
        if (expressionRow.RowState == DataRowState.Detached)
        {
            expressionDto.Expression.Rows.Add(expressionRow);
        }

        // Save expression
        ExpressionManager.SaveExpression(expressionDto);

        // Assign expression id to our new condition
        PromotionDto.PromotionCondition[0].ExpressionId = expressionRow.ExpressionId;

        //if (row.RowState == DataRowState.Detached)
        //PromotionDto.PromotionCondition.Rows.Add(row);
    }
Esempio n. 30
0
        /// <summary>
        /// Handles the Click event of the SaveButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            ExpressionDto dto = (ExpressionDto)HttpContext.Current.Session[_ExpressionDtoEditSessionKey];

            if (dto != null)
            {
                ExpressionFilter = ExprFilter.NodeCollection[0].ChildNodes;

                ExprFilter.Visible    = true;
                ExprFilter.DataSource = dto;
                ExprFilter.Provider.SaveFilters(_RulesPrefix, ExpressionId.ToString(), ExpressionFilter);
                ExpressionDto.ExpressionRow row = null;
                if (ExpressionId == 0) // get the last row added
                {
                    row = dto.Expression[dto.Expression.Count - 1];
                }
                else
                {
                    row = dto.Expression.FindByExpressionId(ExpressionId);
                }

                row.Name = ExpressionName.Text;
            }
            else
            {
                ExprFilter.Visible = false;
            }
            ////Serialize FilterExpression in segment table
            //if (_SegmentDto != null && _SegmentDto.Segment.Count > 0)
            //{
            //    SegmentDto.SegmentRow row = _SegmentDto.Segment[0];
            //    row.ExpressionFilter = SerializeFilterExpressions(ExpressionFilters);
            //}

            CommandParameters cp = new CommandParameters(_RuleEditCommandString);

            CommandHandler.RegisterCloseOpenedFrameScript(this.Page, cp.ToString());
        }