public async Task <BookmarkDto> GetAsync(Guid id) { var cacheKey = $"Bookmark@{id}"; async Task <BookmarkDto> GetBookmarkAsync() { var bookmark = await _bookmarkRepository.GetAsync(id); return(ObjectMapper.Map <Bookmark, BookmarkDto>(bookmark)); } //if (Debugger.IsAttached) //{ // return await GetBookmarkAsync(); //} return(await BookmarkCache.GetOrAddAsync( cacheKey, GetBookmarkAsync, () => new DistributedCacheEntryOptions { //TODO: Configurable? AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(6), SlidingExpiration = TimeSpan.FromMinutes(30) } )); }
public async Task <ValidationResult> DeleteAsync(int id) { if (id <= 0) { return(new ValidationResult(false, new ValidationError("The bookmark is invalid"))); } var bookmark = await _bookmarkRepository.GetAsync(id); if (bookmark == null) { return(new ValidationResult(false, new ValidationError("The bookmark wasn't found"))); } var bookmarkWasDeleted = await _bookmarkRepository.DeleteAsync(bookmark); if (!bookmarkWasDeleted) { return(new ValidationResult(false, new ValidationError("There was an error while deleting the bookmark"))); } return(new ValidationResult(true)); }
public async Task <string> Handle(UpsertBookmarkCommand request, CancellationToken cancellationToken) { //var bookmarks = await _mediator.Send(new GetBookmarkListQuery(), cancellationToken); Bookmark entity; if (string.IsNullOrEmpty(request.Id)) { entity = new Bookmark(request.Url, request.Title, "createdBy_bbe4k56sslf56jll43ls0", BookmarkContentType.Article, DetailType.Detailed, Identifier.New); } else { entity = await _bookmarkRepository.GetAsync(request.Id); entity.Title = request.Title; } request.Images?.ForEach(o => entity.AddImage(o.FileName, o.Url, o.BookmarkId, "createdBy_bbe4k56sslf56jll43ls0")); await _bookmarkRepository.UnitOfWork.SaveAsync(entity, cancellationToken); //await _mediator.Publish (new BookmarkCreated { BookmarkId = entity.Id }, cancellationToken); return(entity.Id); }