Beispiel #1
0
 public void DeleteStateDescription(StateDescription stateDescription)
 {
     if (!dataContext.Descriptions.Remove(stateDescription))
     {
         throw new ItemDoesNotExistException(stateDescription, dataContext.Descriptions);
     }
 }
Beispiel #2
0
 public StateDescription(StateDescription description)
 {
     Code         = description.Code;
     Book         = description.Book;
     Availabile   = description.Availabile;
     PurchaseDate = description.PurchaseDate;
     Location     = description.Location;
 }
Beispiel #3
0
 public void AddStateDescription(StateDescription description)
 {
     if (!dataContext.Descriptions.Contains(description))
     {
         dataContext.Descriptions.Add((StateDescription)description);
     }
     else
     {
         throw new ItemAlreadyExistsException(description, dataContext.Descriptions);
     }
 }
Beispiel #4
0
        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;
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
        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;
            }
        }
Beispiel #8
0
        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));
        }
Beispiel #9
0
        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))
 {
 }
Beispiel #11
0
 public BorrowEvent(Person causer, StateDescription bookState, DateTimeOffset date) : base(causer, bookState, date)
 {
 }
Beispiel #12
0
 public void AddStateDescription(StateDescription description)
 {
     repository.AddStateDescription(description);
 }
Beispiel #13
0
 public void DeleteStateDescription(StateDescription stateDescription)
 {
     repository.DeleteStateDescription(stateDescription);
 }
Beispiel #14
0
 public void UpdateStateDescription(StateDescription description)
 {
     repository.UpdateStateDescription(description);
 }