private async Task HandleRemarkStatisticsAsync(T @event) { var remarkStatistics = await _remarkStatisticsRepository.GetAsync(@event.RemarkId); var remark = await _serviceClient.GetAsync <RemarkDto>(@event.Resource); if (remarkStatistics.HasNoValue) { remarkStatistics = new RemarkStatistics(@event.RemarkId, remark.Value.Category.Name, @event.UserId, remark.Value.Author.Name, remark.Value.CreatedAt, remark.Value.State.State, remark.Value.Location.Latitude, remark.Value.Location.Longitude, remark.Value.Location.Address, remark.Value.Description, remark.Value.Tags); } else { Location location = null; if (remark.Value.State.Location != null) { location = new Location(remark.Value.State.Location.Latitude, remark.Value.Location.Longitude, remark.Value.Location.Address); } remarkStatistics.Value.AddState(new RemarkState(remark.Value.State.State, @event.UserId, location: location)); } await _remarkStatisticsRepository.AddOrUpdateAsync(remarkStatistics.Value); }
public async Task AddOrUpdateAsync(RemarkStatistics statistics) => await _database.RemarkStatistics().AddOrUpdateAsync(statistics);
public static async Task AddOrUpdateAsync(this IMongoCollection <RemarkStatistics> statistics, RemarkStatistics value) => await statistics.ReplaceOneAsync(x => x.Id == value.Id, value, new UpdateOptions { IsUpsert = true });