示例#1
0
        public async Task <IActionResult> Post([FromBody] CreateProjectModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var project = new Project {
                        Name = model.ProjectName
                    };

                    var projectId = await _tenantRepository.AddProjectToTeam(project, TenantId); //you need to find team Id!!!!!!!!!!!!!!!!!!!!!!!!!!

                    var user = await _userService.GetCurrentUserAsync(TenantId);

                    await _tenantRepository.AddProjectUser(user.Id, projectId, TenantId, Role.SuperAdministrator);

                    return(Ok(new { id = projectId, project_name = model.ProjectName, users = new List <User> {
                                        user
                                    } }));
                }
                catch (Exception ex)
                {
                    return(BadRequest(new { ex.Message }));
                }
            }

            return(BadRequest(ModelState));
        }
示例#2
0
        public async Task <IActionResult> AddUserToProject(AddUserRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var projects = await _tenantRepository.GetUserProjects(model.Email, TenantId);

            if (projects != null && projects.Any())
            {
                return(BadRequest($"user {model.Email} already in project"));
            }
            var user = await _tenantRepository.GetUserByEmailAsync(model.Email, tenantId : TenantId);

            if (user == null)
            {
                return(BadRequest("this user does not exist on team"));
            }
            await _tenantRepository.AddProjectUser(user.Id, model.Id, TenantId, model.Role);

            return(new OkObjectResult(new { Message = $"User {model.Email} added to project {model.Id}" }));
        }