Esempio n. 1
0
        private async Task <IActionResult> AddUserToForm(AddUserRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var user = await _tenantRepository.GetUserByEmailAsync(model.Email, TenantId);

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

            if (form == null)
            {
                return(BadRequest("no forms with this Id exists!"));
            }
            var projects = await _tenantRepository.GetUserProjects(model.Email, tenantId : TenantId);

            if (!projects.Any(p => p.Forms.Contains(form)))
            {
                return(BadRequest("user does not have access to this project!"));
            }
            await _tenantRepository.AddUserToForm(user.Id, model.Id, TenantId, model.Role);

            return(Ok());
        }
Esempio n. 2
0
        public async Task <IActionResult> Post([FromBody] CreateFormModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var form = new Form {
                    Name = model.FormName, FormJson = model.FormJson.ToString(), Title = model.FormTitle
                };

                var formId = await _tenantRepository.AddFormToProject(form, model.ProjectId, TenantId);

                var user = await _userService.GetCurrentUserAsync(TenantId);

                await _tenantRepository.AddUserToForm(user.Id, formId, TenantId, Role.SuperAdministrator);

                return(Ok(new { id = formId, form_title = model.FormTitle }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { ex.Message }));
            }
        }