예제 #1
0
        /// <summary>
        /// Rename a node on the tree, either a new one created, or an existing one.
        /// </summary>
        /// <param name="key"> id of the folder, 0 for root, -1 for new folder</param>
        /// <param name="name">New folder name</param>
        /// <param name="parent">Id of the parent, used for creating new folders</param>
        /// <returns></returns>
        public ActionResult Rename(int key, string name, int?parent, int projectId)
        {
            if (!CanManageProject(projectId))
            {
                return(JsonNoPermissions());
            }

            ProjectDocumentDto document;

            if (key == -1)
            {
                var doc = new ProjectDocument
                {
                    Name             = name,
                    IsFolder         = true,
                    ParentDocumentId = parent,
                    ProjectId        = projectId
                };

                document = ProjectDocumentManager.Create(doc);
            }
            else
            {
                document = ProjectDocumentManager.Get(key);

                document.Entity.Name = name;

                ProjectDocumentManager.Update(document.Entity);
            }

            return(JsonSuccess(document));
        }
예제 #2
0
        public ActionResult DeleteDocument(int documentId, int projectId)
        {
            if (!CanManageProject(projectId))
            {
                return(JsonNoPermissions());
            }

            var documentDto = ProjectDocumentManager.Get(documentId);

            if (documentDto != null)
            {
                ProjectDocumentManager.Delete(documentId);

                return(JsonSuccess(new { id = documentId }));
            }

            return(JsonError("Unable to find file"));
        }
예제 #3
0
        public ActionResult DeleteFolder(int folderId, int projectId)
        {
            if (!CanManageProject(projectId))
            {
                return(JsonNoPermissions());
            }

            var documentDto = ProjectDocumentManager.Get(folderId);

            if (documentDto != null)
            {
                if (!documentDto.Entity.IsFolder)
                {
                    throw new ValidationException("Not a folder");
                }

                ProjectDocumentManager.Delete(folderId);

                return(JsonSuccess(new { id = folderId }));
            }

            return(JsonError("Unable to find folder"));
        }
예제 #4
0
        public ActionResult UploadFile(int?folderId, string qqfile, int?documentId, int projectId)
        {
            if (!CanManageProject(projectId))
            {
                return(JsonNoPermissions());
            }

            var attachment = documentId.HasValue ? ProjectDocumentManager.Get(documentId.Value).Entity : new ProjectDocument();

            if (String.IsNullOrEmpty(Request["qqfile"]) && Request.Files != null && Request.Files.Count > 0)
            {
                // IE
                qqfile = Request.Files[0].FileName;

                attachment.Name = qqfile;

                attachment.ProjectId = projectId;

                attachment.ContentLength = (int)Request.Files[0].InputStream.Length;

                attachment.ContentType = Request.Files[0].ContentType;

                attachment.Created = DateTime.UtcNow;

                var fileContent = new Byte[attachment.ContentLength];

                Request.Files[0].InputStream.Read(fileContent, 0, attachment.ContentLength);

                attachment.Data = fileContent;
            }
            else
            {
                attachment.ProjectId = projectId;

                attachment.ContentLength = (int)Request.InputStream.Length;

                attachment.ContentType = ContentHelper.GetFileContentType(FileHelper.GetFileExtension(qqfile));

                attachment.Name = qqfile;

                attachment.Created = DateTime.UtcNow;

                var fileContent = new Byte[attachment.ContentLength];

                Request.InputStream.Read(fileContent, 0, attachment.ContentLength);

                attachment.Data = fileContent;
            }

            if (string.IsNullOrEmpty(qqfile))
            {
                return(JsonError());
            }

            if (documentId.HasValue)
            {
                ProjectDocumentManager.Update(attachment);
            }
            else
            {
                var folder = ProjectDocumentManager.Get(folderId.Value);

                attachment.ParentDocumentId = folder.Entity.Id;

                ProjectDocumentManager.Create(attachment);
            }

            return(Json(new { success = true, fileId = attachment.Id, folderId = attachment.ParentDocumentId }, "text/html"));
        }