annotate Library/LibrarySystem/Core/Library.cs @ 41:dbd242eb9c33

Initial wave of TDD development
author adminsh@apollo
date Tue, 03 Apr 2012 23:29:32 +0100
parents
children aef06698d9e2
rev   line source
41
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
1 using System.Collections.Generic;
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
2 using System.Linq;
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
3 using LibrarySystem.Interfaces;
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
4
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
5 namespace LibrarySystem.Core
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
6 {
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
7 public class Library : ILibrary
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
8 {
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
9 public string Location { get; set; }
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
10 public IList<IStock> StockList { get; set; }
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
11
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
12 public Library()
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
13 {
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
14 StockList = new List<IStock>(0);
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
15 }
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
16
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
17 public void AddStock(params IBook[] books)
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
18 {
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
19 var stock = new List<IStock>(StockList.Count + books.Length);
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
20
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
21 stock.AddRange(StockList);
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
22
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
23 foreach (var book in books)
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
24 {
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
25 stock.Add(new Stock() { Book = book, IsAvailable = true });
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
26 }
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
27
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
28 StockList = stock;
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
29 }
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
30
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
31 public bool IsBookAvailableByISBN(string isbn)
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
32 {
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
33 var qry = from books in StockList
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
34 where books.Book.ISBN == isbn
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
35 & books.IsAvailable
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
36 select books.IsAvailable;
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
37
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
38 return qry.FirstOrDefault();
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
39 }
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
40
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
41 public IList<IStock> FindBooks(string searchString)
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
42 {
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
43 searchString = searchString.ToLower();
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
44
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
45 var qry = from books in StockList
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
46 where books.Book.Title.ToLower().Contains(searchString)
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
47 || books.Book.Author.ToLower().Contains(searchString)
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
48 select books;
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
49
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
50 return qry.ToList();
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
51 }
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
52
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
53 public void LendBook(IPerson person, IBook book)
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
54 {
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
55 throw new System.NotImplementedException();
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
56 }
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
57 }
dbd242eb9c33 Initial wave of TDD development
adminsh@apollo
parents:
diff changeset
58 }