Exemplo n.º 1
0
        /// <summary>
        /// Alter the upvote value for an upload.
        /// </summary>
        /// <param name="votevalue">The value going to be added to the current upvote value. Can be negative.</param>
        /// <param name="uploadId">Id of upload used for searching.</param>
        /// <param name="failurecount">Current number of times operation has failed.</param>
        /// <param name="username">Username of person requesting operation for logging.</param>
        /// <param name="ipAddress">IP address of system requesting operation for logging.</param>
        /// <returns>A boolean for the successful completion of the operation. </returns>
        public async Task <bool> EditUpvotesonUpload(int votevalue, int uploadId, int failurecount, string username, string ipAddress)
        {
            try
            {
                bool result = await _uploadService.IncrementUpvotesonUpload(votevalue, uploadId).ConfigureAwait(false);

                _ = _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString),
                                             Constants.UpvoteOperation + "/" + uploadId, username, ipAddress).ConfigureAwait(false);

                return(result);
            }
            catch (Exception e)
            {
                _ = _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString),
                                             Constants.UpvoteOperation + "/" + uploadId, username, ipAddress).ConfigureAwait(false);
                failurecount += 1;

                if (failurecount >= Constants.LoggingRetriesAmount)
                {
                    throw e;
                }
                else
                {
                    return(await EditUpvotesonUpload(votevalue, uploadId, failurecount, username, ipAddress).ConfigureAwait(false));
                }
            }
        }