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); }
public async Task <IActionResult> ImportBooks([FromBody] BookImportRequest request) { if (request == null) { return(BadRequest("Request missing")); } var result = await _importService.ImportBooksAsync(request); return(Json(result)); }