public Order(Reader reader, Book book)
 {
     Id = Guid.NewGuid();
     Reader = reader;
     Book = book;
     if (book != null)
     {
         Department = book.Department;
     }
 }
 public Order(Guid id, Reader reader, Book book)
 {
     Id = id;
     Reader = reader;
     Book = book;
     if (book != null)
     {
         Department = book.Department;
     }
 }
 public override void Save(Book item)
 {
     Book Book = GetItem(item.Id);
     if (Book != null)
     {
         books[books.IndexOf(Book)] = item;
     }
     else
     {
         books.Add(item);
     }
 }
 public override IEnumerable<Order> GetOrdersByBook(Book book, bool closed)
 {
     using (BinaryReader binaryReader = new BinaryReader(File.Open(FileName, FileMode.Open), Encoding.Unicode))
     {
         while (binaryReader.PeekChar() != -1)
         {
             string[] arrayString = binaryReader.ReadString().Split('|');
             if ( arrayString[2] == book.Id.ToString() && Convert.ToBoolean(arrayString[8]) == closed )
             {
                 yield return CreateItem(arrayString);
             }
         }
     }
 }
        public LibraryClassTest()
        {
            repository = new Repository(new ObjectRepositoryFactory());

            reader = new Reader("Иван Иванов", "Брест");
            repository.ReaderRepository.Save(reader);
            department = new LibraryDepartment("Абонемент", true);
            repository.LibraryDepartmentRepository.Save(department);
            librarian = new Librarian("Мария Иванова", department);
            repository.LibrarianRepository.Save(librarian);
            book = new Book("Михаил Фленов", "Библия C#", 2002, department);
            repository.BookRepository.Save(book);

            library = new LibraryClass(repository);
        }
 public void GetBooksOrderedByReaderTest()
 {
     library.AuthorizationReader(reader);
     library.OrderBook(book, reader);
     IEnumerable<Book> books = library.GetBooksOrderedByReader(reader);
     Assert.AreEqual(1, books.Count());
     Book book2 = new Book("Бен Ватсон", "С# 4.0 на примерах", 2000, department);
     library.OrderBook(book2, reader);
     books = library.GetBooksOrderedByReader(reader);
     Assert.AreEqual(2, books.Count());
     Assert.IsTrue(books.Contains(book));
     Assert.IsTrue(books.Contains(book2));
     library.ReturnBook(book);
     library.ReturnBook(book2);
     library.ExitReader(reader);
 }
 public override void Remove(Book item)
 {
     books.Remove(item);
 }
 public BookTest()
 {
     b1 = new Book("Author1", "Title1", 1999, new LibraryDepartment("Абонемент", true));
     b2 = new Book("Author2", "Title2", 2000, new LibraryDepartment("Читальный зал", false));
     b3 = new Book(b1.Id, "Author1", "Title1", 1999, b1.Department);
 }
        public bool OrderBook(Book book, Reader reader)
        {
            if (openOrders.Select(o => o.Book).Contains(book)) return false;
            if (!activeReaders.Contains(reader)) return false;

            Order order = new Order(reader, book);
            order.TimeGetBook = DateTime.Now;
            order.LibrarianOpenOrder = workLibrarians.First(l => l.Department == book.Department);

            openOrders.Add(order);
            repository.OrderRepository.Save(order);

            return true;
        }
 public void ReturnBook(Book book)
 {
     Order order = openOrders.Single(o => o.Book == book);
     openOrders.Remove(order);
     order.TimeReturnBook = DateTime.Now;
     order.LibrarianClosedOrder = workLibrarians.First(l => l.Department == book.Department);
     order.Closed = true;
     repository.OrderRepository.Save(order);
 }
 public override IEnumerable<Order> GetOrdersByBook(Book book, bool closed)
 {
     return orders.Where(order => order.Book.Id == book.Id && order.Closed == closed);
 }
 public override void Save(Book item)
 {
     XElement element = document.Root.Elements("Book").SingleOrDefault(e => e.Attribute("id").Value == item.Id.ToString());
     if (element != null)
     {
         element.Element("Author").Value = item.Author;
         element.Element("Title").Value = item.Title;
         element.Element("Year").SetValue(item.Year);
         element.Element("DepartmentId").SetValue(item.Department.Id);
     }
     else
     {
         document.Root.Add(
             new XElement("Book",
                 new XAttribute("id", item.Id),
                 new XElement("Author", item.Author),
                 new XElement("Title", item.Title),
                 new XElement("Year", item.Year),
                 new XElement("DepartmentId", item.Department.Id)));
     }
     document.Save(FileName);
     libraryDepartmentRepository.Save(item.Department);
 }
 public override void Remove(Book item)
 {
     Remove(item.Id);
 }
 public override IEnumerable<Order> GetOrdersByBook(Book book, bool closed)
 {
     return document.Root.Elements("Order")
         .Where(e => e.Element("BookId").Value == book.Id.ToString() && Convert.ToBoolean(e.Element("Closed").Value) == closed)
         .Select(e => CreateItem(e));
 }
 public override void Save(Book item)
 {
     int i = 0;
     using (BinaryReader binaryReader = new BinaryReader(File.Open(FileName, FileMode.Open), Encoding.Unicode))
     {
         while (binaryReader.PeekChar() != -1)
         {
             string[] arrayString = binaryReader.ReadString().Split('|');
             if (arrayString[0] == item.Id.ToString()) break;
             i = i + 1;
         }
     }
     using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(FileName, FileMode.Open, FileAccess.Write), Encoding.Unicode))
     {
         binaryWriter.Seek(i * RecordSize, SeekOrigin.Begin);
         StringBuilder str = new StringBuilder(
             String.Join("|", item.Id.ToString(), item.Author, item.Title, item.Year.ToString(), item.Department.Id.ToString()));
         str.Append("|");
         str.Length = MaxRecordStringLength;
         binaryWriter.Write(str.ToString());
     }
     libraryDepartmentRepository.Save(item.Department);
 }
 private static bool BookCompare(Book a, Book b)
 {
     if (Object.ReferenceEquals(a, b))
     {
         return true;
     }
     return a.Id == b.Id &&
         a.Author == b.Author &&
         a.Title == b.Title &&
         a.Year == b.Year &&
         a.Department == b.Department;
 }