Beispiel #1
0
        public async Task <IActionResult> FileUpload(IFormFile file, [Bind("id,name,text")] DocumentsIB documentsIB)
        {
            if (file != null && file.Length > 0)
            {
                var filePath   = @"\Upload\Files";
                var uploadPath = _env.WebRootPath + filePath;

                //Create
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }

                //Create Uniq file name
                var    uniqFileName = Guid.NewGuid().ToString();
                var    filename     = Path.GetFileName(uniqFileName + "." + file.FileName.Split(".")[1].ToLower());
                string fullPath     = uploadPath + filename;

                filePath = filePath + @"\";
                var filesPath = @".." + Path.Combine(filePath, filename);
                documentsIB.name = file.FileName;
                documentsIB.text = Url.Content(fullPath);
                _context.DocumentsIB.Add(documentsIB);
                _context.SaveChanges();
                using (var fileStream = new FileStream(fullPath, FileMode.Create))
                {
                    await file.CopyToAsync(fileStream);
                }


                ViewData["FileLocation"] = filePath;
            }
            return(View("../DocumentsIBs/Index", await _context.DocumentsIB.ToListAsync()));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("id,name,text")] DocumentsIB documentsIB)
        {
            if (id != documentsIB.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(documentsIB);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DocumentsIBExists(documentsIB.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(documentsIB));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("id,name,text")] DocumentsIB documentsIB)
        {
            if (ModelState.IsValid)
            {
                _context.Add(documentsIB);
                await _context.SaveChangesAsync();

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