Exemplo n.º 1
0
 public IActionResult Create(Book model, IFormFile photo)
 {
     if (ModelState.IsValid)
     {
         _book.Add(model, photo);
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Exemplo n.º 2
0
        public IHttpActionResult Add(Book Model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Data can not be saved"));
                }

                BookCategory _category = _bookCategoryRepository.Get(Model.CategoryId);
                if (_category == null)
                {
                    return(NotFound());
                }

                if (_bookRepository.AlreadyExists(Model.ISBN))
                {
                    return(BadRequest("ISBN already assigned to a book"));
                }

                string _message;
                if (!_bookRepository.ValidateInput(Model, out _message))
                {
                    return(BadRequest(_message));
                }

                _bookRepository.Add(Model);
                _bookRepository.Save();

                return(Ok("Record Saved"));
            }
            catch (Exception) { return(BadRequest("Record can not be saved")); }
        }
Exemplo n.º 3
0
 public IActionResult Create(Book newBook, IFormFile ImageUrl)
 {
     if (ImageUrl != null)
     {
         newBook.ImageUrl = "/images/assets/" + ImageUrl.FileName;
         var fileName = Path.Combine(he.WebRootPath + "/images/assets", Path.GetFileName(ImageUrl.FileName));
         ImageUrl.CopyTo(new FileStream(fileName, FileMode.Create));
     }
     _assets.Add(newBook);
     //return Content(mess);
     return(RedirectToAction("ListBook"));
 }
Exemplo n.º 4
0
        public IActionResult Post(Books books, string username, string password)
        {
            var admin = login.GetDetails(username, password);

            if (admin != null)
            {
                book.Add(books);
                book.Commit();
                return(Created("Book created", books));
            }
            else
            {
                return(NotFound("You are not an Admin"));
            }
        }
Exemplo n.º 5
0
        public IActionResult CreateBookByAdmin([FromBody] List <BookTest> book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            else
            {
                string Token = String.Empty;
                try
                {
                    Token = Request.Headers["Admin"];
                    if (Token == "1")
                    {
                        _logger.WriteActivity(book.ToString());
                        foreach (var item in book)
                        {
                            var newBook = new Books()
                            {
                                BookId             = Guid.NewGuid(),
                                Title              = item.Title,
                                Isbn               = item.Isbn,
                                PublishYear        = item.PublishYear,
                                CoverPrice         = item.CoverPrice,
                                AvailabilityStatus = "Check-In"
                            };

                            _book.Add(newBook);
                        }

                        return(Ok(book));
                    }
                    else
                    {
                        _logger.WriteActivity("Not Authorised");
                        return(Unauthorized());
                    }
                }
                catch (Exception ex)
                {
                    _logger.WriteLog(ex);
                    return(BadRequest());
                }
            }
        }
        public IActionResult Add(Book book)
        {
            Book newBook = new Book()
            {
                Title        = book.Title,
                Author       = book.Author,
                Description  = book.Description,
                Year         = book.Year,
                IsCheckouted = false
            };

            if (ModelState.IsValid)
            {
                _books.Add(newBook);
                return(RedirectToAction("Index"));
            }

            return(View(newBook));
        }
Exemplo n.º 7
0
        public async Task <BookListModel> AddBookToList(string bookId, int bookListId)
        {
            BookListModel bookList = await GetRaw(bookListId, true);

            if (bookList == null)
            {
                return(null);
            }

            BookModel book = await _book.Add(await _book.Get(bookId));

            if (book == null)
            {
                return(null);
            }

            if (bookList.Books.Select(b => b.Id).Contains(book.Id))
            {
                return(bookList);
            }


            BookListModel currentBookList = await _book.UserBookList(book.Id);

            if (currentBookList != null)
            {
                List <Book_BookListModel> book_bookList_list = currentBookList.Book_BookLists.Where(b => b.Book.Id == book.Id).ToList();
                _context.Remove(book_bookList_list.First());
            }

            bookList.Book_BookLists.Add(new Book_BookListModel()
            {
                Book     = book,
                BookList = bookList
            });

            _context.Update(bookList);
            await _context.SaveChangesAsync();

            return(bookList);
        }
Exemplo n.º 8
0
 public void Post([FromBody] Book book)
 {
     _book.Add(book);
 }
Exemplo n.º 9
0
 // POST api/<controller>
 public Book Post(Book book)
 {
     return(repositorydb.Add(book));
 }