Example #1
0
        public async Task <bool> UpdateAsync(UpdateExaminationAudioFileInfoRequest request)
        {
            string oldFileName = string.Empty;

            var response = await transactionService.CommitAsync(new[] { TransactionContextScope.Main }, async() =>
            {
                var fileInfo = await questionAudioFilesRepository.GetAsync((long)request.Id);

                if (fileInfo.IsDeleted)
                {
                    return(false);
                }

                oldFileName = fileInfo.Name;

                if (await CheckAudioInfoForUpdate(fileInfo, request))
                {
                    if (fileInfo.Name != request.FileName)
                    {
                        var newFilePath = CreateFilePath(request.FileName);
                        File.Delete(newFilePath);
                        File.Move(fileInfo.Path, newFilePath);

                        fileInfo.Path = newFilePath;
                    }

                    fileInfo.Comment   = request.Comment;
                    fileInfo.Name      = request.FileName;
                    fileInfo.IsDeleted = request.IsDeleted;

                    await questionAudioFilesRepository.UpdateAsync(fileInfo);
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            if (response && oldFileName != request.FileName)
            {
                BackgroundJob.Enqueue <IExaminationIntegrationResponseService>(service => service.NotifyLocalInstancesAboutRenameAudioFile(request.FileName, oldFileName));
            }

            return(response);
        }
Example #2
0
        private async Task <bool> CheckAudioInfoForUpdate(QuestionAudioFile fileInfo, UpdateExaminationAudioFileInfoRequest request)
        {
            if (fileInfo == null)
            {
                return(false);
            }

            if (fileInfo.Name != request.FileName && await questionAudioFilesRepository.ExistsAsync(request.FileName))
            {
                return(false);
            }

            if (fileInfo.Id == request.Id && fileInfo.Name == request.FileName && fileInfo.Comment == request.Comment)
            {
                return(false);
            }

            return(true);
        }
 public async Task <bool> UpdateAudioFileInfo([FromBody] UpdateExaminationAudioFileInfoRequest request)
 => await examinationAudioService.UpdateAsync(request);