Пример #1
0
        public async Task <IActionResult> CreateSandboxAsync(int studyId, SandboxCreateDto newSandbox)
        {
            var createdSandbox = await _sandboxService.CreateAsync(studyId, newSandbox);

            var sandboxDetails = await _sandboxService.GetSandboxDetailsAsync(createdSandbox.Id);

            return(new JsonResult(sandboxDetails));
        }
Пример #2
0
        public static void NewlyCreatedExpectSuccess(SandboxCreateDto createRequest, ApiResponseWrapper <SandboxDetails> responseWrapper)
        {
            ApiResponseBasicAsserts.ExpectSuccess <SandboxDetails>(responseWrapper);

            Assert.NotEqual <int>(0, responseWrapper.Content.Id);
            Assert.Equal(createRequest.Name, responseWrapper.Content.Name);
            Assert.Equal(createRequest.Region, responseWrapper.Content.Region);
        }
Пример #3
0
        static async Task <ApiConversation <SandboxCreateDto, TResponse> > Create <TResponse>(RestHelper restHelper, int studyId, string sandboxName = "sandboxName", string region = "norwayeast")
        {
            var request = new SandboxCreateDto()
            {
                Name = sandboxName, Region = region
            };
            var response = await restHelper.Post <TResponse, SandboxCreateDto>(String.Format(ApiUrls.STUDY_SANDBOXES, studyId), request);

            return(new ApiConversation <SandboxCreateDto, TResponse>(request, response));
        }
Пример #4
0
        public async Task <Sandbox> CreateAsync(int studyId, SandboxCreateDto sandboxCreateDto)
        {
            _logger.LogInformation(_sandboxCreateEventId, "Sandbox {0}: Starting", studyId);

            Sandbox createdSandbox;

            GenericNameValidation.ValidateName(sandboxCreateDto.Name);

            if (String.IsNullOrWhiteSpace(sandboxCreateDto.Region))
            {
                throw new ArgumentException("Region not specified.");
            }

            // Verify that study with that id exists
            var study = await _studyModelService.GetForSandboxCreateAndDeleteAsync(studyId, UserOperation.Study_Crud_Sandbox);

            await _studyWbsValidationService.ValidateForSandboxCreationOrThrow(study);

            //Check uniqueness of name
            if (await _sandboxModelService.NameIsTaken(studyId, sandboxCreateDto.Name))
            {
                throw new ArgumentException($"A Sandbox called {sandboxCreateDto.Name} allready exists for Study");
            }

            try
            {
                createdSandbox = await _sandboxModelService.AddAsync(study, _mapper.Map <Sandbox>(sandboxCreateDto));

                try
                {
                    await _sandboxResourceCreateService.CreateBasicSandboxResourcesAsync(createdSandbox);
                }
                catch (Exception)
                {
                    //Deleting sandbox entry and all related from DB
                    if (createdSandbox.Id > 0)
                    {
                        await _sandboxResourceDeleteService.UndoResourceCreationAsync(createdSandbox.Id);

                        await _sandboxModelService.HardDeleteAsync(createdSandbox.Id);
                    }

                    throw;
                }

                return(createdSandbox);
            }
            catch (Exception ex)
            {
                throw new Exception($"Sandbox creation failed: {ex.Message}", ex);
            }
        }