public override void Save(Order item) { Order Order = GetItem(item.Id); if (Order != null) { orders[orders.IndexOf(Order)] = item; } else { orders.Add(item); } }
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 OrderTest() { o1 = new Order(new Reader("Name1", "Address1"), new Book("Author1", "Title1", 2000, new LibraryDepartment("Абонемент", true))); o2 = new Order(o1.Reader, o1.Book) { Closed = true }; o3 = new Order(o1.Id, o1.Reader, o1.Book); }
private static bool OrderCompare(Order a, Order b) { if (Object.ReferenceEquals(a, b)) { return true; } return a.Id == b.Id && a.Reader == b.Reader && a.Book == b.Book && a.TimeGetBook == b.TimeGetBook && a.LibrarianOpenOrder == b.LibrarianOpenOrder && a.TimeReturnBook == b.TimeReturnBook && a.LibrarianClosedOrder == b.LibrarianClosedOrder && a.Closed == b.Closed; }
public override void Remove(Order item) { orders.Remove(item); }
public override void Save(Order item) { XElement element = document.Root.Elements("Order").SingleOrDefault(e => e.Attribute("id").Value == item.Id.ToString()); if (element != null) { element.Element("ReaderId").SetValue(item.Reader.Id); element.Element("BookId").SetValue(item.Book.Id); element.Element("DepartmentId").SetValue(item.Department.Id); element.Element("TimeGetBook").SetValue(item.TimeGetBook); element.Element("LibrarianOpenOrderId").SetValue(item.LibrarianOpenOrder != null ? item.LibrarianOpenOrder.Id : Guid.Empty); element.Element("TimeReturnBook").SetValue(item.TimeReturnBook); element.Element("LibrarianClosedOrderId").SetValue(item.LibrarianClosedOrder != null ? item.LibrarianClosedOrder.Id : Guid.Empty); element.Element("Closed").SetValue(item.Closed); } else { document.Root.Add( new XElement("Order", new XAttribute("id", item.Id), new XElement("ReaderId", item.Reader.Id), new XElement("BookId", item.Book.Id), new XElement("DepartmentId", item.Department.Id), new XElement("TimeGetBook", item.TimeGetBook), new XElement("LibrarianOpenOrderId", item.LibrarianOpenOrder != null ? item.LibrarianOpenOrder.Id : Guid.Empty), new XElement("TimeReturnBook", item.TimeReturnBook), new XElement("LibrarianClosedOrderId", item.LibrarianClosedOrder != null ? item.LibrarianClosedOrder.Id : Guid.Empty), new XElement("Closed", item.Closed))); } document.Save(FileName); readerRepository.Save(item.Reader); bookRepository.Save(item.Book); if (item.LibrarianOpenOrder != null) librarianRepository.Save(item.LibrarianOpenOrder); if (item.LibrarianClosedOrder != null) librarianRepository.Save(item.LibrarianClosedOrder); }
public override void Remove(Order item) { Remove(item.Id); }
private Order CreateItem(XElement e) { Reader reader = readerRepository.GetItem(new Guid(e.Element("ReaderId").Value)); Book book = bookRepository.GetItem(new Guid(e.Element("BookId").Value)); Order order = new Order(new Guid(e.Attribute("id").Value), reader, book); order.TimeGetBook = Convert.ToDateTime(e.Element("TimeGetBook").Value); order.LibrarianOpenOrder = librarianRepository.GetItem(new Guid(e.Element("LibrarianOpenOrderId").Value)); order.TimeReturnBook = Convert.ToDateTime(e.Element("TimeReturnBook").Value); order.LibrarianClosedOrder = librarianRepository.GetItem(new Guid(e.Element("LibrarianClosedOrderId").Value)); order.Closed = Convert.ToBoolean(e.Element("Closed").Value); return order; }
private Order CreateItem(string[] arrayString) { Reader reader = readerRepository.GetItem(new Guid(arrayString[1])); Book book = bookRepository.GetItem(new Guid(arrayString[2])); Order order = new Order(new Guid(arrayString[0]), reader, book); order.TimeGetBook = Convert.ToDateTime(arrayString[4]); order.LibrarianOpenOrder = librarianRepository.GetItem(new Guid(arrayString[5])); order.TimeReturnBook = Convert.ToDateTime(arrayString[6]); order.LibrarianClosedOrder = librarianRepository.GetItem(new Guid(arrayString[7])); order.Closed = Convert.ToBoolean(arrayString[8]); return order; }
public override void Save(Order 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.Reader.Id.ToString(), item.Book.Id.ToString(), item.Department.Id.ToString(), item.TimeGetBook.ToString(), item.LibrarianOpenOrder != null ? item.LibrarianOpenOrder.Id.ToString() : Guid.Empty.ToString(), item.TimeReturnBook.ToString(), item.LibrarianClosedOrder != null ? item.LibrarianClosedOrder.Id.ToString() : Guid.Empty.ToString(), item.Closed.ToString())); str.Append("|"); str.Length = MaxRecordStringLength; binaryWriter.Write(str.ToString()); } readerRepository.Save(item.Reader); bookRepository.Save(item.Book); if (item.LibrarianOpenOrder != null) librarianRepository.Save(item.LibrarianOpenOrder); if (item.LibrarianClosedOrder != null) librarianRepository.Save(item.LibrarianClosedOrder); }