Ejemplo n.º 1
0
        public async Task <ImportResponse> ImportBooksAsync(BookImportRequest request)
        {
            ImportResponse response = await CheckRequest(request.UserID, request.Books.Count);

            if (!response.Successful)
            {
                return(response);
            }

            var user = await _userManager.FindByIdAsync(request.UserID);

            foreach (var book in request.Books)
            {
                try
                {
                    book.UserID  = request.UserID;
                    book.UserNum = user.UserNum;
                    book.ID      = 0;
                    _bookService.Add(book);
                    response.Imported++;
                }
                catch (Exception ex)
                {
                    response.Failed++;
                    response.Message += $"{book.Title} - {ex.Message} : {ex.InnerException?.Message}";
                }
            }

            response.Successful = true;

            return(response);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ImportBooks([FromBody] BookImportRequest request)
        {
            if (request == null)
            {
                return(BadRequest("Request missing"));
            }

            var result = await _importService.ImportBooksAsync(request);

            return(Json(result));
        }