public async Task <IActionResult> GetById(string id)
        {
            var track = await LibrivoxAPI.GetTrackLinks(id);

            if (track == null)
            {
                return(NotFound(id));
            }
            return(Ok(track));
        }
        public async Task <IActionResult> GetAsync(int limit, int offset)
        {
            try
            {
                var books = await LibrivoxAPI.GetBookList(limit, offset);

                return(Ok(books.Books));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
        public async Task <IActionResult> GetById(string id)
        {
            try
            {
                var book = await LibrivoxAPI.GetBook(id);

                if (book == null)
                {
                    return(NotFound(id));
                }
                return(Ok(book));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
        public async Task <IActionResult> Search(string searchTerm)
        {
            try
            {
                var books = await LibrivoxAPI.SearchBooks(searchTerm);

                if (books == null)
                {
                    return(NotFound(searchTerm));
                }

                return(Ok(books.Books));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
示例#5
0
        public async Task <IActionResult> AddListenedAsync(string Id)

        {
            try
            {
                var userId = HttpContext.User.Claims.ElementAt(0).Value;
                var user   = _db.Users
                             .Include(user => user.BooksListened)
                             .ThenInclude(book => book.Authors)
                             .SingleOrDefault(u => u.Email == userId);

                var book = await LibrivoxAPI.GetBook(Id);

                if (user == null || book == null)
                {
                    return(NotFound());
                }

                var bookExists = _db.Books.SingleOrDefault(b => b.Id == Id);
                if (bookExists == null)
                {
                    _db.Books.Add(book);
                }

                if (user.BooksListened.SingleOrDefault(b => b.Id == Id) == null)
                {
                    user.BooksListened.Add(book);
                }
                _db.SaveChanges();

                return(Ok(user));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }