public async Task <GetMissingResponse <BookDto> > GetMissingBooks(GetMissingRequest request, string userIdentifier) { var missingBooks = await _context.UserBooks .AsNoTracking() .Where(ub => ub.UserIdentifier == userIdentifier) .Select(ub => ub.Book) .Include(b => b.Genre) .Include(b => b.Bookmarks) .Where(b => !request.IdList.Contains(b.BookId)) .ToListAsync(); var remoteDtoList = _mapper.Map <List <BookDto> >(missingBooks); var synchedIdList = await _context.UserBooks .AsNoTracking() .Where(ub => ub.UserIdentifier == userIdentifier) .Select(ub => ub.Book) .Where(b => request.IdList.Contains(b.BookId)) .Select(b => b.BookId) .ToListAsync(); var missingIdList = request.IdList.Where(id => !synchedIdList.Contains(id)).ToList(); var response = new GetMissingResponse <BookDto> { MissingIdList = missingIdList, RemoteDtoList = remoteDtoList }; return(response); }
public Task <GetMissingResponse <BookDto> > GetMissingBooks([FromBody] GetMissingRequest request) { //return _bookService.GetMissingBooks(request, UserId); #region tmp ki lesz veve return(_bookService.GetMissingBooks(request, request.UserIdentifier)); #endregion }
private async Task SyncBooksWithServer() { using (var client = new HttpClient()) { var localBookList = _database.SelectTable <ClientBookDto>(); var localBookIdList = localBookList.Select(lb => lb.BookId).ToList(); var request = new GetMissingRequest { IdList = localBookIdList, #region tmp ki lesz veve UserIdentifier = HbrApplication.UserIdentifier #endregion }; var result = await client.PostAsJsonAsync("https://hbr.azurewebsites.net/api/Book/GetMissingBooks", request); if (!result.IsSuccessStatusCode) { return; } var response = await result.Content.ReadAsAsync <GetMissingResponse <ClientBookDto> >(); _database.AddElements(response.RemoteDtoList); var booksToSend = localBookList .Where(lb => response.MissingIdList.Contains(lb.BookId)) .Select(lb => new AddOrEditBookRequest { BookId = lb.BookId, Author = lb.Author, AutoCompleteData = false, GenreId = lb.GenreId, Isbn = lb.Isbn, PageNumber = lb.PageNumber, Title = lb.Title, #region tmp ki lesz veve UserIdentifier = HbrApplication.UserIdentifier #endregion }).ToList(); result = await client.PostAsJsonAsync("https://hbr.azurewebsites.net/api/Book/bulkupdatebooks", booksToSend); } }
private async Task SyncBookmarksWithServer() { using (var client = new HttpClient()) { var localBookmarkList = _database.SelectTable <ClientBookmarkDto>(); var localBookmarkIdList = localBookmarkList.Select(lbm => lbm.BookmarkId).ToList(); var request = new GetMissingRequest { IdList = localBookmarkIdList, #region tmp ki lesz veve UserIdentifier = HbrApplication.UserIdentifier #endregion }; var result = await client.PostAsJsonAsync("https://hbr.azurewebsites.net/api/Bookmark/GetMissingBookmarks", request); if (!result.IsSuccessStatusCode) { return; } var response = await result.Content.ReadAsAsync <GetMissingResponse <ClientBookmarkDto> >(); _database.AddElements(response.RemoteDtoList); var bookmarksToSend = localBookmarkList .Where(lbm => response.MissingIdList.Contains(lbm.BookmarkId)) .Select(lbm => new AddBookmarkRequest { BookId = lbm.BookId, BookmarkId = lbm.BookmarkId, PageNumber = lbm.PageNumber, #region tmp ki lesz veve UserIdentifier = HbrApplication.UserIdentifier #endregion }).ToList(); await client.PostAsJsonAsync("https://hbr.azurewebsites.net/api/Book/BulkUpdateBooks", bookmarksToSend); } }