public async Task Increment(IEnumerable <long> advertIds, AdvertStatisticType type) { var paramsValues = new StringBuilder(); var adverts = advertIds.ToList(); if (adverts.Count == 0) { return; } for (var index = 1; index <= adverts.Count; index++) { paramsValues.Append("{"); paramsValues.Append(index); paramsValues.Append("}"); if (index != adverts.Count) { paramsValues.Append(","); } } var parameters = new List <object>() { (int)type }; parameters.AddRange(advertIds.Select(a => (object)a)); await _context.Database.ExecuteSqlRawAsync( @"UPDATE ""AdvertsStatistics"" SET ""Value"" = ""AdvertsStatistics"".""Value"" + 1 WHERE ""AdvertId"" in (" + paramsValues + @") and ""AdvertStatisticType"" = {0}", parameters); }
public Task IncrementAdvertsStats(long id, AdvertStatisticType statisticType) => _statisticRepository.Increment(id, statisticType);
public async Task <IActionResult> IncrementStatistic(long id, AdvertStatisticType statisticType) { await _service.IncrementAdvertsStats(id, statisticType); return(Ok()); }
public Task Increment(long advertId, AdvertStatisticType type) => _context.Database.ExecuteSqlInterpolatedAsync( $@"UPDATE ""AdvertsStatistics"" SET ""Value"" = ""AdvertsStatistics"".""Value"" + 1 WHERE ""AdvertId"" = {advertId} and ""AdvertStatisticType"" = {(int) type}");