Skip to content

Instantly share code, notes, and snippets.

View schotime's full-sized avatar

Adam Schroder schotime

  • Melbourne, Australia
View GitHub Profile
@schotime
schotime / gist:925273
Created April 18, 2011 12:56
QueryInvoker
public interface IQueryInvoker
{
TViewModel Invoke<TViewModel>() where TViewModel : new();
}
public class QueryInvoker : IQueryInvoker
{
private readonly IObjectResolver _objectResolver;
public QueryInvoker(IObjectResolver objectResolver)
public class RepositoryConvention : IRegistrationConvention
{
public void Process(Type type, StructureMap.Configuration.DSL.Registry registry)
{
if (type.IsClass && type.GetInterfaces().Where(x => x == typeof(IRepository)).Any())
{
if (type.Name.Contains(GlobalSettings.DbType))
{
Type specificInterface = type.GetInterfaces().Where(x => x != typeof(IRepository)).First();
registry.For(specificInterface).Use(type);
public class AutoMapperProfile : Profile
{
protected override void Configure()
{
CreateMap<DateTime, FormattedDateTime>().ConvertUsing<FormattedDateConverter>();
CreateMap<string, bool>().ConvertUsing(x => x == "Y" || x.ToLowerInvariant() == "on" || x == "1");
DictionaryToClassConverter.ConvertFromDictionary(this, GetType().Assembly, x => x.ToLowerInvariant());
}
//Mappings
CreateMap<DateTime, FormattedDateTime>().ConvertUsing<FormattedDateConverter>();
CreateMap<string, bool>().ConvertUsing(x => x == "Y" || x.ToLowerInvariant() == "on" || x == "1");
//Dictionary
var dict = new Dictionary<string,object>() { { "id", 2 },{ "date", DateTime.Now }, { "istrue", "Y" } };
//Class
//Take this
public ActionResult Logins()
{
var mapped = _repository
.Query(new GetLoginHistoryAndUser())
.AutoMap<LoginHistory, LoginHistoryDisplay>()
.ToList();
return View(new LoginHistoryViewModel { LoginHistory = mapped });
var collection = new MongoCollection(tranny.TypeName, DB, DB.CurrentConnection);
var result = collection.Find(fly, tranny.Take, tranny.Skip);
// So that
IEnumberable<T> list = (IEnumerable<T>)result;
// Where T is the type is in the list