示例#1
0
        public static Book UpdateBookStatus(UpdateBookStatusVM bookVM)
        {
            using (var db = new AppDbContext())
            {
                var book = db.Books.Find(bookVM.BookId);

                book = BookMappers.UpdateFromStatusVM(book, bookVM);

                db.Books.Update(book);
                db.SaveChanges();

                return(book);
            }
        }
示例#2
0
        public static Book AddBook(UpdateBookVM bookVM)
        {
            using (var db = new AppDbContext())
            {
                var author = AuthorRepository.GetAddAuthor(bookVM.AuthorFirstName, bookVM.AuthorLastName);

                var book = BookMappers.FromAddVM(bookVM, author);

                db.Add(book);
                db.SaveChanges();

                return(book);
            }
        }
示例#3
0
        public static Book UpdateBook(UpdateBookVM bookVM)
        {
            using (var db = new AppDbContext())
            {
                var book = db.Books.Find(bookVM.BookId);

                var authorVM = AuthorRepository.GetAddAuthor(bookVM.AuthorFirstName, bookVM.AuthorLastName);

                book = BookMappers.UpdateFromVM(book, bookVM, authorVM);

                db.Books.Update(book);
                db.SaveChanges();

                return(book);
            }
        }
示例#4
0
        public static Book AddUpdateBook(UpdateBookVM book)
        {
            if (book.BookId > 0)
            {
                return(UpdateBook(book));
            }

            var duplicate = GetByUniqueName(BookMappers.GetUniqueName(book));

            if (duplicate != null)
            {
                book = BookMappers.UpdateFromDuplicate(book, duplicate);
                return(UpdateBook(book));
            }
            else
            {
                return(AddBook(book));
            }
        }