public void DeleteStateDescription(StateDescription stateDescription) { if (!dataContext.Descriptions.Remove(stateDescription)) { throw new ItemDoesNotExistException(stateDescription, dataContext.Descriptions); } }
public StateDescription(StateDescription description) { Code = description.Code; Book = description.Book; Availabile = description.Availabile; PurchaseDate = description.PurchaseDate; Location = description.Location; }
public void AddStateDescription(StateDescription description) { if (!dataContext.Descriptions.Contains(description)) { dataContext.Descriptions.Add((StateDescription)description); } else { throw new ItemAlreadyExistsException(description, dataContext.Descriptions); } }
public void UpdateStateDescription(StateDescription description) { int index = dataContext.Descriptions.IndexOf(description); if (index == -1) { throw new ItemDoesNotExistException(description, dataContext.Descriptions); } dataContext.Descriptions[index] = (StateDescription)description; }
public List <Event> GetAllTransactionsByBookState(StateDescription bookState) { List <Event> eventList = new List <Event>(); foreach (Event transaction in GetAllTransactions()) { if (transaction.BookState.Equals(bookState)) { eventList.Add(transaction); } } return(eventList); }
public void BorrowBook(Person person, long bookStateCode) { StateDescription state = repository.GetStateDescriptionByCode(bookStateCode); if (state == null) { throw new ItemDoesNotExistException(bookStateCode, typeof(StateDescription)); } if (!state.Availabile) { throw new BookUnavailableException(state); } state.Availabile = false; repository.AddTransaction(new Event(person, state, Event.EventType.Borrow, DateTimeOffset.Now)); }
public Event(Person causer, StateDescription bookState, EventType type, DateTimeOffset date) { Code = getNextID(); Causer = causer; Type = type; BookState = bookState; if (type == EventType.Borrow) { BorrowDate = date; } else { BookState = bookState; } }
public Person GetPersonByBorrowedBook(StateDescription book) { if (book.Availabile) { throw new BookNotUnavailableException(book); } foreach (Event transaction in GetAllTransactions()) { if (transaction.BookState.Code == book.Code) { return(transaction.Causer); } } throw new ItemDoesNotExistException(string.Format("Could not find person who borrowed {0}", book)); }
public void ReturnBook(long bookStateCode) { StateDescription state = repository.GetStateDescriptionByCode(bookStateCode); if (state == null) { throw new ItemDoesNotExistException(bookStateCode, typeof(StateDescription)); } if (!state.Availabile) { throw new BookNotUnavailableException(state); } Person person = GetPersonByBorrowedBook(state); state.Availabile = true; repository.AddTransaction(new Event(person, state, Event.EventType.Return, DateTimeOffset.Now)); }
public BookUnavailableException(StateDescription book) : base(string.Format("Book {0} is currently borrowed.", book)) { }
public BorrowEvent(Person causer, StateDescription bookState, DateTimeOffset date) : base(causer, bookState, date) { }
public void AddStateDescription(StateDescription description) { repository.AddStateDescription(description); }
public void DeleteStateDescription(StateDescription stateDescription) { repository.DeleteStateDescription(stateDescription); }
public void UpdateStateDescription(StateDescription description) { repository.UpdateStateDescription(description); }