Example #1
0
        private ItemProductModel SetModel(String model)
        {
            JavaScriptSerializer objJavascript = new JavaScriptSerializer();

            Char[] commaDelimiter = new char[] { ',' };
            Char[] colonDelimiter = new char[] { ':' };
            if (SessionData.item != null)
            {
                ItemProductModel productModel = new ItemProductModel();

                Array assosiations = (Array)objJavascript.DeserializeObject(model);
                productModel.ItemsProduct = new List <Models.ItemProduct>();
                foreach (String assosiation in assosiations)
                {
                    Models.ItemProduct itemProduct = new Models.ItemProduct();
                    itemProduct.ItemId = SessionData.item.id;
                    Array values = assosiation.Split(commaDelimiter, StringSplitOptions.RemoveEmptyEntries);

                    itemProduct.ItemProductAssociation = new List <ItemProductAssociation>();
                    foreach (String value in values)
                    {
                        ItemProductAssociation itemProductAssociation = new ItemProductAssociation();

                        Array vars = value.Split(colonDelimiter, StringSplitOptions.RemoveEmptyEntries);

                        itemProduct.id   = Int32.Parse(vars.GetValue(0).ToString());
                        itemProduct.Type = EnumHelper <CommonUnit.ProductType> .Parse(vars.GetValue(2).ToString());

                        itemProductAssociation.ItemProductId = Int32.Parse(vars.GetValue(0).ToString());
                        itemProductAssociation.ItemId        = Int32.Parse(vars.GetValue(1).ToString());

                        itemProduct.ItemProductAssociation.Add(itemProductAssociation);
                    }
                    productModel.ItemsProduct.Add(itemProduct);
                }
                return(productModel);
            }
            return(null);
        }
        private ItemProductModel SetModel(String model) {
            JavaScriptSerializer objJavascript = new JavaScriptSerializer();
            Char[] commaDelimiter = new char[] { ',' };
            Char[] colonDelimiter = new char[] { ':' };
            if (SessionData.item != null) {
                ItemProductModel productModel = new ItemProductModel();

                Array assosiations = (Array)objJavascript.DeserializeObject(model);
                productModel.ItemsProduct = new List<Models.ItemProduct>();
                foreach (String assosiation in assosiations) {
                    Models.ItemProduct itemProduct = new Models.ItemProduct();
                    itemProduct.ItemId = SessionData.item.id;
                    Array values = assosiation.Split(commaDelimiter, StringSplitOptions.RemoveEmptyEntries);

                    itemProduct.ItemProductAssociation = new List<ItemProductAssociation>();
                    foreach (String value in values) {
                        ItemProductAssociation itemProductAssociation = new ItemProductAssociation();

                        Array vars = value.Split(colonDelimiter, StringSplitOptions.RemoveEmptyEntries);

                        itemProduct.id = Int32.Parse(vars.GetValue(0).ToString());
                        itemProduct.Type = EnumHelper<Common.ProductType>.Parse(vars.GetValue(2).ToString());
                        itemProductAssociation.ItemProductId = Int32.Parse(vars.GetValue(0).ToString());
                        itemProductAssociation.ItemId = Int32.Parse(vars.GetValue(1).ToString());

                        itemProduct.ItemProductAssociation.Add(itemProductAssociation);
                    }
                    productModel.ItemsProduct.Add(itemProduct);
                }
                return productModel;
            }
            return null;
        }