public static List <WebsiteInfoDto> ToDtos(this IReadOnlyCollection <IHit <WebsiteInfo> > Hits) { var results = new List <WebsiteInfoDto>(); foreach (var hit in Hits) { var newResult = new WebsiteInfoDto { Id = hit.Source.Id, Title = hit.Source.Title, Url = hit.Source.Url, Language = hit.Source.Language, DescriptionMeta = hit.Source.DescriptionMeta, CreateDate = hit.Source.CreateDate, Paragraphs = hit.Source.Paragraphs, Highlights = new List <string>() }; if (hit.Highlights.Count > 0) { foreach (var highlight in hit.Highlights?.First().Value.Highlights?.ToList()) { newResult.Highlights.Add(highlight); } } results.Add(newResult); } return(results); }
public IActionResult CreateBookmark(WebsiteInfoDto payload) { var userId = Request.HttpContext.User.Claims.First(c => c.Type == "UserId").Value; var newBookmark = payload.ToEntity(userId); var context = new ApplicationDbContext(); context.Bookmarks.Add(newBookmark); context.SaveChanges(); return(Ok(new { Status = "Success" })); }
public static Bookmark ToEntity(this WebsiteInfoDto dto, string userId) { var entity = new Bookmark(); entity.Id = Guid.NewGuid().ToString(); entity.Language = dto.Language; entity.Title = dto.Title; entity.Url = dto.Url; entity.UserId = userId; entity.ElasticsearchId = dto.Id; entity.CreateDate = DateTime.Now; entity.Content = string.Join("\n", dto.Highlights); return(entity); }
public static WebsiteInfoDto ToDto(this Bookmark entity) { var result = new WebsiteInfoDto(); result.Id = entity.ElasticsearchId; result.Language = entity.Language; result.Title = entity.Title; result.Url = entity.Url; result.CreateDate = DateTime.Now; result.Highlights = new List <string>() { entity.Content }; return(result); }