public async Task <Study> UpdateMetadataAsync(int studyId, StudyUpdateDto updatedStudy, IFormFile logo = null)
        {
            if (studyId <= 0)
            {
                throw new ArgumentException("Study Id was zero or negative:" + studyId);
            }

            GenericNameValidation.ValidateName(updatedStudy.Name);

            var studyFromDb = await GetStudyForUpdateAsync(studyId, UserOperation.Study_Update_Metadata);

            if (updatedStudy.Name != studyFromDb.Name)
            {
                studyFromDb.Name = updatedStudy.Name;
            }

            if (updatedStudy.Description != studyFromDb.Description)
            {
                studyFromDb.Description = updatedStudy.Description;
            }

            if (updatedStudy.Vendor != studyFromDb.Vendor)
            {
                studyFromDb.Vendor = updatedStudy.Vendor;
            }

            if (updatedStudy.Restricted != studyFromDb.Restricted)
            {
                studyFromDb.Restricted = updatedStudy.Restricted;
            }

            if (updatedStudy.WbsCode != studyFromDb.WbsCode)
            {
                studyFromDb.WbsCode = updatedStudy.WbsCode;

                await _studyWbsValidationService.ValidateForStudyCreateOrUpdate(studyFromDb);
            }

            if (updatedStudy.DeleteLogo)
            {
                if (!String.IsNullOrWhiteSpace(studyFromDb.LogoUrl))
                {
                    studyFromDb.LogoUrl = "";
                    await _studyLogoDeleteService.DeleteAsync(_mapper.Map <Study>(updatedStudy));
                }
            }
            else if (logo != null)
            {
                studyFromDb.LogoUrl = await _studyLogoCreateService.CreateAsync(studyFromDb.Id, logo);
            }

            studyFromDb.Updated = DateTime.UtcNow;

            Validate(studyFromDb);

            await _db.SaveChangesAsync();

            return(studyFromDb);
        }
Beispiel #2
0
        public async Task <IActionResult> UpdateStudyDetailsAsync(int studyId,
                                                                  [ModelBinder(BinderType = typeof(JsonModelBinder))] StudyUpdateDto study,
                                                                  IFormFile image = null)
        {
            var updatedStudy = await _studyUpdateService.UpdateMetadataAsync(studyId, study, image);

            var studyDetails = await _studyDetailsService.Get(studyId);

            return(new JsonResult(studyDetails));
        }
Beispiel #3
0
        public async void UpdatingStudyDetailsWithoutRequiredFieldsShouldBeWellHandled(string name, string vendor)
        {
            await ClearTestDatabase();

            var studyCreateService = StudyServiceMockFactory.CreateService(_serviceProvider);

            var initialStudy = new StudyCreateDto()
            {
                Name   = "TestStudy12345",
                Vendor = "Equinor"
            };

            var createdStudy = await studyCreateService.CreateAsync(initialStudy);

            var studyWithoutReqFields = new StudyUpdateDto()
            {
                Name   = name,
                Vendor = vendor
            };

            var studyUpdateService = StudyServiceMockFactory.UpdateService(_serviceProvider);
            await Assert.ThrowsAsync <ArgumentException>(() => studyUpdateService.UpdateMetadataAsync(createdStudy.Id, studyWithoutReqFields));
        }