-
-
Save srdjan/7414716 to your computer and use it in GitHub Desktop.
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
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 |
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
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