Now that we've enabled Data Migrations, we can use LINQ statements to query the data in the working database. I'd like to order the fabrics by the most popular, so I thought I'd add another property to my Fabric model called ItemsSold. I have stats from Etsy that show my most popular items and Etsy orders them by Sales or Most Visited.
I can order my fabrics by most sold items which will tell me what fabrics are the most popular. That way I can closely monitor my inventory for those fabrics and make sure I always have it in stock. I suppose a nice feature to add later on would be to have the app send me a notification whenever I start to dip below my threshold, probably a 1/4 yd or 1/2 yd.
So, here is how we would order by Items Sold, the largest being on top:
Step 9: Order Fabric List by Most Popular or Most Items Sold:
In the Home Controller, replace the ToList(); statement in the Index action with the following:
public ActionResult Index()
{
var model =
from f in _db.Fabrics
orderby f.ItemsSold descending
select f;
return View(model);
}
You should now see the fabric with the most items sold on top of the page and the listings are in descending order from there.