Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Guid,Title,FileType")] TestDocument testDocument)
        {
            if (id != testDocument.Guid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(testDocument);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TestDocumentExists(testDocument.Guid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(testDocument));
        }
Пример #2
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Guid")] WordDocument wordDocument, IFormFile file)
        {
            if (id != wordDocument.Guid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var    fileName = file.FileName.Split(".");
                    byte[] fileContent;
                    using (var memoryStream = new MemoryStream())
                    {
                        await file.CopyToAsync(memoryStream);

                        fileContent = memoryStream.ToArray();
                    }
                    wordDocument.Title    = fileName[0];
                    wordDocument.FileType = "." + fileName[1];
                    wordDocument.Content  = fileContent;
                    _context.Update(wordDocument);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WordDocumentExists(wordDocument.Guid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(wordDocument));
        }