public virtual IActionResult RelatedProductUpdate(RelatedProductModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) { return(AccessDeniedView()); } //try to get a related product with the specified id var relatedProduct = _productService.GetRelatedProductById(model.Id) ?? throw new ArgumentException("No related product found with the specified id"); //a vendor should have access only to his products if (_workContext.CurrentVendor != null) { var product = _productService.GetProductById(relatedProduct.ProductId1); if (product != null && product.VendorId != _workContext.CurrentVendor.Id) { return(Content("This is not your product")); } } relatedProduct.DisplayOrder = model.DisplayOrder; _productService.UpdateRelatedProduct(relatedProduct); return(new NullJsonResult()); }
public JsonResult SaveRelatedLines(List <RelatedProductData> Data, int Table_ID, int Record_ID) { string result = ""; if (Session["ctx"] != null) { var ctx = Session["ctx"] as Ctx; RelatedProductModel obj = new RelatedProductModel(); result = obj.CreateRelatedLines(ctx, Data, Table_ID, Record_ID); } return(Json(JsonConvert.SerializeObject(result), JsonRequestBehavior.AllowGet)); }
/// <summary> /// Getting Related Product Data /// </summary> /// <param name="M_Product_ID">Product</param> /// <param name="M_AttributeSetInstance_ID">Attribute</param> /// <param name="M_PriceList_ID">Price List</param> /// <param name="Table_ID">Table ID</param> /// <param name="Record_ID">Record ID</param> /// <returns>Related Product data in json format</returns> public JsonResult GetRelatedProduct(int M_Product_ID, int M_AttributeSetInstance_ID, int C_UOM_ID, int M_PriceList_ID, string RelatedProductType, int Table_ID, int Record_ID) { string Result = string.Empty; if (Session["ctx"] != null) { var ctx = Session["ctx"] as Ctx; RelatedProductModel obj = new RelatedProductModel(); Result = JsonConvert.SerializeObject(obj.GetRelatedProduct(ctx, M_Product_ID, M_AttributeSetInstance_ID, C_UOM_ID, M_PriceList_ID, RelatedProductType, Table_ID, Record_ID)); } return(Json(Result, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Prepare paged related product list model /// </summary> /// <param name="searchModel">Related product search model</param> /// <param name="product">Product</param> /// <returns>Related product list model</returns> public virtual RelatedProductListModel PrepareRelatedProductListModel(RelatedProductSearchModel searchModel, Product product) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (product == null) { throw new ArgumentNullException(nameof(product)); } //get related products var relatedProducts = _productService.GetRelatedProductsByProductId1(productId1: product.Id, showHidden: true); //prepare grid model var model = new RelatedProductListModel { Data = relatedProducts.PaginationByRequestModel(searchModel).Select(relatedProduct => { //fill in model values from the entity var relatedProductModel = new RelatedProductModel { Id = relatedProduct.Id, ProductId2 = relatedProduct.ProductId2, DisplayOrder = relatedProduct.DisplayOrder }; //fill in additional values (not existing in the entity) relatedProductModel.Product2Name = _productService.GetProductById(relatedProduct.ProductId2)?.Name; return(relatedProductModel); }), Total = relatedProducts.Count }; return(model); }