public async Task <IActionResult> Post(StatisticsRequest request) { if (request.PostId == Guid.Empty) { ModelState.AddModelError(nameof(request.PostId), "value is empty"); return(BadRequest(ModelState.CombineErrorMessages())); } if (DNT) { return(Ok()); } if (request.IsLike) { if (HasCookie(CookieNames.Liked, request.PostId.ToString())) { return(Conflict()); } } else { if (HasCookie(CookieNames.Hit, request.PostId.ToString())) { return(Ok()); } } await _statistics.UpdateStatisticAsync(request.PostId, request.IsLike? 1 : 0); SetPostTrackingCookie(request.IsLike ? CookieNames.Liked : CookieNames.Hit, request.PostId.ToString()); return(Ok()); }
public async Task <IActionResult> Post(StatisticsRequest request) { if (DNT) { return(NoContent()); } await _statistics.UpdateStatisticAsync(request.PostId, request.IsLike); return(NoContent()); }