示例#1
0
        public async Task <IActionResult> GetAllUploads(Guid taskId, string userId = null)
        {
            var user = await GetCurrentUser();

            if (!await _accessService.CanEdit(taskId, user))
            {
                return(Forbid());
            }

            if (user.Id != userId && !await _roleHelper.IsTeacher(user))
            {
                return(Forbid());
            }

            var uploads = _context.Uploads
                          .AsNoTracking()
                          .Where(u => u.TaskId == taskId && (userId == null || u.UserId == userId))
                          .OrderByDescending(u => u.UploadDate)
                          .Select(u => new LastUploadView
            {
                Id         = u.Id,
                Message    = u.Message,
                Status     = u.Status,
                Points     = u.Points,
                UploadDate = u.UploadDate,
                LanguageId = u.LanguageId
            }).ToList();

            foreach (var upload in uploads)
            {
                upload.Code = _uploadDataRepository.Get(upload.Id)?.Code;
            }

            return(Ok(uploads));
        }
示例#2
0
        public async Task <IActionResult> GetUsers([FromQuery] SieveModel sieveModel)
        {
            var user = await GetCurrentUser();

            if (!await _roleHelper.IsTeacher(user))
            {
                return(Forbid());
            }

            var users = _sieveProcessor.Apply(sieveModel, _context.Users);

            return(Ok(users.Select(u => new ProfileView
            {
                Id = u.Id,
                Email = u.Email,
                Name = u.Name,
                Surname = u.Surname,
                UserName = u.UserName
            })));
        }
 protected Task <bool> IsTeacher(ApplicationUser user) => _roleHelper.IsTeacher(user);