Exemplo n.º 1
0
        /// <summary>
        /// Добавляет бланк или пример заполнения
        /// </summary>
        /// <param name="documentSample"></param>
        /// <param name="uploadedFile"></param>
        /// <returns></returns>
        public async Task AddDocumentSampleAsync(DocumentSample documentSample, IFormFile uploadedFile)
        {
            if (uploadedFile != null)
            {
                var newFileModel = await _fileModelRepository.UploadFileAsync(uploadedFile, (FileDataTypeEnum)documentSample.FileDataTypeId);

                documentSample.FileModelId = newFileModel.Id;
            }

            _context.DocumentSamples.Add(documentSample);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Обновляет бланк или пример заполнения документа
        /// </summary>
        /// <param name="documentSample"></param>
        /// <param name="uploadedFile"></param>
        /// <returns></returns>
        public async Task UpdateDocumentSampleAsync(DocumentSample documentSample, IFormFile uploadedFile)
        {
            var entry = await GetDocumentSampleAsync(documentSample.DocumentSampleId);

            if (entry == null)
            {
                return;
            }

            entry.DocumentSampleName = documentSample.DocumentSampleName;
            entry.FileDataTypeId     = documentSample.FileDataTypeId;
            entry.IsBlank            = documentSample.IsBlank;
            entry.EduProfileId       = documentSample.EduProfileId;
            entry.Link = documentSample.Link;

            if (!string.IsNullOrWhiteSpace(documentSample.Link))
            {
                if (entry.FileModel != null)
                {
                    await _fileModelRepository.RemoveFileModelAsync(entry.FileModel);
                }
            }
            else
            {
                if (uploadedFile != null)
                {
                    if (entry.FileModel != null)
                    {
                        await _fileModelRepository.ReloadFileAsync(entry.FileModel, uploadedFile);
                    }
                    else
                    {
                        var newFileModel = await _fileModelRepository.UploadFileAsync(uploadedFile, (FileDataTypeEnum)entry.FileDataTypeId);

                        entry.FileModelId = newFileModel.Id;
                    }
                }
            }

            _context.DocumentSamples.Update(entry);
            await _context.SaveChangesAsync();
        }