My url should look like this: localhost/Products/Details/1/asus-intel-core-2-duo
.
As you can see, the slug is generated from existing fields: brand-processorBrand-ProcessorModel
. My title will also look like this, without the dashes. I generate this slug in my Service layer. I have 2 questions:
Where and how should I store this format so I can change it once and everything else changes? ie.
{brand} {processorBrand} {ProcessorModel}
How do I generate the string? I only know about:
string.Format("{0} {1} {2}", Model.Brand, Model.ProcessorBrand, Model.ProcessorModel)
. Which doesn't seem like it could work in the case of storing the format elsewhere.
If I am going about this wrong, I have another method in mind. But this requires me to loop over every product in the service layer and call a method on the product class which generates a title and slug. For eg.
public class Product
{
public void GenerateStuff();
//Other properties here...
public string Title {get; set;};
public string Slug {get; set;};
}
I know there is a better way to do this, every method I have seems very messy.