Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Guid,Title,FileType")] TestDocument testDocument)
        {
            if (ModelState.IsValid)
            {
                _context.Add(testDocument);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(testDocument));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(IFormFile file)
        {
            var fileName = file.FileName.Split(".");

            byte[] fileContent;
            using (var memoryStream = new MemoryStream())
            {
                await file.CopyToAsync(memoryStream);

                fileContent = memoryStream.ToArray();
            }
            var doc = new WordDocument()
            {
                Guid     = Guid.NewGuid(),
                Title    = fileName[0],
                FileType = "." + fileName[1],
                Content  = fileContent
            };
            await _context.WordDocument.AddAsync(doc);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }