コード例 #1
0
ファイル: EditAccount.cs プロジェクト: vsrathore2/SES-8.0
        /// <summary>
        /// The process field. </summary>
        /// <param name="fieldName"> The field name. </param>
        /// <param name="fieldValue"> The field value. </param>
        /// <returns> returns processed field </returns>
        private NameValueCollection ProcessField(string fieldName, string fieldValue)
        {
            NameValueCollection field = new NameValueCollection();

            switch (fieldName)
            {
            case "Country":
                fieldValue = (!string.IsNullOrEmpty(fieldValue)) ? BusinessCatalogUtil.GetOptionFromName(fieldValue, BusinessCatalogUtil.COUNTRIES, "Code") : string.Empty;
                break;
            }

            field.Add(fieldName, fieldValue);
            return(field);
        }
コード例 #2
0
        /// <summary> Fill name value collaction by form data </summary>
        /// <param name="fieldName"> name of field</param>
        /// <param name="fieldValue"> form fields</param>
        /// <returns> returns collection of form data</returns>
        private NameValueCollection FillOrderInfo(string fieldName, string fieldValue)
        {
            NameValueCollection orderInfo = new NameValueCollection();

            switch (fieldName)
            {
            case "Country":
                fieldValue = BusinessCatalogUtil.GetOptionFromName(fieldValue, BusinessCatalogUtil.COUNTRIES, "Code");
                break;

            case "ShippingCountry":
                fieldValue = (!string.IsNullOrEmpty(fieldValue)) ? BusinessCatalogUtil.GetOptionFromName(fieldValue, BusinessCatalogUtil.COUNTRIES, "Code") : string.Empty;
                break;
            }

            orderInfo.Add(fieldName, fieldValue);
            return(orderInfo);
        }
コード例 #3
0
        /// <summary>
        /// Gets the property value from the object by the selected fieldName
        /// </summary>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="obj">The object.</param>
        /// <returns>The property value from the object by the selected fieldName</returns>
        private static string GetPropertyValue(string fieldName, object obj)
        {
            if (!string.IsNullOrEmpty(fieldName))
            {
                if (obj is Order)
                {
                    IMappingRule <Order> rule = Context.Entity.Resolve <IMappingRule <Order> >("OrderMappingRule");
                    rule.MappingObject = (Order)obj;
                    obj = rule;
                }

                // If obj is of type Item, then retrieve fieldname.
                if (obj is Item)
                {
                    var item = (Item)obj;
                    return(BusinessCatalogUtil.GetTitleFromReferencedItemOrValue(item[fieldName]));
                }

                EntityHelper entityHelper = Context.Entity.Resolve <EntityHelper>();
                IDictionary <string, object> fieldsCollection = entityHelper.GetPropertiesValues(obj);

                if (fieldsCollection.Count > 0)
                {
                    string value = fieldsCollection.FirstOrDefault(p => p.Key.EndsWith(fieldName)).Value as string;
                    if (DateUtil.IsIsoDate(value))
                    {
                        DateTime date = DateUtil.IsoDateToDateTime(value);
                        return(DateUtil.FormatShortDateTime(date, Sitecore.Context.Culture));
                    }

                    if (!string.IsNullOrEmpty(value) && ID.IsID(value))
                    {
                        Item valueItem = Sitecore.Context.Database.GetItem(value) ?? Sitecore.Context.ContentDatabase.GetItem(value);
                        if (valueItem != null)
                        {
                            value = valueItem.Name;
                        }
                    }

                    return(value);
                }

                // Else retrieve from Property
                if (obj != null)
                {
                    PropertyInfo[] propertyInfos = obj.GetType().GetProperties();
                    foreach (PropertyInfo info in propertyInfos)
                    {
                        if (info.Name.Equals(fieldName))
                        {
                            object o     = info.GetValue(obj, null);
                            string value = o + string.Empty;

                            return(BusinessCatalogUtil.GetTitleFromReferencedItemOrValue(value));
                        }
                    }
                }
            }

            return(string.Empty);
        }