Skip to content

Instantly share code, notes, and snippets.

@srdjan
Forked from dtchepak/BorrowABook.fs
Created November 11, 2013 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srdjan/7414716 to your computer and use it in GitHub Desktop.
Save srdjan/7414716 to your computer and use it in GitHub Desktop.
module BorrowABook =
type BookLoanProblem =
NotInCatalogue
| OutOnLoan
| InsufficientPermission
| Failed of string
type Book = Book
type BookModel = BookModel
let borrow (b : BookModel) : Choice<Book, BookLoanProblem> = Choice1Of2 Book
open System.Web
open System.Web.Mvc
open FSharpx
open BorrowABook
[<HandleError>]
type LibraryController() =
inherit Controller()
member this.viewForProb (prob : BookLoanProblem) =
match prob with
| NotInCatalogue -> setFlash "Not in catalogue"; this.redirect "Catalogue"
| OutOnLoan -> setFlash "Out on loan"; this.redirect "Catalogue"
| InsufficientPermission -> setFlash "Don't have permission"; this.redirect "Catalogue"
| Failed s -> setFlash s; this.viewByName("BorrowFailed")
member this.Borrow (model : BookModel) : ActionResult =
borrow model
|> Choice.choice (this.view "Borrowed") this.viewForProb
let setFlash msg = ()
// Helpers for partial app etc. Put in f#-specific controller base class?
member this.view (s : string) (m:obj) : ActionResult = upcast this.View(s, m)
member this.viewByName (s : string) : ActionResult = upcast this.View(s)
member this.redirect s : ActionResult = upcast this.RedirectToAction(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment