public ReaderObjectRepositoryTest()
 {
     readerRepository = new ReaderObjectRepository();
     John = new Reader("John Doe", "Boston");
     Alex = new Reader("Alex Pupkin", "London");
     Pavel = new Reader("Павел Первый", "Брест");
 }
 public Order(Reader reader, Book book)
 {
     Id = Guid.NewGuid();
     Reader = reader;
     Book = book;
     if (book != null)
     {
         Department = book.Department;
     }
 }
 private static bool ReaderCompare(Reader a, Reader b)
 {
     if (Object.ReferenceEquals(a, b))
     {
         return true;
     }
     return a.Id == b.Id &&
         a.FullName == b.FullName &&
         a.Address == b.Address;
 }
 public Order(Guid id, Reader reader, Book book)
 {
     Id = id;
     Reader = reader;
     Book = book;
     if (book != null)
     {
         Department = book.Department;
     }
 }
 public bool AuthorizationReader(Reader reader)
 {
     if (activeReaders.Contains(reader))
     {
         return false;
     }
     else
     {
         activeReaders.Add(reader);
         return true;
     }
 }
 public override void Save(Reader item)
 {
     Reader reader = GetItem(item.Id);
     if (reader != null)
     {
         readers[readers.IndexOf(reader)] = item;
     }
     else
     {
         readers.Add(item);
     }
 }
        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 override void Remove(Reader item)
 {
     Remove(item.Id);
 }
 public override void Save(Reader 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.FullName, item.Address));
         str.Append("|");
         str.Length = MaxRecordStringLength;
         binaryWriter.Write(str.ToString());
     }
 }
        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 IEnumerable<Book> GetBooksOrderedByReader(Reader reader)
 {
     return openOrders.Where(order => order.Reader == reader).Select(order => order.Book);
 }
 public bool ExitReader(Reader reader)
 {
     activeReaders.Remove(reader);
     return true;
 }
 public Reader AddReader(string fullName, string address)
 {
     Reader reader = new Reader(fullName, address);
     repository.ReaderRepository.Save(reader);
     return reader;
 }
 public override void Remove(Reader item)
 {
     readers.Remove(item);
 }
 public override IEnumerable<Order> GetOrdersByReader(Reader reader, bool closed)
 {
     return orders.Where(order => order.Reader.Id == reader.Id && order.Closed == closed);
 }
 public override IEnumerable<Order> GetOrdersByReader(Reader reader, bool closed)
 {
     return document.Root.Elements("Order")
         .Where(e => e.Element("ReaderId").Value == reader.Id.ToString() && Convert.ToBoolean(e.Element("Closed").Value) == closed)
         .Select(e => CreateItem(e));
 }
 public override IEnumerable<Order> GetOrdersByReader(Reader reader, 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[1] == reader.Id.ToString() && Convert.ToBoolean(arrayString[8]) == closed)
             {
                 yield return CreateItem(arrayString);
             }
         }
     }
 }
 public ReaderTest()
 {
     r1 = new Reader("Name1", "Address1");
     r2 = new Reader("Name2", "Address2");
     r3 = new Reader(r1.Id, "Name1", "Address1");
 }