예제 #1
0
        private async Task AddDetailChanged(Product product)
        {
            List <ProductDetail> productDetail = new List <ProductDetail>();

            foreach (var detItm in await _detailItemService.GetByProductGroupId(product))
            {
                var find = await _productDetailService.GetProductDetail(product.ProductId, detItm.DetailItemId);

                if (find != null)
                {
                    find.Value = Request.Form["detItem_" + detItm.DetailItemId.ToString()];
                    _productDetailService.Edit(find);
                }
                else
                {
                    productDetail.Add(new ProductDetail
                    {
                        DetailItemId = detItm.DetailItemId,
                        ProductId    = product.ProductId,
                        Value        = Request.Form["detItem_" + detItm.DetailItemId.ToString()]
                    });
                }
            }
            if (productDetail != null)
            {
                _productDetailService.Add(productDetail);
            }
        }
예제 #2
0
        public ActionResult Edit(Product products, string ProductGalleriesName, string tags)
        {
            if (ModelState.IsValid)
            {
                //------------Create Gallery Product --------------
                List <ProductGallery> productGalleries = new List <ProductGallery>();
                var Gallery = ProductGalleriesName.Split(',');
                for (int i = 0; i < Gallery.Length - 1; i++)
                {
                    productGalleries.Add(new ProductGallery
                    {
                        ProductId = products.ProductId,
                        ImageName = Gallery[i],
                    });
                }
                _productService.AddGalleries(productGalleries);

                //-------------------Tags---------------------
                _productService.DeleteTagsByProduct(products.ProductId);

                if (!string.IsNullOrEmpty(tags))
                {
                    List <ProductTag> productTags = new List <ProductTag>();

                    foreach (string t in tags.Split('-'))
                    {
                        productTags.Add(new ProductTag
                        {
                            ProductId = products.ProductId,
                            TagTitle  = t.ToLowerInvariant().Trim()
                        });
                    }
                    _productService.AddTags(productTags);
                }

                //-----------------Attribute----------------------
                List <Product_Attribut> productAttribut = new List <Product_Attribut>();

                foreach (var atrgrp in _attributeGrpService.GetAttrGrpProductBase(products.ProductGroupId))
                {
                    {
                        //finding product attribute if that is inserted before or not
                        var find = _productAttributeService.GetProductAttribute(products.ProductId, atrgrp.AttributGrpId);

                        if (find != null)
                        {
                            if (Request.Form["Grp_" + atrgrp.AttributGrpId.ToString()] == "none")
                            {
                                _productAttributeService.Delete(find);
                            }
                            //if user clicked one of attribute of this grp
                            else if (Request.Form["Grp_" + atrgrp.AttributGrpId.ToString()] != null)
                            {
                                find.AttributItemId = Convert.ToInt32(Request.Form["Grp_" + atrgrp.AttributGrpId.ToString()]);
                                _productAttributeService.Edit(find);
                            }
                        }
                        else
                        {
                            if (Request.Form["Grp_" + atrgrp.AttributGrpId.ToString()] != null && Request.Form["Grp_" + atrgrp.AttributGrpId.ToString()] != "none")
                            {
                                productAttribut.Add(new Product_Attribut()
                                {
                                    AttributItemId = Convert.ToInt32(Request.Form["Grp_" + atrgrp.AttributGrpId.ToString()]),
                                    ProductId      = products.ProductId,
                                });
                            }
                        }
                    }
                }
                if (productAttribut != null)
                {
                    _productAttributeService.Add(productAttribut);
                }

                //-----------------Details----------------------
                List <ProductDetail> productDetail = new List <ProductDetail>();

                foreach (var detItm in _detailItemService.GetDetItemByProduct(products))
                {
                    var find = _productDetailService.GetProductDetail(products.ProductId, detItm.DetailItemId);
                    if (find != null)
                    {
                        find.Value = Request.Form["detItem_" + detItm.DetailItemId.ToString()];
                        _productDetailService.Edit(find);
                    }
                    else
                    {
                        productDetail.Add(new ProductDetail
                        {
                            DetailItemId = detItm.DetailItemId,
                            ProductId    = products.ProductId,
                            Value        = Request.Form["detItem_" + detItm.DetailItemId.ToString()]
                        });
                    }
                }
                if (productDetail != null)
                {
                    _productDetailService.Add(productDetail);
                }

                _productService.Edit(products);
                ViewBag.tag = tags;
                return(RedirectToAction("/edit/" + products.ProductId));
            }
            ViewBag.ProductGroupId = new SelectList(_productGroupService.ProductGroups(), "ProductGroupId", "GroupTitle", products.ProductGroupId);
            return(View(products));
        }