Beispiel #1
0
        public ResponseDto Delete(ProductCategoryRawListDto deleteDto)
        {
            ResponseDto responseDto = new ResponseDto();

            ProductCategoryListBo deleteBo = new ProductCategoryListBo()
            {
                Id = deleteDto.Id,

                Session = Session
            };

            ResponseBo responseBo = productCategoryBusiness.Delete(deleteBo);

            responseDto = responseBo.ToResponseDto();

            return(responseDto);
        }
Beispiel #2
0
        public ActionResult Edit([Bind(Include = "ProductId,Title,Description,Text,Visit,Price,ImageName,Sort")] Product product,
                                 List <int> selectedCategory, HttpPostedFileBase imageProduct, string tags)
        {
            if (ModelState.IsValid)
            {
                // Check Categories
                if (selectedCategory == null)
                {
                    ViewBag.Category         = true;
                    ViewBag.SelectedCategory = selectedCategory;
                    ViewBag.Tags             = tags;
                    ViewBag.Categories       = _categoryBusiness.Get();
                    return(View(product));
                }
                // Image
                if (imageProduct != null && imageProduct.IsImage())
                {
                    if (product.ImageName != "user123456789.png")
                    {
                        System.IO.File.Delete(Server.MapPath("/Content/Image/Product/" + product.ImageName));
                        System.IO.File.Delete(Server.MapPath("/Content/Image/Product/Thumbnail/" + product.ImageName));
                    }
                    product.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(imageProduct.FileName);
                    imageProduct.SaveAs(Server.MapPath("/Content/Image/Product/" + product.ImageName));
                    ImageResizer img = new ImageResizer();
                    img.Resize(Server.MapPath("/Content/Image/Product/" + product.ImageName),
                               Server.MapPath("/Content/Image/Product/Thumbnail/" + product.ImageName));
                }

                _productBusiness.Update(product);
                _productBusiness.Save();

                // Category
                _productCategoryBusiness.GetByProductId(product.ProductId).ForEach(p => _productCategoryBusiness.Delete(p));
                foreach (var category in selectedCategory)
                {
                    _productCategoryBusiness.Insert(new ProductCategory()
                    {
                        CategoryId = category,
                        ProductId  = product.ProductId
                    });
                }
                _productCategoryBusiness.Save();

                // Tags
                _tagBusiness.GetByProductId(product.ProductId).ForEach(t => _tagBusiness.Delete(t.TagId));
                if (!string.IsNullOrEmpty(tags))
                {
                    string[] tagsList = tags.Split(',');
                    foreach (var tag in tagsList)
                    {
                        _tagBusiness.Insert(new Tag()
                        {
                            ProductId = product.ProductId,
                            TagName   = tag.Trim()
                        });
                    }
                }
                _tagBusiness.Save();

                return(RedirectToAction("Index"));
            }

            ViewBag.SelectedCategory = selectedCategory;
            ViewBag.Tags             = tags;
            ViewBag.Categories       = _categoryBusiness.Get();
            return(View(product));
        }