// Refusing proof public async Task RefuseReturningFromAdmin(string buildOnReturningId, string reason) { var buildOnReturning = await GetReturning(buildOnReturningId); if (buildOnReturning == null) { throw new Exception("It seems that the returning doesn't exist"); } Project project = await _projectsService.GetProjectFromIdAsync(buildOnReturning.ProjectId); if (project == null) { throw new Exception("The project doesn't exist"); } User builderUser = await _buildersService.GetUserFromAdminAsync(project.BuilderId); if (builderUser == null) { throw new Exception("Their is no user for this project..."); } var update = Builders <BuildOnReturning> .Update .Set(dbBuildOnReturnging => dbBuildOnReturnging.Status, BuildOnReturningStatus.Refused); await _buildOnReturnings.UpdateOneAsync(databaseBuildOnReturning => databaseBuildOnReturning.Id == buildOnReturningId, update ); await _notificationService.NotifyBuildOnReturningRefusedByAdmin(builderUser.Email, builderUser.FirstName, reason); }
public async Task <ActionResult <User> > GetUser(string builderId) { var currentUserId = User.Identity.Name; User user; try { if (User.IsInRole(Role.Admin)) { user = await _buildersService.GetUserFromAdminAsync(builderId); } else if (User.IsInRole(Role.Coach)) { user = await _buildersService.GetUserFromCoachAsync(currentUserId, builderId); } else if (User.IsInRole(Role.Builder)) { user = await _buildersService.GetUserFromBuilderAsync(currentUserId, builderId); } else { return(Forbid("You must be part of the Buildup program")); } } catch (UnauthorizedAccessException e) { return(Forbid($"You are not allowed to get this user: {e.Message}")); } catch (Exception e) { return(BadRequest($"Can't get the user: {e.Message}")); } if (user == null) { return(NotFound()); } return(Ok(user)); }