public async Task <IActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            BookModel book_retrieved = await _bookApiService.GetBook(id);

            if (book_retrieved == null)
            {
                return(NotFound());
            }

            BookIventoryCE_ViewModel book = new BookIventoryCE_ViewModel
            {
                id               = book_retrieved.id,
                book_name        = book_retrieved.book_name,
                genre            = book_retrieved.genre,
                author_name      = book_retrieved.author_name,
                publisher_name   = book_retrieved.publisher_name,
                publish_date     = book_retrieved.publish_date,
                language         = book_retrieved.language,
                edition          = book_retrieved.edition,
                book_cost        = book_retrieved.book_cost,
                no_of_pages      = book_retrieved.no_of_pages,
                book_description = book_retrieved.book_description,
                actual_stock     = book_retrieved.actual_stock,
                issued_books     = book_retrieved.issued_books,
                book_img         = book_retrieved.book_img,
            };

            return(View(book));
        }
        public async Task <IActionResult> Create(BookIventoryCE_ViewModel book)
        {
            if (ModelState.IsValid)
            {
                BookModel savebook = new BookModel
                {
                    id               = book.id,
                    book_name        = book.book_name,
                    genre            = book.genre,
                    author_name      = book.author_name,
                    publisher_name   = book.publisher_name,
                    publish_date     = book.publish_date,
                    language         = book.language,
                    edition          = book.edition,
                    book_cost        = book.book_cost,
                    no_of_pages      = book.no_of_pages,
                    book_description = book.book_description,
                    actual_stock     = book.actual_stock,
                    issued_books     = 0,
                    book_img         = UploadFile(book.book_pic)
                };
                await _bookApiService.CreateBook(savebook);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
        public async Task <IActionResult> Edit(string id, BookIventoryCE_ViewModel book)
        {
            if (id != book.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                BookModel savebook;
                if (book.book_pic != null)
                {
                    savebook = new BookModel
                    {
                        id               = book.id,
                        book_name        = book.book_name,
                        genre            = book.genre,
                        author_name      = book.author_name,
                        publisher_name   = book.publisher_name,
                        publish_date     = book.publish_date,
                        language         = book.language,
                        edition          = book.edition,
                        book_cost        = book.book_cost,
                        no_of_pages      = book.no_of_pages,
                        book_description = book.book_description,
                        actual_stock     = book.actual_stock,
                        book_img         = UploadFile(book.book_pic)
                    };
                }
                else
                {
                    savebook = new BookModel
                    {
                        id               = book.id,
                        book_name        = book.book_name,
                        genre            = book.genre,
                        author_name      = book.author_name,
                        publisher_name   = book.publisher_name,
                        publish_date     = book.publish_date,
                        language         = book.language,
                        edition          = book.edition,
                        book_cost        = book.book_cost,
                        no_of_pages      = book.no_of_pages,
                        book_description = book.book_description,
                        actual_stock     = book.actual_stock,
                    };
                }

                await _bookApiService.UpdateBook(savebook);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
Пример #4
0
 public async Task <IActionResult> Library_Borrow(string id, BookIventoryCE_ViewModel book)
 {
     return(View());
 }