Mercurial > silverbladetech
comparison 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 |
comparison
equal
deleted
inserted
replaced
40:64c89891d7b6 | 41:dbd242eb9c33 |
---|---|
1 using System.Collections.Generic; | |
2 using System.Linq; | |
3 using LibrarySystem.Interfaces; | |
4 | |
5 namespace LibrarySystem.Core | |
6 { | |
7 public class Library : ILibrary | |
8 { | |
9 public string Location { get; set; } | |
10 public IList<IStock> StockList { get; set; } | |
11 | |
12 public Library() | |
13 { | |
14 StockList = new List<IStock>(0); | |
15 } | |
16 | |
17 public void AddStock(params IBook[] books) | |
18 { | |
19 var stock = new List<IStock>(StockList.Count + books.Length); | |
20 | |
21 stock.AddRange(StockList); | |
22 | |
23 foreach (var book in books) | |
24 { | |
25 stock.Add(new Stock() { Book = book, IsAvailable = true }); | |
26 } | |
27 | |
28 StockList = stock; | |
29 } | |
30 | |
31 public bool IsBookAvailableByISBN(string isbn) | |
32 { | |
33 var qry = from books in StockList | |
34 where books.Book.ISBN == isbn | |
35 & books.IsAvailable | |
36 select books.IsAvailable; | |
37 | |
38 return qry.FirstOrDefault(); | |
39 } | |
40 | |
41 public IList<IStock> FindBooks(string searchString) | |
42 { | |
43 searchString = searchString.ToLower(); | |
44 | |
45 var qry = from books in StockList | |
46 where books.Book.Title.ToLower().Contains(searchString) | |
47 || books.Book.Author.ToLower().Contains(searchString) | |
48 select books; | |
49 | |
50 return qry.ToList(); | |
51 } | |
52 | |
53 public void LendBook(IPerson person, IBook book) | |
54 { | |
55 throw new System.NotImplementedException(); | |
56 } | |
57 } | |
58 } |