private void UpdateViewCount(int postId)
{
try
{
int? userId = null;
var username = User.Identity.IsAuthenticated ? User.Identity.Name : string.Empty;
if (!string.IsNullOrEmpty(username))
{
var user = _usersSvc.GetByUserName(username);
if (user != null && user.Error == null)
{
userId = user.Id;
}
}
var viewCount = new ViewCount
{
PostId = postId,
UserId = userId
};
_viewCountSvc.Add(viewCount);
}
catch (Exception ex)
{
_errorSignaler.SignalFromCurrentContext(ex);
}
}
}