private static void SaveOptions(EditAttribute editAttribute, int attributeID)
        {
            var curList = AttributeOptions.GetByAttributeID(attributeID);

            foreach (var option in editAttribute.Options)
            {
                if (!curList.Any(item => item.ID == option.ID))
                {
                    var attributeOption = new AttributeOption();

                    attributeOption.AttributeID = attributeID;
                    attributeOption.Title       = option.Title;

                    AttributeOptions.Insert(attributeOption);
                }
                else
                {
                    var item = curList.Single(cls => cls.ID == option.ID);

                    curList.Remove(item);

                    item.Title   = option.Title;
                    item.OrderID = option.OrderID;

                    AttributeOptions.Update(item);
                }
            }

            foreach (var item in curList)
            {
                AttributeOptions.Delete(item.ID);
            }
        }
Esempio n. 2
0
        private void FirstGridViewRow()
        {
            DataTable dt = new DataTable();
            DataRow   dr = null;

            dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
            dt.Columns.Add(new DataColumn("Col1", typeof(string)));
            dt.Columns.Add(new DataColumn("Col2", typeof(string)));

            dr = dt.NewRow();
            dr["RowNumber"] = 1;
            dr["Col1"]      = string.Empty;
            dr["Col2"]      = string.Empty;
            dt.Rows.Add(dr);

            ViewState["CurrentTable"] = dt;

            AttributeOptions.DataSource = dt;
            AttributeOptions.DataBind();

            TextBox txn = (TextBox)AttributeOptions.Rows[0].Cells[2].FindControl("priorityNo");

            txn.Focus();
            Button btnAdd = (Button)AttributeOptions.FooterRow.Cells[1].FindControl("ButtonAdd");

            Page.Form.DefaultFocus = btnAdd.ClientID;
        }
        public void UnEncodeQuote()
        {
            var options = new AttributeOptions {
                EncodeQuotes = true
            };

            Assert.AreEqual("name='{\"name\":\"daniel\"}'",
                            new AttributeBase("name", "{\"name\":\"daniel\"}").ToString());
            Assert.AreEqual("name='{"name":"daniel"}'",
                            new AttributeBase("name", "{\"name\":\"daniel\"}", options).ToString());

            options = new AttributeOptions {
                Quote = "\""
            };
            Assert.AreEqual("name=\"{"name":"daniel"}\"",
                            new AttributeBase("name", "{\"name\":\"daniel\"}", options).ToString(),
                            "with a different quote and encodeQuotes false");

            options = new AttributeOptions {
                EncodeQuotes = true, Quote = "\""
            };
            Assert.AreEqual("name=\"{"name":"daniel"}\"",
                            new AttributeBase("name", "{\"name\":\"daniel\"}", options).ToString(),
                            "with a different quote and encodeQuotes = true");
        }
Esempio n. 4
0
        protected void AttributeOptions_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                SetRowData();
                if (ViewState["CurrentTable"] != null)
                {
                    DataTable dt           = (DataTable)ViewState["CurrentTable"];
                    DataRow   drCurrentRow = null;
                    int       rowIndex     = Convert.ToInt32(e.RowIndex);
                    if (dt.Rows.Count > 1)
                    {
                        dt.Rows.Remove(dt.Rows[rowIndex]);
                        drCurrentRow = dt.NewRow();
                        ViewState["CurrentTable"]   = dt;
                        AttributeOptions.DataSource = dt;
                        AttributeOptions.DataBind();

                        for (int i = 0; i < AttributeOptions.Rows.Count - 1; i++)
                        {
                            AttributeOptions.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                        }
                        SetPreviousData();
                    }
                }
            }
            catch (Exception exc)
            {
                LogUtils.myLog.Info(exc, exc);
            }
        }
        public void BasicAttributesQuote()
        {
            var options = new AttributeOptions {
                Quote = "\""
            };

            Assert.AreEqual("name=\"value\"",
                            new AttributeBase("name", "value", options).ToString());
            Assert.AreEqual("something=\"other\"",
                            new AttributeBase("something", "other", options).ToString());
        }
Esempio n. 6
0
        /// <summary>
        /// Create an attribute, which can then generated into a name='value' output
        /// </summary>
        /// <param name="name">The attribute name, can also be a prepared attribute. So you can pass in "id" or "id='27'"</param>
        /// <param name="value">The value, if the initial name was really only a name. If it's an object, it will be json serialized</param>
        /// <param name="options">Options how the attribute will be generated</param>
        public AttributeBase(string name, object value = null, AttributeOptions options = null)
        {
            if (name?.IndexOf("=") > 0)
            {
                Prepared = name;
            }
            else
            {
                Name  = name;
                Value = value;
            }

            Options = options;
        }
Esempio n. 7
0
        /// <summary>
        /// Create an attribute, which can then generated into a name='value' output
        /// </summary>
        /// <param name="name">The attribute name, can also be a prepared attribute. So you can pass in "id" or "id='27'"</param>
        /// <param name="value">The value, if the initial name was really only a name. If it's an object, it will be json serialized</param>
        /// <param name="options">Options how the attribute will be generated</param>
        public AttributeBase(string name, object value = null, AttributeOptions options = null)
        {
            if (name?.IndexOf("=") > 0)
            {
                Prepared = name;
            }
            else
            {
                Name = name;
                // if (value is ITag htmlValue) value = htmlValue.ToString();
                Value = value is ITag htmlValue?htmlValue.ToString() : value;
            }

            Options = options;
        }
        public ActionResult Edit(EditAttribute editAttribute)
        {
            try
            {
                var attribute = Mapper.Map <Attribute>(editAttribute);

                attribute.LastUpdate = DateTime.Now;

                ViewBag.Success = true;

                int attributeID = attribute.ID;
                if (attributeID == -1)
                {
                    Attributes.Insert(attribute);
                    attributeID = attribute.ID;

                    SaveGroups(editAttribute, attribute.ID);
                    SaveOptions(editAttribute, attribute.ID);

                    UserNotifications.Send(UserID, String.Format("جدید - ویژگی '{0}'", attribute.Title), "/Admin/Attributes/Edit/" + attribute.ID, NotificationType.Success);
                    editAttribute = new EditAttribute();
                }
                else
                {
                    Attributes.Update(attribute);

                    SaveGroups(editAttribute, attribute.ID);
                    SaveOptions(editAttribute, attribute.ID);

                    editAttribute.Groups  = AttributeGroups.GetByAttributeID(editAttribute.ID).Select(item => item.GroupID).ToList();
                    editAttribute.Options = AttributeOptions.GetByAttributeID(editAttribute.ID).Select(item => new EditAttributeOption()
                    {
                        ID = item.ID, AttributeID = item.AttributeID, Title = item.Title
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
                SetErrors(ex);
            }

            return(ClearView(editAttribute));
        }
        public JsonResult GetAttrOptions(int attrID)
        {
            var jsonSuccessResult = new JsonSuccessResult();

            try
            {
                var attrType = Attributes.GetByID(attrID).AttributeType;

                object model;

                if (attrType == AttributeType.SingleItem || attrType == AttributeType.MultipleItem)
                {
                    model = new
                    {
                        Options  = AttributeOptions.GetByAttributeID(attrID),
                        HasItems = true
                    };

                    jsonSuccessResult.Data = model;
                }
                else
                {
                    model = new
                    {
                        HasItems = false
                    };

                    jsonSuccessResult.Data = model;
                }

                jsonSuccessResult.Success = true;
            }
            catch (Exception ex)
            {
                jsonSuccessResult.Errors  = new string[] { ex.Message };
                jsonSuccessResult.Success = false;
            }

            return(new JsonResult()
            {
                Data = jsonSuccessResult
            });
        }
        public void BasicAttributesEmpty()
        {
            Assert.AreEqual("name=''",
                            new AttributeBase("name", "").ToString());
            Assert.AreEqual("name",
                            new AttributeBase("name", null).ToString());
            Assert.AreEqual("name=''",
                            new AttributeBase("name", null,
                                              new AttributeOptions {
                DropValueIfNull = false
            }).ToString());

            var options = new AttributeOptions {
                KeepEmpty = false
            };

            Assert.AreEqual("",
                            new AttributeBase("name", "", options).ToString());
        }
Esempio n. 11
0
        private void FirstGridViewRow(int inputId)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
            dt.Columns.Add(new DataColumn("Col1", typeof(string)));
            dt.Columns.Add(new DataColumn("Col2", typeof(string)));

            List <QueAttributeOption> queAttrOptionList = queDaoObj.getOptionsListByAttributeID(inputId);
            int rowCount = 0;

            foreach (QueAttributeOption option in queAttrOptionList)
            {
                DataRow dr = null;
                dr = dt.NewRow();
                dr["RowNumber"] = rowCount + 1;
                dr["Col1"]      = option.priorityOption;
                dr["Col2"]      = option.optionStatement;
                dt.Rows.Add(dr);

                rowCount++;
            }

            ViewState["CurrentTable"]   = dt;
            AttributeOptions.DataSource = dt;
            AttributeOptions.DataBind();

            for (int count = 0; count < rowCount; count++)
            {
                TextBox TextBoxName = (TextBox)AttributeOptions.Rows[count].Cells[2].FindControl("txtName");
                TextBoxName.Text = queAttrOptionList[count].optionStatement;
                TextBox PriorityTextBox = (TextBox)AttributeOptions.Rows[count].Cells[1].FindControl("priorityNo");
                PriorityTextBox.Text = queAttrOptionList[count].priorityOption;
            }

            TextBox txn = (TextBox)AttributeOptions.Rows[0].Cells[1].FindControl("priorityNo");

            txn.Focus();
            Button btnAdd = (Button)AttributeOptions.FooterRow.Cells[1].FindControl("ButtonAdd");

            Page.Form.DefaultFocus = btnAdd.ClientID;
        }
Esempio n. 12
0
        /// <summary>
        /// Internal string-based commands to keep data simple till ready for output
        /// </summary>
        /// <returns></returns>
        private string Build()
        {
            var currentOptions = AttributeOptions.UseOrCreate(Options);

            if (Value == null && currentOptions.DropValueIfNull)
            {
                return(Name);
            }

            var val = Internals.Html.Encode(ValueStringOrSerialized(Value)) ?? "";

            if (!currentOptions.EncodeQuotes)
            {
                var safeQuote = currentOptions.Quote == "'" ? "\"" : "'";
                val = val.Replace(Internals.Html.Encode(safeQuote), safeQuote);
            }

            return(currentOptions.KeepEmpty || !string.IsNullOrEmpty(val)
                ? $"{Name}={currentOptions.Quote}{val}{currentOptions.Quote}"
                : "");
        }
Esempio n. 13
0
        private void AddNewRow()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
                DataRow   drCurrentRow   = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        TextBox TextBoxName         = (TextBox)AttributeOptions.Rows[rowIndex].Cells[2].FindControl("txtName");
                        TextBox priorityTextBoxName = (TextBox)AttributeOptions.Rows[rowIndex].Cells[2].FindControl("priorityNo");
                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Col1"] = priorityTextBoxName.Text;
                        dtCurrentTable.Rows[i - 1]["Col2"] = TextBoxName.Text;
                        rowIndex++;
                    }

                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable"] = dtCurrentTable;

                    AttributeOptions.DataSource = dtCurrentTable;
                    AttributeOptions.DataBind();

                    TextBox txn = (TextBox)AttributeOptions.Rows[rowIndex].Cells[2].FindControl("priorityNo");
                    txn.Focus();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            SetPreviousData();
        }
        private void FirstGridViewRow()
        {
            QueQuestion ques1 = new QueQuestion()
            {
                questionId        = 112,
                questionStatement = "This is question One"
            };

            QueQuestion ques2 = new QueQuestion()
            {
                questionId        = 2,
                questionStatement = "This is question Two"
            };


            questionList.Add(ques1);
            questionList.Add(ques2);

            Session["questionList"] = questionList;

            AttributeOptions.DataSource = questionList;
            AttributeOptions.DataBind();
        }
        public void UnEncodeApostropheInValue()
        {
            var options = new AttributeOptions {
                Quote = "\""
            };

            Assert.AreEqual("name=\"isn't it ironic\"",
                            new AttributeBase("name", "isn't it ironic", options).ToString(),
                            "apostrophe with a different quote and encodeQuotes = false");

            options = new AttributeOptions {
                EncodeQuotes = true
            };
            Assert.AreEqual("name='isn&apos;t it ironic'",
                            new AttributeBase("name", "isn't it ironic", options).ToString(),
                            "apostrophe with a different quote and encodeQuotes = true");

            options = new AttributeOptions {
                EncodeQuotes = true, Quote = "\""
            };
            Assert.AreEqual("name=\"isn&apos;t it ironic\"",
                            new AttributeBase("name", "isn't it ironic", options).ToString(),
                            "apostrophe with a different quote and encodeQuotes = true");
        }
Esempio n. 16
0
 public TagOptions(AttributeOptions attributeOptions = null)
 {
     _attribute = attributeOptions;
 }
Esempio n. 17
0
 internal static AttributeOptions UseOrCreate(AttributeOptions original) => original ?? new AttributeOptions();
Esempio n. 18
0
        public IReadOnlyList <DocsElement> Parse(IReadOnlyList <string> lines, string elementName, AttributeOptions attributeOptions)
        {
            var elements = new List <DocsElement>();

            for (var i = 0; i < lines.Count; i++)
            {
                var line  = lines[i];
                var match = Regex.Match(line, OpenPattern, RegexOptions);

                if (match.Success)
                {
                    var name = match.Groups["name"].Value;

                    if (!name.Equals(elementName))
                    {
                        continue;
                    }

                    var attributes = new Dictionary <string, string>();

                    foreach (var attribute in GetAttributes(match))
                    {
                        var key = attribute.Key;

                        if (!attributeOptions.All.Contains(key, StringComparer.OrdinalIgnoreCase))
                        {
                            throw new AppException($"invalid attribute '{key}'.");
                        }

                        if (!attributes.TryAdd(key, attribute.Value))
                        {
                            throw new AppException($"duplicate attribute '{key}'.");
                        }
                    }

                    var missingAttributes = attributeOptions.Required
                                            .Where(x => !attributes.ContainsKey(x))
                                            .ToList();
                    if (missingAttributes.Any())
                    {
                        throw new AppException($"missing attribute(s) {string.Join(", ", missingAttributes)}");
                    }

                    var element = new DocsElement
                    {
                        Attributes  = attributes,
                        Indentation = match.Groups["indentation"].Value,
                        ElementLine = i,
                        Name        = name
                    };

                    if (match.Groups["selfclosing"].Success)
                    {
                        element.ElementLines = 1;
                        elements.Add(element);
                        continue;
                    }

                    while (true)
                    {
                        if (++i == lines.Count)
                        {
                            throw new AppException($"element {element.Name}@{element.ElementLine} : closing tag not found");
                        }

                        line  = lines[i];
                        match = Regex.Match(line, ClosePattern, RegexOptions);

                        if (match.Success && match.Groups["name"].Value.Equals(element.Name, StringComparison))
                        {
                            break;
                        }
                    }

                    element.ElementLines = 1 + i - element.ElementLine;
                    elements.Add(element);
                }
            }

            return(elements);
        }
 public override bool checkIsValidOption(AttributeOption option)
 {
     return(AttributeOptions.Contains(option));
 }
Esempio n. 20
0
 /// <summary>
 /// Create a string for rendering a set of attributes
 /// </summary>
 /// <param name="attributes">An enumerable of key/value pairs, usually a dictionary. Objects will be serialized to json</param>
 /// <param name="options">optional configuration regarding quotes and encoding</param>
 /// <returns>HtmlString so you can use @Tag.Attributes(...) in your code</returns>
 public static AttributeList Attributes(IEnumerable <KeyValuePair <string, object> > attributes, AttributeOptions options = null)
 => new AttributeList(attributes, options);
Esempio n. 21
0
 public Attribute(string name, object value = null, AttributeOptions options = null)
     : base(name, value, options)
 {
 }
Esempio n. 22
0
 /// <summary>
 /// Generate an attribute for use in a tag
 /// </summary>
 /// <param name="name">attribute name</param>
 /// <param name="value">attribute value object - will be serialized to json</param>
 /// <param name="options">optional configuration regarding quotes and encoding</param>
 /// <returns>HtmlString so you can use &lt;div @Tag.Attr("myid", 5930)&gt; in your code</returns>
 public static Attribute Attr(string name, object value = null, AttributeOptions options = null)
 => new Attribute(name, value, options);
Esempio n. 23
0
 /// <summary>
 /// Generate an attribute for use in a tag
 /// </summary>
 /// <param name="name">attribute name</param>
 /// <param name="value">attribute value</param>
 /// <param name="options">optional configuration regarding quotes and encoding</param>
 /// <returns>HtmlString so you can use @Tag.Attribute(...) in your code</returns>
 public static Attribute Attribute(string name, string value, AttributeOptions options = null)
 => new Attribute(name, value, options);