static void InitData(Repository repository)
        {
            LibraryDepartment abonement = new LibraryDepartment("Абонемент", true);
            LibraryDepartment readingRoom = new LibraryDepartment("Читальный зал", false);
            repository.LibraryDepartmentRepository.Save(abonement);
            repository.LibraryDepartmentRepository.Save(readingRoom);

            repository.LibrarianRepository.Save(new Librarian("Мария Иванова", abonement));
            repository.LibrarianRepository.Save(new Librarian("Татьяна Петрова", readingRoom));

            repository.ReaderRepository.Save(new Reader("Иван Иванов", "Брест"));
            repository.ReaderRepository.Save(new Reader("Петр Петров", "Брест"));
            repository.ReaderRepository.Save(new Reader("Сидор Сидоров", "Брест"));

            repository.BookRepository.Save(new Book("Бен Ватсон", "С# 4.0 на примерах", 2000, abonement));
            repository.BookRepository.Save(new Book("Кристиан Нейгел", "C# 4.0 и платформа .NET 4", 2001, abonement));
            repository.BookRepository.Save(new Book("Михаил Фленов", "Библия C#", 2002, abonement));
            repository.BookRepository.Save(new Book("Чарльз Петцольд", "Программирование в тональности C#", 2003, abonement));
            repository.BookRepository.Save(new Book("Герберт Шилдт", "C# 4.0 полное руководство", 2004, abonement));
            repository.BookRepository.Save(new Book("Трей Нэш", "C# 2010. Ускоренный курс ", 2005, readingRoom));
            repository.BookRepository.Save(new Book("Мэтью Мак-Дональд", "Microsoft ASP.NET 3.5 с примерами", 2006, readingRoom));
            repository.BookRepository.Save(new Book("Чарльз Петцольд", "Программирование с использованием Windows Forms", 2007, readingRoom));
            repository.BookRepository.Save(new Book("Фаронов В.В.", "Программирование на языке С#", 2008, readingRoom));
            repository.BookRepository.Save(new Book("Либерти Дж.", "Программирование на C#", 2009, readingRoom));
        }
 public Book(Guid id, string author, string title, int year, LibraryDepartment department)
 {
     Id = id;
     Author = author;
     Title = title;
     Year = year;
     Department = department;
 }
 public Book(string author, string title, int year, LibraryDepartment department)
 {
     Id         = Guid.NewGuid();
     Author     = author;
     Title      = title;
     Year       = year;
     Department = department;
 }
 private static bool LibraryDepartmentCompare(LibraryDepartment a, LibraryDepartment b)
 {
     if (Object.ReferenceEquals(a, b))
     {
         return true;
     }
     return a.Id == b.Id && a.Name == b.Name;
 }
 private static bool LibraryDepartmentCompare(LibraryDepartment a, LibraryDepartment b)
 {
     if (Object.ReferenceEquals(a, b))
     {
         return(true);
     }
     return(a.Id == b.Id && a.Name == b.Name);
 }
 public Book(Guid id, string author, string title, int year, LibraryDepartment department)
 {
     Id         = id;
     Author     = author;
     Title      = title;
     Year       = year;
     Department = department;
 }
 public Book(string author, string title, int year, LibraryDepartment department)
 {
     Id = Guid.NewGuid();
     Author = author;
     Title = title;
     Year = year;
     Department = department;
 }
 public override void Save(LibraryDepartment item)
 {
     LibraryDepartment LibraryDepartment = GetItem(item.Id);
     if (LibraryDepartment != null)
     {
         LibraryDepartments[LibraryDepartments.IndexOf(LibraryDepartment)] = item;
     }
     else
     {
         LibraryDepartments.Add(item);
     }
 }
 public override IEnumerable<Book> GetBooksByDepartment(LibraryDepartment department)
 {
     using (BinaryReader binaryReader = new BinaryReader(File.Open(FileName, FileMode.Open), Encoding.Unicode))
     {
         while (binaryReader.PeekChar() != -1)
         {
             string[] arrayString = binaryReader.ReadString().Split('|');
             if (arrayString[4] == department.Id.ToString())
             {
                 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 override void Save(LibraryDepartment item)
 {
     XElement element = document.Root.Elements("Department").SingleOrDefault(e => e.Attribute("id").Value == item.Id.ToString());
     if (element != null)
     {
         element.Element("Name").Value = item.Name;
         element.Element("IsAbonement").Value = item.IsAbonement.ToString();
     }
     else
     {
         document.Root.Add(
             new XElement("Department",
                 new XAttribute("id", item.Id),
                 new XElement("Name", item.Name),
                 new XElement("IsAbonement", item.IsAbonement)));
     }
     document.Save(FileName);
 }
 public Librarian( Guid id, string fullName, LibraryDepartment department)
 {
     Id = id;
     FullName = fullName;
     Department = department;
 }
 public override void Save(LibraryDepartment 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.Name, item.IsAbonement.ToString()));
         str.Append("|");
         str.Length = MaxRecordStringLength;
         binaryWriter.Write(str.ToString());
     }
 }
 public override void Remove(LibraryDepartment item)
 {
     Remove(item.Id);
 }
 public Librarian(string fullName, LibraryDepartment department)
 {
     Id         = Guid.NewGuid();
     FullName   = fullName;
     Department = department;
 }
 public override IEnumerable<Book> GetBooksByDepartment(LibraryDepartment department)
 {
     return books.Where(book => book.Department.Id == department.Id);
 }
 public override IEnumerable<Book> GetBooksByDepartment(LibraryDepartment department)
 {
     return document.Root.Elements("Book")
         .Where(e => e.Element("DepartmentId").Value == department.Id.ToString())
         .Select(e => CreateItem(e));
 }
 public Librarian(string fullName, LibraryDepartment department)
 {
     Id = Guid.NewGuid();
     FullName = fullName;
     Department = department;
 }
 public IEnumerable<Book> GetBooksByDepartment(LibraryDepartment department)
 {
     return repository.BookRepository.GetBooksByDepartment(department);
 }
 public Librarian(Guid id, string fullName, LibraryDepartment department)
 {
     Id         = id;
     FullName   = fullName;
     Department = department;
 }
 public LibraryDepartmentTest()
 {
     ld1 = new LibraryDepartment("Name1", true);
     ld2 = new LibraryDepartment("Name2", false);
     ld3 = new LibraryDepartment(ld1.Id, "Name1", true);
 }
 public override void Remove(LibraryDepartment item)
 {
     LibraryDepartments.Remove(item);
 }