当前位置: 首页>>代码示例>>C#>>正文


C# FormCollection.ProcessPostCheckboxesData方法代码示例

本文整理汇总了C#中System.Web.Mvc.FormCollection.ProcessPostCheckboxesData方法的典型用法代码示例。如果您正苦于以下问题:C# FormCollection.ProcessPostCheckboxesData方法的具体用法?C# FormCollection.ProcessPostCheckboxesData怎么用?C# FormCollection.ProcessPostCheckboxesData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.FormCollection的用法示例。


在下文中一共展示了FormCollection.ProcessPostCheckboxesData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Prices

        public ActionResult Prices(FormCollection form)
        {
            using (var context = new ShopContainer())
            {
                var products = context.Product.Include("Brand").Include("Category").ToList();

                PostCheckboxesData cbDataNew = form.ProcessPostCheckboxesData("new");
                PostCheckboxesData cbDataSpec = form.ProcessPostCheckboxesData("special");
                PostCheckboxesData cbDataPublish = form.ProcessPostCheckboxesData("publish");
                PostData oldPriceData = form.ProcessPostData("oldprice");
                PostData priceData = form.ProcessPostData("price");

                foreach (var kvp in cbDataNew)
                {
                    var productId = kvp.Key;
                    bool productValue = kvp.Value;

                    products.First(p => p.Id == productId).IsNew = productValue;
                }

                foreach (var kvp in cbDataSpec)
                {
                    var productId = kvp.Key;
                    bool productValue = kvp.Value;

                    products.First(p => p.Id == productId).IsSpecialOffer = productValue;
                }

                foreach (var kvp in cbDataPublish)
                {
                    var productId = kvp.Key;
                    bool productValue = kvp.Value;

                    products.First(p => p.Id == productId).Published = productValue;
                }

                foreach (var kvp in oldPriceData)
                {
                    int productId = Convert.ToInt32(kvp.Key);
                    foreach (var value in kvp.Value)
                    {
                        var productValue = Convert.ToDecimal(value.Value);
                        products.First(p => p.Id == productId).OldPrice = productValue;
                    }
                }

                foreach (var kvp in priceData)
                {
                    int productId = Convert.ToInt32(kvp.Key);
                    foreach (var value in kvp.Value)
                    {
                        var productValue = Convert.ToDecimal(value.Value);
                        products.First(p => p.Id == productId).Price = productValue;
                    }
                }

                context.SaveChanges();
            }
            return RedirectToAction("Prices");
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:60,代码来源:ProductController.cs

示例2: Create

        public ActionResult Create(FormCollection form, HttpPostedFileBase uploadFile)
        {
            using (var context = new ModelContainer())
            {
                int albumId = Convert.ToInt32(form["AlbumId"]);
                var album = context.Album.First(a => a.Id == albumId);

                PostCheckboxesData cbDataCategories = form.ProcessPostCheckboxesData("category");
                PostCheckboxesData cbDataElements = form.ProcessPostCheckboxesData("element");



                var product = new Product();
                TryUpdateModel(product,
                               new[]
                                   {
                                       "Title",
                                       "SortOrder"
                                   });

                string fileName = IOHelper.GetUniqueFileName("~/Content/Images", uploadFile.FileName);
                string filePath = Server.MapPath("~/Content/Images");
                filePath = Path.Combine(filePath, fileName);
                uploadFile.SaveAs(filePath);

                product.ImageSource = fileName;

                foreach (var kvp in cbDataCategories)
                {
                    var categoryId = kvp.Key;
                    bool productValue = kvp.Value;
                    if (productValue)
                    {
                        var category = context.Category.First(c => c.Id == categoryId);
                        product.Categories.Add(category);
                    }
                }

                foreach (var kvp in cbDataElements)
                {
                    var elementId = kvp.Key;
                    var elemrntValue = kvp.Value;
                    if (elemrntValue)
                    {
                        var element = context.Element.First(e => e.Id == elementId);
                        product.Elements.Add(element);
                    }
                }


                album.Products.Add(product);

                context.SaveChanges();
                return RedirectToAction("Index", "Albums", new { Area = "", id = album.Name });
            }
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:56,代码来源:ProductController.cs

示例3: Create

        public ActionResult Create(int id, FormCollection form, string filter)
        {
            try
            {
                using (var context = new CatalogueContainer())
                {
                    var category = context.Category.First(c => c.Id == id);
                    var brand = new Brand { Category = category };
                    PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr");
                    foreach (var kvp in cbData)
                    {
                        var attrId = kvp.Key;
                        bool attrValue = kvp.Value;
                        if (attrValue)
                        {
                            var attribute = context.CategoryAttribute.First(c => c.Id == attrId);
                            brand.CategoryAttributes.Add(attribute);
                        }
                    }

                    TryUpdateModel(brand, new[] { "Title", "Name", "SortOrder", "Href", "DescriptionTitle" });
                    brand.Name = brand.Name.ToLower().Replace(" ", "");
                    brand.Description = HttpUtility.HtmlDecode(form["Description"]);
                    context.AddToBrand(brand);
                    context.SaveChanges();

                    return RedirectToAction("Index", "Catalogue", new { area = "", category = category.Name, filter=filter });
                }
            }
            catch
            {
                return View();
            }
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:34,代码来源:BrandController.cs

示例4: Create

        public ActionResult Create(FormCollection form)
        {
            try
            {
                using (var context = new CatalogueContainer())
                {
                    var category = new Category();


                    var attributes = context.CategoryAttribute.ToList();
                    PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr");
                    foreach (var kvp in postData)
                    {
                        var attribute = attributes.First(a => a.Id == kvp.Key);
                        if (kvp.Value)
                        {
                            if (!category.CategoryAttributes.Contains(attribute))
                                category.CategoryAttributes.Add(attribute);
                        }
                        else
                        {
                            if (category.CategoryAttributes.Contains(attribute))
                                category.CategoryAttributes.Remove(attribute);
                        }
                    }

                    TryUpdateModel(category, new[] { 
                    "Name", 
                    "Title", 
                    "SortOrder",
                    "SeoDescription",
                    "SeoKeywords",
                    "DescriptionTitle"
                    });
                    category.Description = HttpUtility.HtmlDecode(form["Description"]);
                    category.Name = category.Name.ToLower().Replace(" ", "");

                    context.AddToCategory(category);
                    context.SaveChanges();
                    return RedirectToAction("Index", "Category", new { area = "Admin" });
                }


            }
            catch
            {
                return View();
            }
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:49,代码来源:CategoryController.cs

示例5: Create

        public ActionResult Create(FormCollection form, int categoryId, HttpPostedFileBase fileUpload)
        {
            using (var context = new StructureContainer())
            {
                Product product = new Product();
                Category category = context.Category.Include("Parent").First(c => c.Id == categoryId);
                product.Category = category;

                var attributes = context.ProductAttribute.ToList();
                PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "categoryId");

                foreach (var kvp in postData)
                {
                    var attribute = attributes.First(a => a.Id == kvp.Key);
                    if (kvp.Value)
                    {
                        if (!product.ProductAttributes.Contains(attribute))
                            product.ProductAttributes.Add(attribute);
                    }
                    else
                    {
                        if (product.ProductAttributes.Contains(attribute))
                            product.ProductAttributes.Remove(attribute);
                    }
                }


                TryUpdateModel(product, new[] { "Title", "TitleEng", "Description", "DescriptionEng", "ShowOnMainPage","Discount","DiscountText" });

                if (fileUpload != null)
                {
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName);
                    string filePath = Server.MapPath("~/Content/Images");
                    filePath = Path.Combine(filePath, fileName);
                    GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload);

                    product.ImageSource = fileName;
                }

                context.AddToProduct(product);

                context.SaveChanges();

                return category.Parent != null
                    ? RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent.Name, subCategory = category.Name })
                    : RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Name });
            }
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:48,代码来源:ProductController.cs

示例6: Add

        public ActionResult Add(FormCollection form)
        {
            using (var context = new StructureContainer())
            {
                var category = new Category();

                if (!string.IsNullOrEmpty(form["parentId"]))
                {
                    int parentId = Convert.ToInt32(form["parentId"]);
                    var parent = context.Category.First(c => c.Id == parentId);
                    category.Parent = parent;
                }


                var attributes = context.ProductAttribute.ToList();
                PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "parentId");
                foreach (var kvp in postData)
                {
                    var attribute = attributes.First(a => a.Id == kvp.Key);
                    if (kvp.Value)
                    {
                        if (!category.ProductAttributes.Contains(attribute))
                            category.ProductAttributes.Add(attribute);
                    }
                    else
                    {
                        if (category.ProductAttributes.Contains(attribute))
                            category.ProductAttributes.Remove(attribute);
                    }
                }


                TryUpdateModel(category, new[] { "Name", "Title", "TitleEng", "SortOrder" });
                category.Text = HttpUtility.HtmlDecode(form["Text"]);
                category.TextEng = HttpUtility.HtmlDecode(form["TextEng"]);
                context.AddToCategory(category);
                context.SaveChanges();

                return RedirectToAction("Index", "Catalogue",
                                        new
                                            {
                                                Area = "",
                                                category = category.Parent != null ? category.Parent.Name : category.Name,
                                                subCategory = category.Parent != null ? category.Name : null
                                            });
            }
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:47,代码来源:CategoryController.cs

示例7: Create

        public ActionResult Create(FormCollection form)
        {
            using (var context = new SiteContainer())
            {
                var category = new Category();


                var attributes = context.ProductAttribute.ToList();
                PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr");
                foreach (var kvp in postData)
                {
                    var attribute = attributes.First(a => a.Id == kvp.Key);
                    if (kvp.Value)
                    {
                        if (!category.ProductAttributes.Contains(attribute))
                            category.ProductAttributes.Add(attribute);
                    }
                    else
                    {
                        if (category.ProductAttributes.Contains(attribute))
                            category.ProductAttributes.Remove(attribute);
                    }
                }

                TryUpdateModel(category, new[] { 
                    "Name", 
                    "Title", 
                    "SortOrder", 
                    "SeoDescription", 
                    "SeoKeywords" });

                context.AddToCategory(category);
                context.SaveChanges();

                return RedirectToAction("Index", "Catalogue", new { Area = "", id = category.Name });
            }
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:37,代码来源:CategoryController.cs

示例8: Attributes

        public ActionResult Attributes(int categoryId, FormCollection form)
        {
            try
            {
                using (var context = new ShopContainer())
                {
                    var category = context.Category.Include("ProductAttributes").First(c => c.Id == categoryId);
                    var attributes = context.ProductAttribute.ToList();

                    PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "categoryId");

                    foreach (var kvp in postData)
                    {
                        var attribute = attributes.First(a => a.Id == kvp.Key);
                        if (kvp.Value)
                        {
                            if (!category.ProductAttributes.Contains(attribute))
                                category.ProductAttributes.Add(attribute);
                        }
                        else
                        {
                            if (category.ProductAttributes.Contains(attribute))
                                category.ProductAttributes.Remove(attribute);
                        }
                    }

                    context.SaveChanges();

                    return RedirectToAction("Index");
                }
            }
            catch
            {
                return View();
            }
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:36,代码来源:CategoryController.cs

示例9: Attributes

        public ActionResult Attributes(int productId, FormCollection form, string page)
        {
            _repository.LangId = CurrentLangId;
            var product = _repository.GetProduct(productId);
            PostCheckboxesData attrData = form.ProcessPostCheckboxesData("attr", "productId");
            PostData staticAttrData = form.ProcessPostData("tb", "productId");

            product.ProductAttributeValues.Clear();
            string searchCriteriaAttributes = "";

            foreach (var kvp in attrData)
            {
                var attributeValueId = kvp.Key;
                bool attributeValue = kvp.Value;

                if (attributeValue)
                {
                    var productAttributeValue = _repository.GetProductAttributeValue(attributeValueId);
                    searchCriteriaAttributes += productAttributeValue.ProductAttributeId + "-" + attributeValueId + ";";
                    product.ProductAttributeValues.Add(productAttributeValue);
                }
            }

            foreach (var kvp in staticAttrData)
            {
                int attributeId = Convert.ToInt32(kvp.Key);
                foreach (var value in kvp.Value)
                {
                    string attributeValue = value.Value;

                    var productAttribute = _repository.GetProductAttribute(attributeId);

                    //productAttribute.ProductAttributeStaticValues.Clear();

                    ProductAttributeStaticValue productAttributeValue = null;
                    productAttributeValue = _repository.GetProductAttributeStaticValue(productAttribute.Id, product.Id);


                    if (string.IsNullOrEmpty(attributeValue))
                    {
                        if (productAttributeValue != null)
                            _repository.DeleteProductAttributeStaticValue(productAttributeValue.Id);
                    }
                    else
                    {
                        if (productAttributeValue == null)
                        {
                            productAttributeValue = new ProductAttributeStaticValue
                            {
                                Title = attributeValue,
                                ProductAttribute = productAttribute,
                                ProductId = product.Id
                            };
                            _repository.AddProductAttributeStaticValue(productAttributeValue);
                        }
                        else
                        {
                            productAttributeValue.Title = attributeValue;
                            _repository.SaveProductAttributeStaticValue(productAttributeValue);
                        }
                    }
                }
            }

            product.SearchCriteriaAttributes = searchCriteriaAttributes;

            _repository.SaveProduct(product);

            return !string.IsNullOrEmpty(page) ? RedirectToAction("Index", new { page = page }) : RedirectToAction("Index");
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:70,代码来源:ProductController.cs

示例10: CreateMany

        public ActionResult CreateMany(FormCollection form, int categoryId, IList<HttpPostedFileBase> fileUpload, IList<string> titleRU, IList<string> titleEN, IList<string> descriptionRU, IList<string> descriptionEN)
        {
            using (var context = new StructureContainer())
            {
                
                Category category = context.Category.Include("Parent").First(c => c.Id == categoryId);
                var attributes = context.ProductAttribute.ToList();
                PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "categoryId");

                for (int i = 0; i < 10; i++)
                {
                    if (fileUpload[i] != null)
                    {

                        Product product = new Product {Category = category};

                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload[i].FileName);
                        string filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload[i]);
                        product.ImageSource = fileName;




                        foreach (var kvp in postData)
                        {
                            var attribute = attributes.First(a => a.Id == kvp.Key);
                            if (kvp.Value)
                            {
                                if (!product.ProductAttributes.Contains(attribute))
                                    product.ProductAttributes.Add(attribute);
                            }
                            else
                            {
                                if (product.ProductAttributes.Contains(attribute))
                                    product.ProductAttributes.Remove(attribute);
                            }
                        }


                        product.Title = titleRU[i];
                        product.TitleEng = titleEN[i];
                        product.Description = descriptionRU[i];
                        product.DescriptionEng = descriptionEN[i];

                        context.AddToProduct(product);

                    }
                }

                context.SaveChanges();

                return category.Parent != null
                    ? RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent.Name, subCategory = category.Name })
                    : RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Name });
            }
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:58,代码来源:ProductController.cs

示例11: Create

        public ActionResult Create(Product model, FormCollection form, HttpPostedFileBase photo)
        {
            try
            {
                var authors = _context.Authors.ToList();
                var author = authors.First(a => a.Id == model.AuthorId);
                ViewBag.AuthorId = author.Id;
                ViewBag.Tags = _context.Tags.ToList();
                ViewBag.Authors = authors;

                var product = new Product
                {
                    Title = model.Title,
                    TitleEn = model.TitleEn,
                    TitleUa = model.TitleUa,
                    Price = model.Price,
                    SortOrder = model.SortOrder,
                    Author = author
                };

                if (photo != null)
                {
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images/product", photo.FileName);
                    string filePath = Server.MapPath("~/Content/Images/product");
                    string filePathThumb = Server.MapPath("~/Content/Images/product/thumb");
                    string filePathOrigSize = Server.MapPath("~/Content/Images/product/orig");
                    filePath = Path.Combine(filePath, fileName);
                    filePathThumb = Path.Combine(filePathThumb, fileName);
                    filePathOrigSize = Path.Combine(filePathOrigSize, fileName);
                    GraphicsHelper.SaveOriginalImage(filePathOrigSize, fileName, photo,2000);
                    GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, photo, 1440, 960, ScaleMode.Crop);
                    GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePathThumb, fileName, photo, 324, 324, ScaleMode.Crop);
                    product.ImageSrc = fileName;
                }

                PostCheckboxesData attrData = form.ProcessPostCheckboxesData("tag");

                foreach (var kvp in attrData)
                {
                    var tagId = kvp.Key;
                    bool tagValue = kvp.Value;

                    //author.Tags.Clear();

                    if (tagValue)
                    {
                        var tag = _context.Tags.First(t => t.Id == tagId);
                        product.Tags.Add(tag);
                    }
                }

                _context.Products.Add(product);
                _context.SaveChanges();


                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                TempData["errorMessage"] = ex.GetEntityValidationException();

                if (string.IsNullOrEmpty((string)TempData["errorMessage"]))
                {
                    TempData["errorMessage"] = ex.Message;
                }
                return View(model);
            }
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:68,代码来源:ProductController.cs

示例12: Edit

        public ActionResult Edit(Category model, FormCollection form)
        {
            using (var context = new StructureContainer())
            {
                var category = context.Category.Include("Parent").First(c => c.Id == model.Id);

                TryUpdateModel(category, new[]
                                            {
                                                "Name",
                                                "Title",
                                                "TitleEng",
                                                "SortOrder"
                                            });
                category.Text = HttpUtility.HtmlDecode(form["Text"]);
                category.TextEng = HttpUtility.HtmlDecode(form["TextEng"]);

                var attributes = context.ProductAttribute.ToList();
                PostCheckboxesData postData = form.ProcessPostCheckboxesData("attr", "parentId");
                foreach (var kvp in postData)
                {
                    var attribute = attributes.First(a => a.Id == kvp.Key);
                    if (kvp.Value)
                    {
                        if (!category.ProductAttributes.Contains(attribute))
                            category.ProductAttributes.Add(attribute);
                    }
                    else
                    {
                        if (category.ProductAttributes.Contains(attribute))
                            category.ProductAttributes.Remove(attribute);
                    }
                }

                context.SaveChanges();

                return RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent != null ? category.Parent.Name : category.Name });
            }
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:38,代码来源:CategoryController.cs

示例13: Create

        public ActionResult Create(Event model, IEnumerable<HttpPostedFileBase> files, IEnumerable<HttpPostedFileBase> filesAnother, FormCollection form)
        {
            try
            {
                var ev = new Event
                {
                    Title = model.Title,
                    TitleEn = model.TitleEn,
                    TitleUa = model.TitleUa,
                    TitleDescription = model.TitleDescription,
                    TitleDescriptionEn = model.TitleDescriptionEn,
                    TitleDescriptionUa = model.TitleDescriptionUa,
                    Date = model.Date,
                    HighlightedText = model.HighlightedText,
                    HighlightedTextEn = model.HighlightedTextEn,
                    HighlightedTextUa = model.HighlightedTextUa,
                    LocationAddress  = model.LocationAddress,
                    LocationAddressEn  = model.LocationAddressEn,
                    LocationAddressUa  = model.LocationAddressUa,
                    LocationAddressMapUrl = model.LocationAddressMapUrl,
                    LocationTitle = model.LocationTitle,
                    LocationTitleEn = model.LocationTitleEn,
                    LocationTitleUa = model.LocationTitleUa,
                    TicketOrderType = model.TicketOrderType,
                    PreviewContentType = model.PreviewContentType,
                    ArtGroup = model.ArtGroup,
                    ArtGroupEn = model.ArtGroupEn,
                    ArtGroupUa = model.ArtGroupUa,
                    Action = model.Action,
                    ActionEn = model.ActionEn,
                    ActionUa = model.ActionUa,
                    Location = model.Location,
                    LocationEn = model.LocationEn,
                    LocationUa = model.LocationUa,
                    Duration = model.Duration,
                    Description = model.Description,
                    DescriptionEn = model.DescriptionEn,
                    DescriptionUa = model.DescriptionUa,
                    IntervalQuantity = model.IntervalQuantity,
                    PreviewContentVideoSrc = model.PreviewContentVideoSrc,
                    Price = model.Price
                };

                ev.IsHighlighted = !string.IsNullOrEmpty(ev.HighlightedText);

                foreach (var file in files)
                {
                    if (file == null) continue;
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);

                    // h: 283
                    // w: 400
                    GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, file, 400, 283, ScaleMode.Crop);

                    var ci = new ContentImage
                    {
                        ImageSrc = fileName
                    };

                    ev.ContentImages.Add(ci);
                }

                foreach (var file in filesAnother)
                {
                    if (file == null) continue;
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);
                    //GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                    GraphicsHelper.SaveOriginalImageWithDefinedDimentions(filePath, fileName, file, 788, 500, ScaleMode.Crop);

                    var ci = new PreviewContentImage
                    {
                        ImageSrc = fileName
                    };

                    ev.PreviewContentImages.Add(ci);
                }

                PostCheckboxesData attrData = form.ProcessPostCheckboxesData("author");

                foreach (var kvp in attrData)
                {
                    var tagId = kvp.Key;
                    bool tagValue = kvp.Value;

                    //author.Tags.Clear();

                    if (tagValue)
                    {
                        var author = _context.Authors.First(t => t.Id == tagId);
                        ev.Authors.Add(author);
                    }
                }


//.........这里部分代码省略.........
开发者ID:fathurxzz,项目名称:aleqx,代码行数:101,代码来源:EventController.cs

示例14: Tags

        public ActionResult Tags(int productId, FormCollection form)
        {
            using (var context = new ShopContainer())
            {
                var product = context.Product.First(p => p.Id == productId);
                PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr", "productId");
                product.Tags.Clear();
                foreach (KeyValuePair<int, bool> kvp in cbData)
                {
                    if (kvp.Value)
                    {
                        var tagId = kvp.Key;
                        var tag = context.Tag.First(t => t.Id == tagId);
                        product.Tags.Add(tag);
                    }
                }
                context.SaveChanges();

                return RedirectToAction("Index");
            }
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:21,代码来源:ProductController.cs

示例15: Attributes

        public ActionResult Attributes(int productId, FormCollection form)
        {
            using (var context = new ShopContainer())
            {
                var product = context.Product.Include("ProductAttributeValues").First(p => p.Id == productId);

                PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr", "productId");
                PostData staticAttrData = form.ProcessPostData("tb", "productId");

                product.ProductAttributeValues.Clear();

                foreach (var kvp in cbData)
                {
                    var attributeValueId = kvp.Key;
                    bool attributeValue = kvp.Value;

                    if (attributeValue)
                    {
                        var productAttributeValue = context.ProductAttributeValues.First(pv => pv.Id == attributeValueId);
                        product.ProductAttributeValues.Add(productAttributeValue);
                    }
                }


                foreach (var kvp in staticAttrData)
                {
                    int attributeId = Convert.ToInt32(kvp.Key);
                    foreach (var value in kvp.Value)
                    {
                        string attributeValue = value.Value;

                        var productAttribute = context.ProductAttribute.Include("ProductAttributeStaticValues").First(pa => pa.Id == attributeId);

                        //productAttribute.ProductAttributeStaticValues.Clear();

                        ProductAttributeStaticValues productAttributeValue = null;
                        productAttributeValue = context.ProductAttributeStaticValues.FirstOrDefault(
                                pav => pav.ProductAttribute.Id == productAttribute.Id && pav.Product.Id == product.Id);


                        if (string.IsNullOrEmpty(attributeValue))
                        {
                            if (productAttributeValue != null)
                                context.DeleteObject(productAttributeValue);
                        }
                        else
                        {
                            if (productAttributeValue == null)
                            {



                                productAttributeValue = new ProductAttributeStaticValues
                                                            {
                                                                Value = attributeValue,
                                                                ProductAttribute = productAttribute
                                                            };
                                product.ProductAttributeStaticValues.Add(productAttributeValue);

                            }
                            else
                            {
                                productAttributeValue.Value = attributeValue;
                            }
                        }
                        //productAttribute.ProductAttributeValues.Add(productAttributeValue);


                    }
                }

                context.SaveChanges();




                return RedirectToAction("Index");
            }
        }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:79,代码来源:ProductController.cs


注:本文中的System.Web.Mvc.FormCollection.ProcessPostCheckboxesData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。