private static bool LibrarianCompare(Librarian a, Librarian b)
 {
     if (Object.ReferenceEquals(a, b))
     {
         return true;
     }
     return a.Id == b.Id &&
         a.FullName == b.FullName &&
         a.Department == b.Department;
 }
 public override void Save(Librarian item)
 {
     Librarian Librarian = GetItem(item.Id);
     if (Librarian != null)
     {
         librarians[librarians.IndexOf(Librarian)] = item;
     }
     else
     {
         librarians.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 Save(Librarian item)
 {
     XElement element = document.Root.Elements("Librarian").SingleOrDefault(e => e.Attribute("id").Value == item.Id.ToString());
     if (element != null)
     {
         element.Element("FullName").Value = item.FullName;
         element.Element("DepartmentId").SetValue(item.Department.Id);
     }
     else
     {
         document.Root.Add(
             new XElement("Librarian",
                 new XAttribute("id", item.Id),
                 new XElement("FullName", item.FullName),
                 new XElement("DepartmentId", item.Department.Id)));
     }
     document.Save(FileName);
     libraryDepartmentRepository.Save(item.Department);
 }
 public override void Remove(Librarian item)
 {
     Remove(item.Id);
 }
 public LibrarianTest()
 {
     l1 = new Librarian("Name1", new LibraryDepartment("Абонемент", true));
     l2 = new Librarian("Name2", new LibraryDepartment("Читальный зал", false));
     l3 = new Librarian(l1.Id, l1.FullName, l1.Department);
 }
 public override void Remove(Librarian item)
 {
     librarians.Remove(item);
 }
 public override void Save(Librarian 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.Department.Id.ToString()));
         str.Append("|");
         str.Length = MaxRecordStringLength;
         binaryWriter.Write(str.ToString());
     }
     libraryDepartmentRepository.Save(item.Department);
 }