Exemplo n.º 1
0
        public bool InsertLending(LendingModel lending)
        {
            try
            {
                var dbLending = new Lending()
                {
                    LendingDate = lending.LendingDate,
                    ReturnDate  = lending.ReturnDate,
                    BookId      = lending.BookId,
                    ClientId    = lending.ClientId,
                    LibraryId   = lending.LibraryId
                };

                db.Lendings.Add(dbLending);

                var bookCopy = db.BookCopies.FirstOrDefault(
                    x => x.BookId == lending.BookId &&
                    x.LibraryId == lending.LibraryId);

                bookCopy.NumberOfCopies = bookCopy.NumberOfCopies - 1;

                db.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool InsertLibrary(LibraryModel library)
        {
            try
            {
                var dbLibrary = new Library()
                {
                    Name    = library.Name,
                    City    = library.City,
                    Address = library.Address
                };

                db.Libraries.Add(dbLibrary);
                db.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public bool InsertPublisher(PublisherModel publisher)
        {
            try
            {
                var dbpublisher = new Publisher()
                {
                    Id      = publisher.Id,
                    Name    = publisher.Name,
                    Country = publisher.Country
                };

                db.Publishers.Add(dbpublisher);
                db.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        public bool InsertBookCopy(BookCopyModel bookCopy)
        {
            try
            {
                var dbBookCopy = new BookCopy()
                {
                    Id             = bookCopy.Id,
                    NumberOfCopies = bookCopy.NumberOfCopies,
                    BookId         = bookCopy.BookId,
                    LibraryId      = bookCopy.LibraryId
                };

                db.BookCopies.Add(dbBookCopy);
                db.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        public bool InsertBook(BookModel book)
        {
            try
            {
                var dbBook = new Book()
                {
                    Title         = book.Title,
                    YearOfIssue   = book.YearOfIssue,
                    NumberOfPages = book.NumberOfPages,
                    PublisherId   = book.PublisherId
                };

                db.Books.Add(dbBook);
                db.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        public bool InsertClient(ClientModel client)
        {
            try
            {
                var dbClient = new Client()
                {
                    Id      = client.Id,
                    Name    = client.Name,
                    Phone   = client.Phone,
                    City    = client.City,
                    Address = client.Address
                };

                db.Clients.Add(dbClient);
                db.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }