Last active
December 17, 2015 07:48
-
-
Save Maarten88/5574942 to your computer and use it in GitHub Desktop.
Simple Queries and Commands for working with Markdown Content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using Auction.Web.Domain.Entities; | |
using Auction.Web.Domain.Infrastructure; | |
using SqlFu; | |
namespace Auction.Web.Domain.Commands | |
{ | |
public class DeleteContentPage : Command | |
{ | |
int id; | |
public DeleteContentPage(int id) | |
{ | |
this.id = id; | |
} | |
public override void Execute(ICommandContext context) | |
{ | |
context.DataContext.DeleteFrom<ContentPage>("Id = @Id", new { Id = this.id }); | |
} | |
} | |
public class UpdateContentPage : Command | |
{ | |
ContentPage page; | |
public UpdateContentPage(ContentPage page) | |
{ | |
this.page = page; | |
} | |
public override void Execute(ICommandContext context) | |
{ | |
context.DataContext.Update<ContentPage>(page); | |
} | |
} | |
public class InsertContentPage : Command | |
{ | |
ContentPage page; | |
public InsertContentPage(ContentPage page) | |
{ | |
this.page = page; | |
} | |
public override void Execute(ICommandContext context) | |
{ | |
context.DataContext.Insert<ContentPage>(page); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Auction.Web.Domain.Entities; | |
using Auction.Web.Domain.Infrastructure; | |
using SqlFu; | |
namespace Auction.Web.Domain.Queries | |
{ | |
public class SingleContentPageById : Query<ContentPage> | |
{ | |
private int id; | |
public SingleContentPageById(int id) | |
{ | |
this.id = id; | |
} | |
public override ContentPage Execute(IQueryContext context) | |
{ | |
return context.DataContext.Get<ContentPage>(this.id); | |
} | |
} | |
public class SingleContentPage : Query<ContentPage> | |
{ | |
private string slug; | |
public SingleContentPage(string slug) | |
{ | |
this.slug = slug; | |
} | |
public override ContentPage Execute(IQueryContext context) | |
{ | |
return context.DataContext.Query<ContentPage>("Slug = @Slug", new { Slug = this.slug }).SingleOrDefault(); | |
} | |
} | |
public class GetAllContentPages : Query<IEnumerable<ContentPage>> | |
{ | |
public override IEnumerable<ContentPage> Execute(IQueryContext context) | |
{ | |
return context.DataContext.Query<ContentPage>("SELECT * FROM ContentPage"); | |
} | |
} | |
public class GetSeoContentPages : Query<IEnumerable<ContentPage>> | |
{ | |
bool noSearch; | |
public GetSeoContentPages(bool noSearch) | |
{ | |
this.noSearch = noSearch; | |
} | |
public override IEnumerable<ContentPage> Execute(IQueryContext context) | |
{ | |
return context.DataContext.Query<ContentPage>("SELECT * FROM ContentPage WHERE NoSearch = @NoSearch", new { NoSearch = this.noSearch }); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment