Ejemplo n.º 1
0
        public ActionResult EditProduct(string name, string[] sizeList, string[] colorList, string description,
                                        int categoryID, int supplierID, decimal price, int ID)
        {
            StringBuilder size  = new StringBuilder();
            StringBuilder color = new StringBuilder();

            for (int i = 0; i < sizeList.Length; i++)
            {
                size.Append(sizeList[i]);
                if (i < sizeList.Length - 1)
                {
                    size.Append(",");
                }
            }

            for (int i = 0; i < colorList.Length; i++)
            {
                color.Append(colorList[i]);
                if (i < colorList.Length - 1)
                {
                    color.Append(",");
                }
            }

            List <ProductImageViewModel> listProductImage = new List <ProductImageViewModel>();
            ProductImageViewModel        productImage     = new ProductImageViewModel();
            var orderCount = 0;

            byte[] avatarImage = null;
            if (Request.Files.Count > 0)
            {
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file            = Request.Files[i];
                    int fileSizeInBytes = file.ContentLength;

                    using (var br = new BinaryReader(file.InputStream))
                    {
                        avatarImage = br.ReadBytes(fileSizeInBytes);
                    }
                    string picUrl = null;
                    if (avatarImage != null)
                    {
                        picUrl = SaveImageToServer(avatarImage);
                        productImage.PicUrl       = picUrl;
                        productImage.DisplayOrder = ++orderCount;
                        listProductImage.Add(productImage);
                    }
                }
            }

            ProductApi productApi = new ProductApi();
            var        product    = productApi.GetActive().Where(q => q.ID == ID).FirstOrDefault();

            product.Name          = name;
            product.Size          = size.ToString();
            product.Color         = color.ToString();
            product.Description   = description;
            product.CategoryID    = categoryID;
            product.Supplier      = null;
            product.SupplierId    = supplierID;
            product.Price         = price;
            product.ProductImages = listProductImage;
            productApi.EditProduct(product);
            return(Json(new { success = true, message = "Successfully added!" }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public void EditProduct(int productId, string name, string description, decimal price, int categoryId)
        {
            IProductApi api = new ProductApi();

            api.EditProduct(productId, name, description, price, categoryId);
        }