Exemplo n.º 1
0
 public void AddBook(Model.Book book)
 {
     using (LibDataContext lib = new LibDataContext(ConnectionString)) {
         lib.Books.InsertOnSubmit(new Book(book.IdNumber, (int)book.CatalogId, (int)book.ReaderId));
         lib.SubmitChanges();
     }
 }
Exemplo n.º 2
0
 public void DeleteBook(int bookId)
 {
     using (LibDataContext lib = new LibDataContext(ConnectionString)) {
         Book bookEntity = lib.Books.Where(b => b.IdNumber == bookId).FirstOrDefault();
         lib.Books.DeleteOnSubmit(bookEntity);
         lib.SubmitChanges();
     }
 }
Exemplo n.º 3
0
 public void DeleteReader(int readerId)
 {
     using (LibDataContext lib = new LibDataContext(ConnectionString)) {
         Reader readerEntity = lib.Readers.Where(r => r.Id == readerId).FirstOrDefault();
         lib.Readers.DeleteOnSubmit(readerEntity);
         lib.SubmitChanges();
     }
 }
Exemplo n.º 4
0
 public void DeleteCatalog(int catalogId)
 {
     using (LibDataContext lib = new LibDataContext(ConnectionString)) {
         Catalog catalogEntity = lib.Catalogs.Where(c => c.Id == catalogId).FirstOrDefault();
         lib.Catalogs.DeleteOnSubmit(catalogEntity);
         lib.SubmitChanges();
     }
 }
Exemplo n.º 5
0
 public void DeleteMaxBook()
 {
     using (LibDataContext lib = new LibDataContext(ConnectionString)) {
         int  maxId      = lib.Books.Max(b => b.IdNumber);
         Book bookEntity = lib.Books.Where(b => b.IdNumber == maxId).FirstOrDefault();
         lib.Books.DeleteOnSubmit(bookEntity);
         lib.SubmitChanges();
     }
 }
Exemplo n.º 6
0
 public void UpdateBook(Model.Book book)
 {
     using (LibDataContext lib = new LibDataContext(ConnectionString)) {
         Book bookEntity = lib.Books.Where(b => b.IdNumber == book.IdNumber).FirstOrDefault();
         bookEntity.CatalogId = book.CatalogId;
         bookEntity.ReaderId  = book.ReaderId;
         lib.SubmitChanges();
     }
 }
Exemplo n.º 7
0
 public void AddCatalog(Model.Catalog catalog)
 {
     using (LibDataContext lib = new LibDataContext(ConnectionString)) {
         ValidationResult authorValidation = varcharValidator.Validate(catalog.Author, null);
         if (!authorValidation.IsValid)
         {
             return;
         }
         ValidationResult titleValidation = varcharValidator.Validate(catalog.Title, null);
         if (!titleValidation.IsValid)
         {
             return;
         }
         lib.Catalogs.InsertOnSubmit(new Catalog(catalog.CatalogId, catalog.Author, catalog.Title));
         lib.SubmitChanges();
     }
 }
Exemplo n.º 8
0
 public void AddReader(Model.Reader reader)
 {
     using (LibDataContext lib = new LibDataContext(ConnectionString)) {
         ValidationResult firstNameValidation = varcharValidator.Validate(reader.FirstName, null);
         if (!firstNameValidation.IsValid)
         {
             return;
         }
         ValidationResult lastNameValidation = varcharValidator.Validate(reader.LastName, null);
         if (!lastNameValidation.IsValid)
         {
             return;
         }
         lib.Readers.InsertOnSubmit(new Reader(reader.Id, reader.FirstName, reader.LastName));
         lib.SubmitChanges();
     }
 }
Exemplo n.º 9
0
 public void UpdateCatalog(Model.Catalog catalog)
 {
     using (LibDataContext lib = new LibDataContext(ConnectionString)) {
         ValidationResult authorValidation = varcharValidator.Validate(catalog.Author, null);
         if (!authorValidation.IsValid)
         {
             return;
         }
         ValidationResult titleValidation = varcharValidator.Validate(catalog.Title, null);
         if (!titleValidation.IsValid)
         {
             return;
         }
         Catalog catalogEntity = lib.Catalogs.Where(c => c.Id == catalog.CatalogId).FirstOrDefault();
         catalogEntity.Author = catalog.Author;
         catalogEntity.Title  = catalog.Title;
         lib.SubmitChanges();
     }
 }
Exemplo n.º 10
0
 public void UpdateReader(Model.Reader reader)
 {
     using (LibDataContext lib = new LibDataContext(ConnectionString)) {
         ValidationResult firstNameValidation = varcharValidator.Validate(reader.FirstName, null);
         if (!firstNameValidation.IsValid)
         {
             return;
         }
         ValidationResult lastNameValidation = varcharValidator.Validate(reader.LastName, null);
         if (!lastNameValidation.IsValid)
         {
             return;
         }
         Reader readerEntity = lib.Readers.Where(r => r.Id == reader.Id).FirstOrDefault();
         readerEntity.FirstName = reader.FirstName;
         readerEntity.LastName  = reader.LastName;
         lib.SubmitChanges();
     }
 }
Exemplo n.º 11
0
        public void RentBook(string author, string title, int readerId)
        {
            using (LibDataContext lib = new LibDataContext(ConnectionString)) {
                Catalog catalogEntity = (from _catalog in lib.Catalogs
                                         where _catalog.Author == author && _catalog.Title == title
                                         select _catalog).SingleOrDefault();

                Reader readerEntity = lib.Readers.Where(r => r.Id == readerId).SingleOrDefault();

                if (catalogEntity != null && readerEntity != null)
                {
                    Book bookEntity = catalogEntity.Books.Where(b => b.ReaderId == null && b.CatalogId == catalogEntity.Id).FirstOrDefault();
                    if (bookEntity != null)
                    {
                        bookEntity.ReaderId = readerEntity.Id;
                        lib.SubmitChanges();
                    }
                }
            }
        }