Lab meta work, fix broken links in source search

This commit is contained in:
Thomas Hounsell 2014-12-17 21:46:34 +00:00
parent d91b52f38e
commit 05d6459a18
2 changed files with 88 additions and 7 deletions

View File

@ -34,14 +34,14 @@ public IEnumerable<SearchResult> GetSearchResult(string query)
List<SearchResult> results = new List<SearchResult>(); List<SearchResult> results = new List<SearchResult>();
var sourceResults = from s in Enum.GetValues(typeof(BuildFeed.Models.TypeOfSource)).Cast<BuildFeed.Models.TypeOfSource>().Select(s => DisplayHelpers.GetDisplayTextForEnum(s)) var sourceResults = from s in Enum.GetValues(typeof(BuildFeed.Models.TypeOfSource)).Cast<BuildFeed.Models.TypeOfSource>().Select(s => new { Text = DisplayHelpers.GetDisplayTextForEnum(s), Value = s })
where s.ToLower().Contains(query.ToLower()) where s.Text.ToLower().Contains(query.ToLower())
orderby s.ToLower().IndexOf(query.ToLower()) ascending orderby s.Text.ToLower().IndexOf(query.ToLower()) ascending
select new SearchResult() select new SearchResult()
{ {
Url = Url.Route("Source Root", new { controller = "build", action = "source", source = s }), Url = Url.Route("Source Root", new { controller = "build", action = "source", source = s.Value }),
Label = s.Replace(query, "<strong>" + query + "</strong>"), Label = s.Text.Replace(query, "<strong>" + query + "</strong>"),
Title = s, Title = s.Text,
Group = "Source" Group = "Source"
}; };

View File

@ -1,5 +1,7 @@
using NServiceKit.DataAnnotations; using BuildFeed;
using NServiceKit.DataAnnotations;
using NServiceKit.DesignPatterns.Model; using NServiceKit.DesignPatterns.Model;
using NServiceKit.Redis;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -25,5 +27,84 @@ public class LabMeta : IHasId<string>
[DisplayName("Meta Description")] [DisplayName("Meta Description")]
public string MetaDescription { get; set; } public string MetaDescription { get; set; }
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static IEnumerable<LabMeta> Select()
{
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
{
var client = rClient.As<LabMeta>();
return client.GetAll();
}
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static LabMeta SelectById(string id)
{
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
{
var client = rClient.As<LabMeta>();
return client.GetById(id);
}
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static IEnumerable<string> SelectUnusedLabs()
{
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
{
var client = rClient.As<LabMeta>();
var labs = Build.SelectBuildLabs();
var usedLabs = client.GetAll();
return from l in labs
where !usedLabs.Any(ul => ul.Id == l)
select l;
}
}
[DataObjectMethod(DataObjectMethodType.Insert, true)]
public static void Insert(LabMeta item)
{
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
{
var client = rClient.As<LabMeta>();
client.Store(item);
}
}
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static void Update(LabMeta item)
{
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
{
var client = rClient.As<LabMeta>();
client.Store(item);
}
}
[DataObjectMethod(DataObjectMethodType.Insert, false)]
public static void InsertAll(IEnumerable<LabMeta> items)
{
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
{
var client = rClient.As<LabMeta>();
client.StoreAll(items);
}
}
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static void DeleteById(long id)
{
using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database))
{
var client = rClient.As<LabMeta>();
client.DeleteById(id);
}
}
} }
} }