Пример #1
0
        public ActionResult UploadToTask(int ProjectID, int?TaskID, string TaskName)
        {
            BuildingEntities db   = (BuildingEntities)this.db;
            User             user = HttpContext.CurrentUser();

            if (Request.Files.Count < 1)
            {
                return(Json(new { Code = 202, Success = false, Message = "No files uploaded!" }));
            }

            Project project = db.Projects.FirstOrDefault(val => val.ID == ProjectID);

            if (project == null)
            {
                return(Json(new { Code = 202, Success = false, Message = "Project not found!" }));
            }

            CheckPermissionsEventArgs e = new CheckPermissionsEventArgs(db, "Projects", "Project", project, EntityJs.Client.Events.ActionsEnum.Select);

            project.OnCheckPermissions(e);
            if (e.Cancel)
            {
                return(Json(new { Code = 202, Success = false, Message = "You can't operate with this project!" }));
            }

            ProjectTask task = null;

            if (TaskID > 0)
            {
                task = db.ProjectTasks.FirstOrDefault(val => val.ID == TaskID);
                if (task == null)
                {
                    return(Json(new { Code = 202, Success = false, Message = "Task not found!" }));
                }

                e = new CheckPermissionsEventArgs(db, "ProjectTasks", "ProjectTask", task, EntityJs.Client.Events.ActionsEnum.Edit);
                task.OnCheckPermissions(e);
                if (e.Cancel)
                {
                    return(Json(new { Code = 202, Success = false, Message = "You can't edit this task!" }));
                }
            }

            int              code;
            string           message;
            UploadFileHelper helper = new UploadFileHelper(this.db as BuildingEntities);

            Folder folder = helper.GetFolder(project, TaskName, true);

            Models.File        file  = helper.UploadFiles(-1, folder.ID, out code, out message, false);
            Models.ProjectFile pfile = file != null?file.ProjectFiles.FirstOrDefault(val => val.ProjectID == ProjectID) : null;

            if (pfile != null)
            {
                pfile.ProjectTask = task;
                db.SaveChanges();
            }
            var data = new { Code = code, Message = message, File = file != null?file.ToJson() : null, ProjectFile = pfile != null?pfile.ToJson() : null };

            return(this.Json(data));
        }