예제 #1
0
        public static string GetUniqueName(UpdateBookVM bookVM)
        {
            var combinedInfo = (bookVM.Name + bookVM.AuthorFirstName + bookVM.AuthorLastName);
            var uniqueName   = combinedInfo.LettersOnly().ToUpper();

            return(uniqueName);
        }
예제 #2
0
        public Result <Book> Update(Guid id, [FromBody] UpdateBookVM updateBookVM)
        {
            updateBookVM.Id = id;
            var book = Mapper.Map <Book>(updateBookVM);

            return(_service.Update(book));
        }
        public IActionResult Update(Guid Id, [FromBody] UpdateBookVM updateBookVM)
        {
            updateBookVM.Id = Id;
            var book = _mapper.Map <Book>(updateBookVM);

            _service.Update(book);
            return(Ok(new Result {
                SuccessMessage = "Livro alterado com sucesso!"
            }));
        }
예제 #4
0
        public static Book UpdateFromVM(Book book, UpdateBookVM bookVM, Author author)
        {
            book.AmazonRating    = bookVM.AmazonRating;
            book.AmazonVotes     = bookVM.AmazonVotes;
            book.AuthorId        = author.AuthorId;
            book.GoodReadsRating = bookVM.GoodReadsRating;
            book.GoodReadsVotes  = bookVM.GoodReadsVotes;
            book.Name            = bookVM.Name;
            book.StatusId        = bookVM.StatusId;
            book.UniqueName      = GetUniqueName(bookVM);
            book.Year            = bookVM.Year;

            return(book);
        }
예제 #5
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);
            }
        }
예제 #6
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);
            }
        }
예제 #7
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));
            }
        }
예제 #8
0
        public static Book FromAddVM(UpdateBookVM bookVM, Author authorVM)
        {
            var uniqueName = GetUniqueName(bookVM);

            var book = new Book
            {
                DateAdded       = DateTime.Now,
                AmazonRating    = bookVM.AmazonRating,
                AmazonVotes     = bookVM.AmazonVotes,
                AuthorId        = authorVM.AuthorId,
                GoodReadsRating = bookVM.GoodReadsRating,
                GoodReadsVotes  = bookVM.GoodReadsVotes,
                Name            = bookVM.Name,
                StatusId        = bookVM.StatusId,
                UniqueName      = uniqueName,
                Year            = bookVM.Year
            };

            return(book);
        }
예제 #9
0
 public Book Post([FromBody] UpdateBookVM model)
 {
     return(BookRepository.AddUpdateBook(model));
 }
예제 #10
0
 public static UpdateBookVM UpdateFromDuplicate(UpdateBookVM update, Book duplicate)
 {
     update.BookId   = duplicate.BookId;
     update.StatusId = duplicate.StatusId;
     return(update);
 }