Jury-rig


Software Engineering, a personal journey

Site Update: Tagging articles

All blogs tag articles so that you can catagorise and aggregate content into meaningful catagories fit for human interaction

I've also added tags to my homebrew MVC blog (check them out below). The main method used to return comment articles which share a tag uses LINQ. Also a ?: Operator just incase a tag hasn't been passed. The code is as follows:
        public static IEnumerable<ArticlesModel> Articles(string tag)
        {
            var Items = new List<ArticlesModel>();
            using (var db = new LiteDatabase(DbConnectionString.DbLocation))
            {
                var collection = db.GetCollection<ArticlesModel>("Articles");
                collection.EnsureIndex(x => x._Id);
                var results = !string.IsNullOrEmpty(tag) ? collection.FindAll().Where(c => c.Tags.Contains(tag)) : collection.FindAll();
                dummyItems.AddRange(results);
            }
            return Items;
        }‚Äč
 


Comments



Have your say

Author:

Comment here (140 chars only)*:

Email address: