Esempio n. 1
0
        public async Task <IActionResult> AddTeamMemberAsync([FromBody] AddTeamMemberRequest request)
        {
            await ValidateAccessToTeamAsync(request.TeamId);

            AppUserDTO newTeamMember = await users.GetUserAsync(request.User);

            await teamService.AddTeamMemberAsync(request.TeamId, newTeamMember.Id);

            return(Ok());
        }
        public async Task AddTeamMember(AddTeamMemberRequest addTeamMemberRequest)
        {
            var user = await dbcontext.Users.SingleOrDefaultAsync(u => u.Login == addTeamMemberRequest.Login);

            if (user == null)
            {
                throw new ArgumentException("User was not found");
            }

            var teamMember = new TeamMember
            {
                EditAccess = addTeamMemberRequest.HasEditAccess,
                Role       = addTeamMemberRequest.Role,
                StartupId  = addTeamMemberRequest.StartupId,
                UserId     = user.UserId
            };

            await dbcontext.TeamMembers.AddAsync(teamMember);

            await dbcontext.SaveChangesAsync();
        }
        public async Task <IActionResult> AddStartupTeamMembers(AddTeamMemberRequest addTeamMemberRequest)
        {
            try
            {
                int contextUserId = int.Parse(HttpContext.User.Identity.Name);

                var user = await userService.GetByIdAsync(contextUserId);

                if (!await userService.HasEditAccess(user.UserId, addTeamMemberRequest.StartupId))
                {
                    return(BadRequest(new { message = "Current user can't add team members" }));
                }

                await userService.AddTeamMember(addTeamMemberRequest);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }