Created
August 26, 2016 15:48
-
-
Save JustinJohnWilliams/3736675f537c37487dcc84c544bd07aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 database | |
open FSharp.Data.Sql | |
open FSharp.Data.Sql.Common | |
let [<Literal>] connectionString = "Data Source=.;Initial Catalog=CreditFulfillment;Integrated Security=SSPI;" | |
type sql = SqlDataProvider<DatabaseProviderTypes.MSSQLSERVER, | |
connectionString, | |
CaseSensitivityChange = CaseSensitivityChange.ORIGINAL> | |
let ctx = sql.GetDataContext() | |
let getActiveAccountsFor email = | |
query { | |
for customer in ctx.Dbo.Customers do | |
join account in ctx.Dbo.Accounts on (customer.Id = account.CustomerId) | |
where (customer.EmailAddress = email && account.IsActive = true) | |
select account | |
} |> Seq.toArray | |
let deactivateAccount accountId = | |
query { | |
for account in ctx.Dbo.Accounts do | |
where (account.AccountId = accountId) | |
select account | |
} |> Seq.iter(fun account -> | |
account.IsActive <- false | |
) | |
ctx.SubmitUpdates() | |
let deActivateCustomer email = | |
getActiveAccountsFor email |> Seq.iter (fun account -> deactivateAccount account.AccountId) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment