public virtual ActionResult CreateNew(HiveId? id) { if (id.IsNullValueOrEmpty()) return HttpNotFound(); var currentFolderPath = "/"; if (id != FixedHiveIds.SystemRoot) { using (var uow = Hive.Create()) { var parentFile = uow.Repositories.Get<File>(id.Value); if (parentFile == null) throw new ArgumentException("No folder could be found for the id specified"); currentFolderPath = "/" + parentFile.GetFilePathForDisplay(); } } var model = new CreateFileModel { ParentId = id.Value, CurrentFolderPath = currentFolderPath }; EnsureViewData(model); return View(model); }
protected override void OnBeforeCreate(CreateFileModel createModel, FileEditorModel editorModel) { createModel.ParentId = editorModel.ParentId = FixedHiveIds.SystemRoot; }
public virtual ActionResult CreateNewForm(CreateFileModel createModel) { Mandate.ParameterNotNull(createModel, "createModel"); Mandate.That<NullReferenceException>(createModel.Name != null); Mandate.That<NullReferenceException>(!createModel.ParentId.IsNullValueOrEmpty()); EnsureViewData(createModel); //validate the model if (!TryUpdateModel(createModel)) { return View(createModel); } using (var uow = Hive.Create()) { if (createModel.ParentId != FixedHiveIds.SystemRoot) { //validate the parent var parentFile = uow.Repositories.Get<File>(createModel.ParentId); if (parentFile == null) throw new ArgumentException("No folder could be found for the parent id specified"); } //if its a folder, then we just create it and return success. if (createModel.CreateType == CreateFileType.Folder) { var folder = new File() { IsContainer = true, RootedPath = createModel.ParentId == FixedHiveIds.SystemRoot ? createModel.Name.ToRebelAlias(removeSpaces: true) : (string)createModel.ParentId.Value + "/" + createModel.Name.ToRebelAlias(removeSpaces: true) }; uow.Repositories.AddOrUpdate(folder); uow.Complete(); //add notification Notifications.Add(new NotificationMessage("Folder.Save.Message".Localize(this), "Folder.Save.Title".Localize(this), NotificationType.Success)); //add path for entity for SupportsPathGeneration (tree syncing) to work GeneratePathsForCurrentEntity(CreatePaths(folder)); return RedirectToAction("CreateNew", new { id = folder.Id }); } var model = FileEditorModel.CreateNew(); model.Name = createModel.Name.ToRebelAlias(removeSpaces:true) + createModel.FileExtension; model.ParentId = createModel.ParentId; if (!createModel.Stub.IsNullValueOrEmpty()) PopulateFileContentFromStub(model, createModel.Stub.Value); EnsureViewData(model, null); OnBeforeCreate(createModel, model); var file = PerformSave(model); OnAfterCreate(file); //add notification Notifications.Add(new NotificationMessage(SaveSuccessfulMessage, SaveSuccessfulTitle, NotificationType.Success)); //add path for entity for SupportsPathGeneration (tree syncing) to work GeneratePathsForCurrentEntity(CreatePaths(file)); return RedirectToAction("Edit", new { id = file.Id }); } }
/// <summary> /// This adds some required elements to the ViewBag so that the Create view renders correctly /// </summary> /// <param name="model"></param> protected virtual void EnsureViewData(CreateFileModel model) { var controllerName = RebelController.GetControllerName(this.GetType()); // Update thumbnails var thumbnailFolder = Url.Content(BackOfficeRequestContext.Application.Settings.RebelFolders.DocTypeThumbnailFolder); model.AvailableFileExtensions = AllowedFileExtensions; model.FileThumbnail = thumbnailFolder + "/doc.png"; model.FolderThumbnail = thumbnailFolder + "/folder.png"; // Populate avilable stubs var stubDirHiveId = new HiveId(new Uri("storage://stubs"), "stubs", new HiveIdValue(controllerName)); var stubHive = BackOfficeRequestContext.Application.Hive.GetReader<IFileStore>(stubDirHiveId.ToUri()); using (var uow = stubHive.CreateReadonly()) { var stubFileRelations = uow.Repositories.GetChildRelations(stubDirHiveId, FixedRelationTypes.DefaultRelationType); if(stubFileRelations.Any()) { var stubFiles = uow.Repositories.Get<File>(true, stubFileRelations.Select(x => x.DestinationId).ToArray()); if(stubFiles.Any()) { model.AvailableStubs = stubFiles.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }); } } } // Populate viewbag ViewBag.Title = CreateNewTitle; ViewBag.ControllerId = RebelController.GetControllerId<EditorAttribute>(GetType()); }
/// <summary> /// Used by inheritors to make any changes to the model before creation /// </summary> /// <param name="model"></param> protected virtual void OnBeforeCreate(CreateFileModel createModel, FileEditorModel editorModel) { }