public IActionResult GetProductsToXml(int productId) { var products = _productRepo.Products; var getProducts = ViewModelHelper.GetProducts(products); var selectedProduct = getProducts.FirstOrDefault(x => x.Id.Equals(productId)); if (productId == 0) { return(Ok(getProducts)); } else { return(Ok(selectedProduct)); } }
public IActionResult GetProductsToJson(int productId) { var products = _productRepo.Products; var getProducts = ViewModelHelper.GetProducts(products); var selectedProduct = getProducts.FirstOrDefault(x => x.Id.Equals(productId)); if (productId == 0) { var productJson = JsonConvert.SerializeObject(getProducts); var bytes = Encoding.UTF8.GetBytes(productJson); return(File(bytes, "application/octet-stream", "products.json")); } else { var selectedProductJson = JsonConvert.SerializeObject(selectedProduct); var bytes = Encoding.UTF8.GetBytes(selectedProductJson); return(File(bytes, "application/octet-stream", "product_" + productId + ".json")); } }