Exemplo n.º 1
0
        public async Task<IActionResult> UploadFiles(IList<IFormFile> file, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            foreach (var f in file)
            {
                if (f.Length <= 0) continue;

                byte[] fileContent;
                using (var memStream = new MemoryStream())
                {
                    await f.CopyToAsync(memStream, cancellationToken);
                    if (cancellationToken.IsCancellationRequested)
                        return new EmptyResult();
                    fileContent = memStream.ToArray();
                }

                var item = new Domain.Core.File
                {
                    Name = f.FileName,
                    Extension = f.ContentType,
                    FileContent = fileContent
                };
                await _fileRepository.CreateAsync(item);
            }

            return new StatusCodeResult(200);
        }
Exemplo n.º 2
0
 public void Create(Domain.Core.File file)
 {
     context.Files.Add(file);
 }
Exemplo n.º 3
0
 public void Update(Domain.Core.File file)
 {
     context.Entry(file).State = EntityState.Modified;
 }