Exemplo n.º 1
0
        /// <summary>
        /// Uploads a number of tips used by a candidate.
        /// </summary>
        /// <param name="taskId">An id of a task.</param>
        /// <param name="usedTipsNumber">A number of used tips.</param>
        /// <param name="userId">An id of a candidate.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public Task UploadTipsNumber(int taskId, int usedTipsNumber, Guid userId)
        {
            string cadidateCode        = string.Empty;
            CandidateTaskResult result = CreateCandidateTaskResult(cadidateCode, taskId, userId, usedTipsNumber);

            result.Score = 0;
            return(UpdateCandidateTaskResultAsync(result));
        }
Exemplo n.º 2
0
 private static void UpdateResult(CandidateTaskResult previousResult, CandidateTaskResult currentTaskResult)
 {
     previousResult.Code = currentTaskResult.Code;
     previousResult.CandidateExerciseId = currentTaskResult.CandidateExerciseId;
     previousResult.CreatorId           = currentTaskResult.CreatorId;
     previousResult.ModifierId          = currentTaskResult.ModifierId;
     previousResult.UsedTipsNumber      = currentTaskResult.UsedTipsNumber;
     previousResult.Score       = currentTaskResult.Score;
     previousResult.IsCompleted = currentTaskResult.IsCompleted;
     previousResult.EndDate     = currentTaskResult.EndDate;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Create task result.
        /// </summary>
        /// <param name="taskId">An id of a task.</param>
        /// <param name="startDate">Task start date.</param>
        /// <param name="userId">An id of a candidate.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public Task CreateCandidateTaskResultAsync(int taskId, DateTime startDate, Guid userId)
        {
            CandidateTaskResult currentTaskResult = CreateCandidateTaskResult(null, taskId, userId, 0, startDate);

            CandidateTaskResult previousResult = _context.CandidateTaskResults.FirstOrDefault(result => result.ModifierId == currentTaskResult.ModifierId && result.CandidateExerciseId == currentTaskResult.CandidateExerciseId);

            if (previousResult != null)
            {
                throw new TaskResultAlreadyExistsException();
            }

            return(SaveCandidateTaskResultAsync(currentTaskResult));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates task result.
        /// </summary>
        /// <param name="currentTaskResult">A candidates' current result.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public Task UpdateCandidateTaskResultAsync(CandidateTaskResult currentTaskResult)
        {
            if (currentTaskResult == null)
            {
                throw new ArgumentNullException(nameof(currentTaskResult));
            }

            CandidateTaskResult previousResult = _context.CandidateTaskResults.FirstOrDefault(result => result.ModifierId == currentTaskResult.ModifierId && result.CandidateExerciseId == currentTaskResult.CandidateExerciseId);

            if (previousResult == null)
            {
                return(SaveCandidateTaskResultAsync(currentTaskResult));
            }

            UpdateResult(previousResult, currentTaskResult);

            return(_context.SaveChangesAsync());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates an instance of <see cref="CandidateTaskResult"/>
        /// </summary>
        /// <param name="candidateCode">A code of a candidate.</param>
        /// <param name="taskId">An id of a task made by a candidate.</param>
        /// <param name="userId">An id of a candidate.</param>
        /// <param name="usedTipsNumber">A number of tips used by a candidate.</param>
        /// <param name="startDate">Task start date.</param>
        /// <param name="endDate">Task end date.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        private static CandidateTaskResult CreateCandidateTaskResult(
            string candidateCode, int taskId, Guid userId, int usedTipsNumber, DateTime?startDate = null, DateTime?endDate = null)
        {
            var candidatesResult = new CandidateTaskResult
            {
                Code = candidateCode,
                CandidateExerciseId = taskId,
                CreatorId           = userId,
                ModifierId          = userId,
                UsedTipsNumber      = usedTipsNumber,
                Score       = 0,
                IsCompleted = false,
                StartDate   = startDate,
                EndDate     = endDate
            };

            return(candidatesResult);
        }
Exemplo n.º 6
0
 private Task SaveCandidateTaskResultAsync(CandidateTaskResult candidatesResult)
 {
     _context.CandidateTaskResults.Add(candidatesResult);
     return(_context.SaveChangesAsync());
 }