Ejemplo n.º 1
0
        public async Task <ActionResult> ShareDocument(int id)
        {
            using (IntelliDocsEntities db = new IntelliDocsEntities())
            {
                Document doc = await db.Documents.FindAsync(id);

                List <Share> docShares =
                    await
                    db.Shares.Include(shr => shr.AspNetUsers)
                    .Where(shr => shr.Document_docId == doc.docId)
                    .ToListAsync();

                ViewBag.DocShares = docShares;

                return(PartialView(doc));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Upload(int dirId, string fileName, HttpPostedFileBase file)
        {
            if (string.IsNullOrEmpty(fileName)) return Json(new { status = "error", message = "A file name is required to upload." });
            if (file == null || file.ContentLength == 0) return Json(new { status = "error", message = "A file is required." });
            using (IntelliDocsEntities db = new IntelliDocsEntities())
            {
                Directory thisDirectory = db.Directories.Find(dirId);

                string extension = Path.GetExtension(file.FileName);

                Document newDoc = new Document()
                {
                    dirId = dirId,
                    docCreatedDate = DateTime.Now,
                    docName = fileName,
                    docExtension = extension,
                    docContentType = file.ContentType,
                    User_userId = User.Identity.GetUserId()
                };

                db.Documents.Add(newDoc);

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    return Json(new { status = "error", message = "Error uploading new Document: " + ex.Message });
                }

                string basePath = Path.Combine(Server.MapPath("~"), thisDirectory.Path);
                string fullFileName = newDoc.docId + newDoc.docExtension;
                if (!System.IO.Directory.Exists(basePath))
                {
                    System.IO.Directory.CreateDirectory(basePath);
                }
                file.SaveAs(Path.Combine(basePath, fullFileName));
            }

            return Json(new { status = "success", message = "The new Document was uploaded successfully." });
        }