-
Notifications
You must be signed in to change notification settings - Fork 0
/
Repository.fs
37 lines (25 loc) · 1.02 KB
/
Repository.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
namespace Dhl
open FSharp.Data
open FSharp.Data.Runtime
open System
open System.IO
open Resources
type TrackingNumbers = CsvProvider<"./Data/sample.csv", Separators=";", ResolutionFolder=__SOURCE_DIRECTORY__>
type TrackingNumber = TrackingNumber of string
module Repository =
let private path =
(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "dhl.csv")
|> Path.Combine
let loadFile () = path |> TrackingNumbers.Load
let saveFile (file: CsvFile<TrackingNumbers.Row>) = path |> file.Save
let loadTrackingNumbers () =
loadFile().Rows |> Seq.map (fun r -> TrackingNumber(r))
let add (TrackingNumber(number)) =
loadFile ()
|> fun rows -> rows.Append [ new TrackingNumbers.Row(number) ]
|> saveFile
Number_Added.FormattedString(number)
let remove (TrackingNumber(number)) =
loadFile ()
|> fun file -> file.Filter(fun item -> item.TrackingNumber <> number) |> saveFile
Number_Removed.FormattedString(number)