private static void MapNewSearchCharacterDbModelList(this SearchTermDbModel searchTermDbModel) { var characters = searchTermDbModel.SearchTerm.Distinct().ToList(); searchTermDbModel.Characters = characters.ConvertAll(x => new SearchTermCharactersDbModel { Id = Guid.NewGuid(), Character = x, Count = searchTermDbModel.SearchTerm.Count(y => y == x) }); }
public static SearchDateDbModel MapNewSearchDateDbModel(this SearchTermDbModel searchTermDbModel) { if (string.IsNullOrWhiteSpace(searchTermDbModel.SearchTerm)) { return(null); } return(new SearchDateDbModel { Id = Guid.NewGuid(), SearchTermId = searchTermDbModel.Id, SearchDate = DateTime.UtcNow }); }
public static SearchTermStatisticsViewModel MapToViewModel(this SearchTermDbModel dbModel) { if (dbModel == null) { return(null); } return(new SearchTermStatisticsViewModel { Term = dbModel.SearchTerm, Length = dbModel.Length, TotalOcurrences = dbModel.SearchDates.Count, Characters = dbModel.Characters.ConvertAll(x => x.MapToViewModel()), FirstOccurence = dbModel.SearchDates.Min(x => x.SearchDate), LastOccurence = dbModel.SearchDates.Max(x => x.SearchDate) }); }
public static SearchTermDbModel MapToSearchTermDbModel(this string term) { if (string.IsNullOrWhiteSpace(term)) { return(null); } var model = new SearchTermDbModel { Id = Guid.NewGuid(), Length = term.Length, SearchTerm = term, SearchDates = new List <SearchDateDbModel>() }; model.MapNewSearchCharacterDbModelList(); model.SearchDates.Add(model.MapNewSearchDateDbModel()); return(model); }
private async Task UpdateSeachTerm(SearchTermDbModel model, CancellationToken cancellation) { var searchDateModel = model.MapNewSearchDateDbModel(); await _uow.StatisticRepository.AddSearchDate(searchDateModel, cancellation).ConfigureAwait(false); }
public async Task AddSearchTerm(SearchTermDbModel model, CancellationToken cancellation) { await _dbContext.SearchTerms.AddAsync(model, cancellation).ConfigureAwait(false); }