// Added by Bharat to get Attribute Set from Product on 28 Feb 2018
        public JsonResult GetAttributeSet(string fields)
        {
            ProductManagementModel model = new ProductManagementModel();
            int      M_Product_ID        = Util.GetValueOfInt(fields);
            MProduct prd = new MProduct(Session["ctx"] as Ctx, M_Product_ID, null);

            return(Json(JsonConvert.SerializeObject(prd.GetM_AttributeSet_ID()), JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetProductDetails(int M_Product_ID)
        {
            Ctx ct = Session["ctx"] as Ctx;
            ProductManagementModel model = new ProductManagementModel();
            DataSet dsProd = model.GetProductDetails(M_Product_ID, ct);

            return(Json(JsonConvert.SerializeObject(dsProd), JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetProductPrices(List <int> M_Product_ID, int PriceList)
        {
            Ctx ct = Session["ctx"] as Ctx;
            ProductManagementModel model  = new ProductManagementModel();
            List <PriceInfo>       dsProd = model.GetProductPrices(M_Product_ID, PriceList, ct);

            return(Json(JsonConvert.SerializeObject(dsProd), JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetProdCats(string searchText, int pageNo, int pageSize)
        {
            Ctx ct = Session["ctx"] as Ctx;
            ProductManagementModel model = new ProductManagementModel();
            List <ProdCatInfo>     prods = model.GetProdCats(searchText, pageNo, pageSize, ct);

            return(Json(JsonConvert.SerializeObject(prods), JsonRequestBehavior.AllowGet));
        }
        public JsonResult SetRelatedProduct(int M_Product_ID, int RelatedProduct)
        {
            Ctx ct = Session["ctx"] as Ctx;
            ProductManagementModel model = new ProductManagementModel();
            string data = model.SetRelatedProduct(M_Product_ID, RelatedProduct, ct);

            return(Json(JsonConvert.SerializeObject(data), JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetProdInfo(string searchText, int SearchQuery, int proCategory, int pageNo, int pageSize, int Parent_ID)
        {
            Ctx ct = Session["ctx"] as Ctx;
            ProductManagementModel model = new ProductManagementModel();
            List <ProductInfo>     prods = model.GeProdInfo(searchText, SearchQuery, proCategory, pageNo, pageSize, ct, Parent_ID);

            return(Json(JsonConvert.SerializeObject(prods), JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetAttributeValues(int product_id)
        {
            Ctx ct = Session["ctx"] as Ctx;
            ProductManagementModel model = new ProductManagementModel();
            var res = model.GetAttributeValues(ct, product_id);

            return(Json(JsonConvert.SerializeObject(res), JsonRequestBehavior.AllowGet));
        }
        public JsonResult AttributeSetListing(int AttributeSet_ID)
        {
            Ctx ctx = Session["ctx"] as Ctx;
            ProductManagementModel obj = new ProductManagementModel();
            var value = obj.CreateTree(AttributeSet_ID, ctx);

            return(Json(JsonConvert.SerializeObject(value), JsonRequestBehavior.AllowGet));
        }
        public JsonResult DeleteAttributeValues(string attValueImagesID)
        {
            Ctx ctx = Session["ctx"] as Ctx;
            ProductManagementModel             obj = new ProductManagementModel();
            List <VA005_AttributeValueDeletes> lindatatoString1 = JsonConvert.DeserializeObject <List <VA005_AttributeValueDeletes> >(attValueImagesID);
            var image = obj.DeleteAttributeValues(ctx, lindatatoString1);

            return(Json(JsonConvert.SerializeObject(image), JsonRequestBehavior.AllowGet));
        }
        //Manish 28/9/2016

        public JsonResult SaveAttributeValueImage(string imagePath, string imageName, int productID, string attributeValue, string attimages_id)
        {
            Ctx ctx = Session["ctx"] as Ctx;

            byte[] imageByteData       = System.IO.File.ReadAllBytes(imagePath);
            ProductManagementModel obj = new ProductManagementModel();
            var image      = obj.SaveAttributeValueImage(ctx, imageByteData, imageName, true, productID, attributeValue, attimages_id);
            var jsonResult = Json(JsonConvert.SerializeObject(image), JsonRequestBehavior.AllowGet);

            jsonResult.MaxJsonLength = int.MaxValue;
            return(jsonResult);
        }
        public JsonResult Save(Int32 id, Int32 Org, String Name, String Value, String ProductType, Int32 attrSet, Int32 taxcat, Int32 prodCat, Int32 UOM, String UPC, int Parent_ID)
        {
            ProdInfo value = null;

            if (Session["ctx"] != null)
            {
                VAdvantage.Utility.Ctx ctx   = Session["ctx"] as Ctx;
                ProductManagementModel model = new ProductManagementModel();
                value = model.save(id, Org, Name, Value, ProductType, attrSet, taxcat, prodCat, UOM, UPC, Parent_ID, ctx);
            }
            return(Json(JsonConvert.SerializeObject(value), JsonRequestBehavior.AllowGet));
        }
        public JsonResult deleteInventory(List <PriceInfo> ColumnName)
        {
            string value = "";

            if (Session["ctx"] != null)
            {
                VAdvantage.Utility.Ctx ctx   = Session["ctx"] as Ctx;
                ProductManagementModel model = new ProductManagementModel();
                value = model.deleteInventory(ColumnName, ctx);
            }
            return(Json(new { result = value }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult updateVarient(Int32 id, String UpcCode)
        {
            string value = "";

            if (Session["ctx"] != null)
            {
                VAdvantage.Utility.Ctx ctx   = Session["ctx"] as Ctx;
                ProductManagementModel model = new ProductManagementModel();
                value = model.updateVarient(id, UpcCode, ctx);
            }
            return(Json(new { result = value }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveConversion(Int32 id, Int32 Conv_ID, Decimal Mul, Decimal Div, Int32 UOM, Int32 UomTo, String UOMUPC)
        {
            string value = "";

            if (Session["ctx"] != null)
            {
                VAdvantage.Utility.Ctx ctx   = Session["ctx"] as Ctx;
                ProductManagementModel model = new ProductManagementModel();
                value = model.SaveConversion(id, Conv_ID, Mul, Div, UOM, UomTo, UOMUPC, ctx);
            }
            return(Json(new { result = value }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult deleteRelatedProduct(Int32 id, List <RelatedInfo> relatedData)
        {
            string value = "";

            if (Session["ctx"] != null)
            {
                VAdvantage.Utility.Ctx ctx   = Session["ctx"] as Ctx;
                ProductManagementModel model = new ProductManagementModel();
                value = model.deleteRelatedProduct(id, relatedData, ctx);
            }
            return(Json(new { result = value }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult UpdatePrice(Int32 id, List <PriceInfo> priceData)
        {
            string value = "";

            if (Session["ctx"] != null)
            {
                VAdvantage.Utility.Ctx ctx   = Session["ctx"] as Ctx;
                ProductManagementModel model = new ProductManagementModel();
                value = model.UpdatePrice(id, priceData, ctx);
            }
            return(Json(new { result = value }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveAttribute(int id, int AttributeSet, List <Int32> ColumnName, Dictionary <string, string> ColumnValue)
        {
            string        value  = "";
            List <String> prodID = new List <String>();

            //if (prodIDs != null && prodIDs.Trim().Length > 0)
            //{
            //    prodID = JsonConvert.DeserializeObject<List<String>>(prodIDs);
            //}
            if (Session["ctx"] != null)
            {
                VAdvantage.Utility.Ctx ctx   = Session["ctx"] as Ctx;
                ProductManagementModel model = new ProductManagementModel();
                value = model.saveAttribute(id, AttributeSet, ColumnName, ColumnValue, ctx);
            }
            return(Json(new { result = value }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult UpdateSupplier(int Supplier, List <PriceInfo> ColumnName)
        {
            string        value  = "";
            List <String> prodID = new List <String>();

            //if (prodIDs != null && prodIDs.Trim().Length > 0)
            //{
            //    prodID = JsonConvert.DeserializeObject<List<String>>(prodIDs);
            //}
            if (Session["ctx"] != null)
            {
                VAdvantage.Utility.Ctx ctx   = Session["ctx"] as Ctx;
                ProductManagementModel model = new ProductManagementModel();
                value = model.UpdateSupplier(Supplier, ColumnName, ctx);
            }
            return(Json(new { result = value }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveImage(HttpPostedFileBase file, bool isDatabaseSave, string ad_image_id)
        {
            if (file == null)
            {
                Json(new { result = false }, JsonRequestBehavior.AllowGet);
            }

            ProductManagementModel obj = new ProductManagementModel();
            var value = 0;

            if (Session["Ctx"] != null)
            {
                var ctx = Session["ctx"] as Ctx;
                if (!Directory.Exists(Path.Combine(Server.MapPath("~/Images"))))
                {
                    Directory.CreateDirectory(Path.Combine(Server.MapPath("~/Images")));
                }
                value = obj.SaveImage(ctx, Server.MapPath("~/Images"), file, Convert.ToInt32(ad_image_id), isDatabaseSave);
            }
            return(Json(new { result = value }, JsonRequestBehavior.AllowGet));
        }
        // Added by Bharat to Load Parent Product Data on 06 March 2018
        public JsonResult LoadParentData(int M_Product_ID)
        {
            ProductManagementModel model = new ProductManagementModel();

            return(Json(JsonConvert.SerializeObject(model.LoadParentData(Session["ctx"] as Ctx, M_Product_ID)), JsonRequestBehavior.AllowGet));
        }
        // Added by Bharat to Load Cart Data on 05 March 2018
        public JsonResult LoadCartData(int VAICNT_InventoryCount_ID)
        {
            ProductManagementModel model = new ProductManagementModel();

            return(Json(JsonConvert.SerializeObject(model.LoadCartData(VAICNT_InventoryCount_ID, Session["ctx"] as Ctx)), JsonRequestBehavior.AllowGet));
        }
        // Added by Bharat to Load UOM Conversion Data on 05 March 2018
        public JsonResult LoadUOMRate(int C_UOM_Conversion_ID)
        {
            ProductManagementModel model = new ProductManagementModel();

            return(Json(JsonConvert.SerializeObject(model.LoadUOMConversionData(C_UOM_Conversion_ID, Session["ctx"] as Ctx)), JsonRequestBehavior.AllowGet));
        }
        // Added by Bharat to Load UPC of Product on 05 March 2018
        public JsonResult GetProductUPC(string fields)
        {
            ProductManagementModel model = new ProductManagementModel();

            return(Json(JsonConvert.SerializeObject(model.GetProductUPC(fields, Session["ctx"] as Ctx)), JsonRequestBehavior.AllowGet));
        }
        // Added by Bharat to Load Product Attribute Data on 05 March 2018
        public JsonResult LoadProdAttributeData(int M_Product_ID, int M_AttributeSetInstance_ID, string UPC)
        {
            ProductManagementModel model = new ProductManagementModel();

            return(Json(JsonConvert.SerializeObject(model.LoadProdAttributeData(M_Product_ID, M_AttributeSetInstance_ID, UPC, Session["ctx"] as Ctx)), JsonRequestBehavior.AllowGet));
        }
        // Added by Bharat to Load Related Type on 05 March 2018
        public JsonResult LoadRelatedType()
        {
            ProductManagementModel model = new ProductManagementModel();

            return(Json(JsonConvert.SerializeObject(model.LoadRelatedType(Session["ctx"] as Ctx)), JsonRequestBehavior.AllowGet));
        }
        // Added by Bharat to Load Category Data on 05 March 2018
        public JsonResult LoadOnCategorySelect(int ProdCatID)
        {
            ProductManagementModel model = new ProductManagementModel();

            return(Json(JsonConvert.SerializeObject(model.LoadOnCategorySelect(Session["ctx"] as Ctx, ProdCatID)), JsonRequestBehavior.AllowGet));
        }