Beispiel #1
0
        public AddGroupAssignments()
        {
            _group = new Group
            {
                Id = Guid.NewGuid()
            };
            _group.Users = new List <UserGroup>
            {
                new UserGroup
                {
                    UserId  = _user.Id,
                    GroupId = _group.Id,
                }
            };

            _request = new AssignGroupRequest
            {
                GroupId  = _group.Id,
                TaskId   = _task.Id,
                Deadline = DateTime.Now
            };
        }
Beispiel #2
0
        public async Task <IActionResult> AddGroupAssignments([FromRoute] Guid taskId, [FromBody] AssignGroupRequest request)
        {
            if (taskId != request.TaskId)
            {
                ModelState.AddModelError(nameof(taskId), "Task IDs do not match");
                return(BadRequest(ModelState));
            }

            var assignments = await _context.Groups.Include(g => g.Users)
                              .Where(g => g.Id == request.GroupId)
                              .SelectMany(g => g.Users
                                          .Select(u => new AssignmentRequest
            {
                UserId   = u.UserId,
                Deadline = request.Deadline
            }))
                              .ToArrayAsync();

            if (assignments.Length == 0)
            {
                ModelState.AddModelError(nameof(request.GroupId), "No users in group or group does not exist.");
                return(NotFound(ModelState));
            }

            return(await AddAssignments(taskId, assignments, false));
        }