コード例 #1
0
        public static KitComposition FromForm(Customer ThisCustomer, int ProductID, int VariantID)
        {
            KitComposition composition = new KitComposition(0);

            string kitContents = CommonLogic.FormCanBeDangerousContent("KitItems");

            if (!string.IsNullOrEmpty(kitContents))
            {
                string[] selectedItems = kitContents.Split(',');

                foreach (string kitGroup in selectedItems)
                {
                    string[] groups  = kitGroup.Split('+');
                    int      groupID = int.Parse(groups[0]);
                    int      itemID  = int.Parse(groups[1]);

                    KitCartItem selectedKitItem = new KitCartItem();
                    selectedKitItem.CustomerID = ThisCustomer.CustomerID;
                    selectedKitItem.ProductID  = ProductID;
                    selectedKitItem.VariantID  = VariantID;
                    selectedKitItem.KitGroupID = groupID;
                    selectedKitItem.KitItemID  = itemID;

                    composition.Compositions.Add(selectedKitItem);
                }
            }

            // process text options
            HttpContext ctx = HttpContext.Current;

            foreach (KitCartItem item in composition.Compositions)
            {
                string id   = string.Format("KitItemTextOption_{0}_{1}", item.KitGroupID, item.KitItemID);
                string text = CommonLogic.FormCanBeDangerousContent(id);
                if (!CommonLogic.IsStringNullOrEmpty(text))
                {
                    item.TextOption = text;
                }
            }

            // process file upload
            foreach (KitCartItem item in composition.Compositions)
            {
                // NOTE:
                //  We don't use the group id for file upload
                string         id   = string.Format("KitItemFileUpload_{0}", item.KitItemID);
                HttpPostedFile file = ctx.Request.Files[id];
                if (null != file)
                {
                    item.FileName  = file.FileName;
                    item.ImageFile = file;
                }
                else
                {
                    // must be edit mode
                    id = string.Format("KitItemFile_{0}", item.KitItemID);
                    string savedFile = CommonLogic.FormCanBeDangerousContent(id);
                    if (!CommonLogic.IsStringNullOrEmpty(savedFile))
                    {
                        item.TextOption = savedFile;
                    }
                }
            }

            return(composition);
        }