Пример #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 JsonResult AddProductDetail(ProductDetaiDTO model)
        {
            ProductDetail product = new ProductDetail();

            product = AutoMapper.Mapper.Map <ProductDetail>(product);
            bool status = false;

            status = productDetailService.Add(product);
            productDetailService.Save();

            return(Json(status, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public HttpResponseMessage Post(HttpRequestMessage request, ProductDetail pd)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (ModelState.IsValid)
                {
                    request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var productDetail = _productDetailService.Add(pd);
                    _productDetailService.SaveChanges();

                    response = request.CreateResponse(HttpStatusCode.Created, productDetail);
                }
                return response;
            }));
        }
        public IActionResult Create(string productChild, [Bind("ProductDetailID,ProductID,DetailID,Definition1,Definition2")] ProductDetail productDetail)
        {
            if (ModelState.IsValid)
            {
                service.Add(productDetail);

                //When product is succesful added, it will return to the Software / Hardware controller.
                if (productChild == "Software")
                {
                    return(RedirectToAction("Edit", "Software", new { id = productDetail.ProductID }));
                }
                else
                {
                    return(RedirectToAction("Edit", "Hardware", new { id = productDetail.ProductID }));
                }
            }

            //ViewData["DetailID"] = new List<SelectListItem>(service.GetSelectListDetails());
            ViewData["DetailID"]  = new List <SelectListItem>(service.GetSelectListDetailsOfProductType(productDetail.ProductID));
            ViewData["ProductID"] = productDetail.ProductID;

            return(View(productDetail));
        }
Пример #5
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));
        }