Ejemplo n.º 1
0
        public static BookGridModel ToBookGridModel(this Book book)
        {
            var resultBook = new BookGridModel
            {
                PageCount      = book.PageCount,
                Title          = book.Title,
                Status         = book.Status,
                AdditionalInfo = book.AdditionalInfo,
                Bookshelf      = book.Bookshelf,
                FlibustaUrl    = book.FlibustaUrl,
                LibRusEcUrl    = book.LibRusEcUrl,
                LiveLibUrl     = book.LiveLibUrl,
                Owner          = book.Owner,
                Year           = book.Year,
                ImageUrl       = book.ImageUrl,
                Id             = book.Id,
            };

            foreach (var author in book.Authors)
            {
                resultBook.Authors.Add(author.ToAuthorGridModel());
            }

            return(resultBook);
        }
Ejemplo n.º 2
0
        public ActionResult Edit([DataSourceRequest]DataSourceRequest request, BookGridModel book)
        {
            if (ModelState.IsValid)
            {
                var bookCategory = this.CategoryService.GetByIName(book.CategoryName);
                var bookToUpdate = this.BookService.GetById(book.Id);

                if (bookToUpdate.Category.Name != book.CategoryName)
                {

                    bookToUpdate.Category = bookCategory;
                }

                UpdateBookFields(book, bookToUpdate);

                this.BookService.Update(bookToUpdate);
            }
            return Json(new[] { book }.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 3
0
        public ActionResult Create([DataSourceRequest]DataSourceRequest request, BookGridModel book)
        {
            if (ModelState.IsValid)
            {

                Book newBook = new Book()
                {
                    Description = book.Description,
                    Author = book.Author,
                    ISBN = book.ISBN,
                    Title = book.Title,
                    Website = book.Website
                };

                this.BookService.Create(newBook);

                book.Id = newBook.Id;
            }

            return Json(new[] { book }.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 4
0
        public static Book ToBook(this BookGridModel bookGridModel)
        {
            var book = new Book(bookGridModel.Title, bookGridModel.PageCount, bookGridModel.Status)
            {
                AdditionalInfo =
                    bookGridModel
                    .AdditionalInfo,
                Bookshelf =
                    bookGridModel
                    .Bookshelf,
                FlibustaUrl =
                    bookGridModel
                    .FlibustaUrl,
                LibRusEcUrl =
                    bookGridModel
                    .LibRusEcUrl,
                LiveLibUrl =
                    bookGridModel
                    .LiveLibUrl,
                Owner =
                    bookGridModel
                    .Owner,
                Year =
                    bookGridModel
                    .Year,
                ImageUrl =
                    bookGridModel
                    .ImageUrl,
                Id =
                    bookGridModel
                    .Id,
            };

            foreach (var author in bookGridModel.Authors)
            {
                book.Authors.Add(author.ToAuthor());
            }

            return(book);
        }
Ejemplo n.º 5
0
 private static void UpdateBookFields(BookGridModel book, Book oldBook)
 {
     oldBook.Author = book.Author;
     oldBook.Description = book.Description;
     oldBook.ISBN = book.ISBN;
     oldBook.Title = book.Title;
     oldBook.Website = book.Website;
 }