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