コード例 #1
0
ファイル: ProductController.cs プロジェクト: vergilooos/Hasma
        public async Task <IHttpActionResult> PostUpdateProduct()
        {
            try
            {
                if (!Request.Content.IsMimeMultipartContent())
                {
                    return(Json(JsonConvert.SerializeObject("Exception dade: UnsupportedMediaType")));
                }

                var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

                ProductMorphy mProductMorphy = new ProductMorphy();

                foreach (var itemContent in filesReadToProvider.Contents)
                {
                    if (itemContent.Headers.ContentDisposition.Name == "Object" || itemContent.Headers.ContentDisposition.Name == "\"Object\"")
                    {
                        var jsonString = await itemContent.ReadAsStringAsync();

                        var serializer = new JavaScriptSerializer();
                        mProductMorphy = serializer.Deserialize <ProductMorphy>(jsonString);

                        COM.Product mProduct = new COM.Product()
                        {
                            PID         = mProductMorphy.PID,
                            Brand       = mProductMorphy.Brand,
                            CatID       = mProductMorphy.CatID,
                            Description = mProductMorphy.Description,
                            Name        = mProductMorphy.Name,
                            Price       = mProductMorphy.Price,
                            PriceOff    = mProductMorphy.PriceOff,
                            StockCount  = mProductMorphy.StockCount,
                            SubCatID    = mProductMorphy.SubCatID,
                        };

                        mProduct.specification = JsonConvert.SerializeObject(mProductMorphy.specification);

                        bool ResAdd = BLL.Product.UpdateProduct(mProduct);
                        if (!ResAdd)
                        {
                            return(Json(JsonConvert.SerializeObject("natoooneste to DB save beshe ")));
                        }
                        else
                        {
                            return(Json(JsonConvert.SerializeObject(ResAdd.ToString())));
                        }
                    }
                }
                return(Json(JsonConvert.SerializeObject("az halghe biroon oomad toosh hich chizi naboode")));
            }
            catch (Exception ee)
            {
                Log.DoLog(COM.Action.PostUpdateProduct, "UpdatePro", -100, ee.Message);
                return(Json(JsonConvert.SerializeObject("Exception dade: " + ee.Message)));
            }
        }
コード例 #2
0
ファイル: ProductController.cs プロジェクト: vergilooos/Hasma
        public int AddProduct([FromBody] ProductMorphy NewProduct)
        {
            COM.Product product = new COM.Product()
            {
                Brand       = NewProduct.Brand,
                CatID       = NewProduct.CatID,
                Description = NewProduct.Description,
                Name        = NewProduct.Name,
                Price       = NewProduct.Price,
                PriceOff    = NewProduct.PriceOff,
                StockCount  = NewProduct.StockCount,
                SubCatID    = NewProduct.SubCatID,
            };

            product.specification = JsonConvert.SerializeObject(NewProduct.specification);

            return(BLL.Product.AddProduct(product));
        }
コード例 #3
0
ファイル: ProductController.cs プロジェクト: vergilooos/Hasma
        public ProductMorphy GetProductByPID(int PID)
        {
            var mProduct = BLL.Product.GetProductByID(PID);

            ProductMorphy productMorphy = new ProductMorphy()
            {
                Brand         = mProduct.Brand,
                PID           = mProduct.PID,
                specification = JsonConvert.DeserializeObject <List <Spec> >(mProduct.specification),
                SubCatID      = mProduct.SubCatID,
                StockCount    = mProduct.StockCount,
                CatID         = mProduct.CatID,
                Description   = mProduct.Description,
                Name          = mProduct.Name,
                Price         = mProduct.Price,
                PriceOff      = mProduct.PriceOff
            };

            return(productMorphy);
        }