コード例 #1
0
        /// <summary>
        /// Добавляет файл в бд и в локальное хранилище
        /// </summary>
        /// <param name="fileModel"></param>
        /// <returns></returns>
        public async Task <Guid> AddAsync(FileModel fileModel)
        {
            if (fileModel == null)
            {
                throw new NullReferenceException("Файла для добавления нету.");
            }

            var result = new File(fileModel.TypeFile, fileModel.NameFile);
            await _context.Files.AddAsync(result);

            await _fileStore.Create(fileModel.StreamFile, result.FileId.ToString());

            await _context.SaveChangesAsync();

            return(result.FileId);
        }
コード例 #2
0
        public async Task <IActionResult> OnPost()
        {
            if (UploadedFile == null)
            {
                return(Page());
            }
            if (User == null)
            {
                throw new UnauthorizedAccessException();
            }
            var id = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (string.IsNullOrEmpty(id))
            {
                throw new UnauthorizedAccessException();
            }
            //bewust niet awaiten? laat maar gaan
            await _fileStore.Create(UploadedFile, id);

            await _videoEngine.Create(id);

            return(RedirectToPage("/Index"));
        }