コード例 #1
0
        /// <summary>
        /// Добавляет к аннотации загруженный файл
        /// </summary>
        /// <param name="eduAnnotation"></param>
        /// <param name="uploadedFile"></param>
        /// <returns></returns>
        public async Task <EduAnnotation> UpdateEduAnnotationAsync(EduAnnotation eduAnnotation, IFormFile uploadedFile)
        {
            if (eduAnnotation == null || uploadedFile == null)
            {
                return(null);
            }
            FileModel fileModel = await _fileModelRepository.UploadEduAnnotationAsync(uploadedFile);

            if (eduAnnotation.FileModelId != 0)
            {
                await _fileModelRepository.RemoveFileAsync(eduAnnotation.FileModelId);
            }

            eduAnnotation.FileModel   = fileModel;
            eduAnnotation.FileModelId = fileModel.Id;

            if (eduAnnotation.EduAnnotationId == 0)
            {
                await _context.EduAnnotations.AddAsync(eduAnnotation);
            }

            await _context.SaveChangesAsync();

            return(eduAnnotation);
        }
コード例 #2
0
        /// <summary>
        /// Удаляет аннотацию
        /// </summary>
        /// <param name="eduAnnotation"></param>
        /// <returns></returns>
        public async Task RemoveEduAnnotationAsync(EduAnnotation eduAnnotation)
        {
            _context.EduAnnotations.Remove(eduAnnotation);
            await _fileModelRepository.RemoveFileAsync(eduAnnotation.FileModelId);

            await _context.SaveChangesAsync();
        }