Esempio n. 1
0
        public async Task <IActionResult> GetUserRoles(string projectId)
        {
            var ids = _context.UserProjectRole.Where(x => x.ProjectId == Convert.ToInt32(projectId))
                      .Select(x => new { x.UserId, x.ScrumRolesId }).ToArray();

            UserRoleToReturnDto[] str = new UserRoleToReturnDto[ids.Length];
            int i = 0;

            foreach (var item in ids)
            {
                var user = await _context.Users.Where(x => x.Id == item.UserId)
                           .Select(x => new { x.FirstName, x.LastName, x.Id }).FirstOrDefaultAsync();

                var roleName = await _context.ScrumRoles.Where(x => x.Id == item.ScrumRolesId)
                               .Select(x => new { x.ScrumRoleName, x.Id }).FirstOrDefaultAsync();

                UserRoleToReturnDto dto = new UserRoleToReturnDto()
                {
                    UserId    = user.Id,
                    FirstName = user.FirstName,
                    LastName  = user.LastName,
                    RoleId    = roleName.Id,
                    RoleName  = roleName.ScrumRoleName
                };
                str[i] = dto;
                i++;
            }
            return(Ok(str));
        }
Esempio n. 2
0
        public async Task <IActionResult> RemoveRole(string projectId, UserRoleToReturnDto InDto)
        {
            var roleToDelete = await _context.UserProjectRole
                               .Where(x => x.ProjectId == Convert.ToInt32(projectId) &&
                                      x.ScrumRolesId == InDto.RoleId && x.UserId == InDto.UserId)
                               .FirstOrDefaultAsync();

            _context.UserProjectRole.Remove(roleToDelete);
            await _context.SaveChangesAsync();

            return(Ok());
        }