29.05.2015 Views

o_19mgorv9t13a3ko71fev19l81mqa.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ReservationRepository.cs to the Models folder and you can see the contents of the new file in Listing 27-2.<br />

Listing 27-2. The Contents of the ReservationRespository.cs File<br />

using System.Collections.Generic;<br />

using System.Linq;<br />

namespace WebServices.Models {<br />

public class ReservationRespository {<br />

private static ReservationRespository repo = new<br />

ReservationRespository();<br />

public static ReservationRespository Current {<br />

get {<br />

return repo;<br />

}<br />

}<br />

private List data = new List {<br />

new Reservation {<br />

ReservationId = 1, ClientName = "Adam", Location = "Board<br />

Room"},<br />

new Reservation {<br />

ReservationId = 2, ClientName = "Jacqui", Location =<br />

"Lecture Hall"},<br />

new Reservation {<br />

ReservationId = 3, ClientName = "Russell", Location =<br />

"Meeting Room 1"},<br />

};<br />

public IEnumerable GetAll() {<br />

return data;<br />

}<br />

public Reservation Get(int id) {<br />

return data.Where(r => r.ReservationId ==<br />

id).FirstOrDefault();<br />

}<br />

public Reservation Add(Reservation item) {<br />

item.ReservationId = data.Count + 1;<br />

data.Add(item);<br />

return item;<br />

}<br />

public void Remove(int id) {<br />

Reservation item = Get(id);<br />

if (item != null) {<br />

data.Remove(item);<br />

}<br />

}<br />

public bool Update(Reservation item) {<br />

Reservation storedItem = Get(item.ReservationId);<br />

if (storedItem != null) {<br />

706

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!