/// <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)); }
public ActionResult LoadTree(int projectId) { if (!CanViewProject(projectId)) { return(JsonNoPermissions()); } var documents = ProjectDocumentManager.GetFolders(projectId); if (documents == null || documents.Count == 0) { var entity = new ProjectDocument { Name = GetResource(ResourceKeys.Documents), IsFolder = true, ProjectId = projectId }; documents.Add(ProjectDocumentManager.Create(entity)); } var result = documents.Select(document => new FolderItem(document)).ToList(); return(Content(result.ToJson(), "text/json")); }
public override WidgetResult Show(IssueDto args) { _projectManager = new ProjectManager(Cache, UserContext, GeminiContext); _projectDocumentManager = new ProjectDocumentManager(Cache, UserContext, GeminiContext); IssuesGridFilter tmp = new IssuesGridFilter(); HttpSessionManager HttpSessionManager = new HttpSessionManager(); var projects = new List <int>(); int selectedFolderKey = 0; // Safety check required because of http://gemini.countersoft.com/project/DEV/21/item/5088 try { if (CurrentCard.IsNew) { tmp = new IssuesGridFilter(HttpSessionManager.GetFilter(CurrentCard.Id, CurrentCard.Filter)); if (tmp == null) { tmp = CurrentCard.Options[AppGuid].FromJson <IssuesGridFilter>(); } projects = tmp.GetProjects(); } else { var cardOptions = CurrentCard.Options[AppGuid].FromJson <DocumentAppNavCard>(); projects.Add(cardOptions.projectId); selectedFolderKey = cardOptions.folderKey; } } catch (Exception ex) { tmp = new IssuesGridFilter(HttpSessionManager.GetFilter(CurrentCard.Id, IssuesFilter.CreateProjectFilter(UserContext.User.Entity.Id, UserContext.Project.Entity.Id))); projects = tmp.GetProjects(); } var activeProjects = _projectManager.GetActive(); var viewableProjects = new List <ProjectDto>(); int?currentProjectId = projects.Count > 0 ? projects.First() : 0; if (activeProjects == null || activeProjects.Count == 0) { activeProjects = new List <ProjectDto>(); } else { viewableProjects = ProjectManager.GetAppViewableProjects(this); } if (!viewableProjects.Any(s => s.Entity.Id == currentProjectId.Value)) { currentProjectId = viewableProjects.Count > 0 ? viewableProjects.First().Entity.Id : 0; } var model = new DocumentsModel { Projects = viewableProjects, FolderList = _projectDocumentManager.GetFolders(currentProjectId), MaxFileUpload = GeminiApp.Config.MaxFileUploadSizeBytes }; model.ProjectList = new SelectList(model.Projects, "Entity.Id", "Entity.Name", currentProjectId); model.Projects = viewableProjects; model.SelectedFolder = selectedFolderKey; model.HeaderText.Add(new HeaderTextItem(ResourceKeys.Documents)); if (!model.FolderList.Any() && currentProjectId > 0) { var entity = new ProjectDocument { Name = ResourceKeys.Documents, IsFolder = true, ProjectId = currentProjectId }; model.FolderList.Add(_projectDocumentManager.Create(entity)); } if (ProjectManager.GetAppEditableProjects(this).Count > 0) { ViewBag.EditPermission = true; } else { ViewBag.EditPermission = false; } WidgetResult result = new WidgetResult(); result.Markup = new WidgetMarkup("views\\Documents.cshtml", model); result.Success = true; return(result); }
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")); }