Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Edited Issue: Expose the default logic of link generation to enable re-using logic. [536]

$
0
0
I agree that its easy to create links ourselves, but its natural and easier to just fallback to the default logic too.

Scenarios:
a. I would like to build a 'Transient' action on Product called "ExtendSupportDate". In my HasActionLink logic, I check to see if the given entity instance context(Product) is discontinued or not. if discontinued, i do not want to 'advertise' the action "ExtendSupportDate" otherwise I would like to re-use whatever logic the default Action link convention generates.
b. Similar as above, a scenario where you don't want to show Edit link for some entity instances and for the rest of them would want to use the default Edit link convention that we have.

Currently for scenario 'a', i am doing the following:
----------------------------------------------------------
static IEdmModel GetImplicitEdmModel()
{
ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
var products = modelBuilder.EntitySet<Product>("Products");
var productFamilies = modelBuilder.EntitySet<ProductFamily>("ProductFamilies");
var suppliers = modelBuilder.EntitySet<Supplier>("Suppliers");

var config = products.EntityType.TransientAction("ExtendSupportDate");
config.Parameter<DateTime>("newDate");
config.ReturnsFromEntitySet<Product>("Products");
config.HasActionLink(eic =>
{
//Do not advertise 'ExtendSupportDate' for discontinued products
if(eic.EntityType.Name == "DiscontinuedProduct")
return null;

//Advertise for the rest of them
Product pd = (Product)eic.EntityInstance;

return new Uri(eic.UrlHelper.Link(ODataRouteNames.InvokeBoundAction, new {
controller = eic.EntitySet.Name,
boundId = pd.ID,
odataAction = "ExtendSupportDate" }));
});

return modelBuilder.GetEdmModel();
}

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>