Exemple #1
0
        public async Task <IActionResult> Confirm(CodeTaskResultDto model)
        {
            var userId = User.FindFirstValue("sub");
            await _codeTaskResultService.Confirm(userId, model);

            return(Ok(new { }));
        }
Exemple #2
0
        public async Task Confirm(string userId, CodeTaskResultDto model)
        {
            var user = await _context.Users
                       .Include(x => x.UserGroups)
                       .ThenInclude(x => x.Group)
                       .FirstOrDefaultAsync(x => x.Id == userId);

            var result = new CodeTaskResult
            {
                Code     = model.Code,
                Group    = user.UserGroups != null && user.UserGroups.Count > 0 ? user.UserGroups[0].Group : null,
                CodeTask = await _context.CodeTasks.FindAsync(model.CodeTaskId),
                Sender   = user
            };

            if (result.Sender == null || result.CodeTask == null)
            {
                throw new ArgumentException();
            }

            _context.CodeTaskResults.Add(result);
            await _context.SaveChangesAsync();
        }