Skip to content

Instantly share code, notes, and snippets.

@t0yv0
Created January 28, 2011 09:42
Show Gist options
  • Save t0yv0/800045 to your computer and use it in GitHub Desktop.
Save t0yv0/800045 to your computer and use it in GitHub Desktop.
let Controller =
let handle = function
| ShowRecentBlogs ->
let blogs = Model.WithBlogs <| fun db -> db.GetRecentBlogs()
View.ShowRecentBlogs blogs
| CreateBlog ->
View.CreateBlog ()
| ReadBlog id ->
let blog = Model.WithBlogs <| fun db -> db.ReadBlog id
match blog with
| Some blog ->
View.ReadBlog blog
| None ->
Content.NotFound
| UpdateBlog id ->
let blog = Model.WithBlogs <| fun db -> db.ReadBlog id
match blog with
| None -> Content.Redirect Action.CreateBlog
| Some blog -> View.UpdateBlog blog
| DeleteBlog id ->
let blog = Model.WithBlogs <| fun db ->
let blog = db.ReadBlog id
if blog.IsSome then
db.DeleteBlog id
|> ignore
blog
match blog with
| Some blog ->
View.BlogDeleted blog
| None ->
Content.ServerError
{ Handle = handle }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment