コード例 #1
0
 public Order(Reader reader, Book book)
     : this()
 {
     Id = Guid.NewGuid();
     Reader = reader;
     Book = book;
     if (book != null)
     {
         Department = book.Department;
     }
 }
コード例 #2
0
 public Order(Guid id, Reader reader, Book book)
     : this()
 {
     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)
     {
         context.Books.InsertOnSubmit(item);
     }
     else
     {
         book.Author = item.Author;
         book.Title = item.Title;
         book.Year = item.Year;
         book.Department = item.Department;
     }
     context.SubmitChanges();
 }
        public LibraryClassTest()
        {
            repository = new Repository(new MSSQLRepositoryFactory());

            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);
            book2 = new Book("Бен Ватсон", "С# 4.0 на примерах", 2000, department);
            repository.BookRepository.Save(book2);

            library = new LibraryClass(repository);
        }
        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.TimeReturnBook = 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 context.Orders.Where(order => order.Book.Id == book.Id && order.Closed == closed);
 }
 private void GetBook(Book book)
 {
     if (book == null) return;
     if (reader == null && !Authorization()) return;
     Console.Clear();
     Console.WriteLine(ConsoleResource.OrderBookTitle, book);
     if (library.OrderBook(book, reader))
     {
         Console.WriteLine(ConsoleResource.OrderSuccess);
     }
     else
     {
         Console.WriteLine(ConsoleResource.OrderWrong);
     }
     Console.ReadLine();
 }
コード例 #9
0
 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);
 }
		private void detach_Books(Book entity)
		{
			this.SendPropertyChanging();
			entity.Department = null;
		}
		private void attach_Books(Book entity)
		{
			this.SendPropertyChanging();
			entity.Department = this;
		}
 partial void DeleteBook(Book instance);
 partial void UpdateBook(Book instance);
 partial void InsertBook(Book instance);
 public override void Remove(Book item)
 {
     Remove(item.Id);
 }