Exemple #1
0
        public async Task <ActionResult <Book> > PostBooks(Book books)
        {
            _context.Books.Add(books);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBooks", new { id = books.BookId }, books));
        }
        public async Task <ActionResult <Book> > PostCategories(Category categories)
        {
            _context.Categories.Add(categories);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCategories", new { id = categories.CategoryId }, categories));
        }
        public async Task <ActionResult <BorrowRequest> > PostBorrowRequests(BorrowRequest borrowRequest)
        {
            if (_context.BorrowDetails.Count() > 5)
            {
                return(BadRequest("Khong the lay tren 5 quyen"));
            }

            _context.BorrowRequests.Add(borrowRequest);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBorrowRequests", new { id = borrowRequest.BorrowRequestId }, borrowRequest));
        }
Exemple #4
0
        public async System.Threading.Tasks.Task <ActionResult <User> > PostUser(User user)
        {
            if (!UserExists(user.UserId))
            {
                _context.Users.Add(user);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetUser", new { id = user.UserId }, user));
            }
            else
            {
                return(UnprocessableEntity());
            }
        }