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)); }
/// <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 = UmbracoController.GetControllerName(this.GetType()); // Update thumbnails var thumbnailFolder = Url.Content(BackOfficeRequestContext.Application.Settings.UmbracoFolders.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 = UmbracoController.GetControllerId <EditorAttribute>(GetType()); }
public CreateFileWindow() { InitializeComponent(); WindowStyle = WindowStyle.None; m_ViewModel = new CreateFileViewModel(this); Model = m_ViewModel.Model; DataContext = Model; }
public async Task <IActionResult> Upload([FromForm] CreateFileModel model) { if (model == null) { return(BadRequest()); } var uploads = Path.Combine(hostingEnvironment.ContentRootPath, "uploads"); if (!Directory.Exists(uploads)) { Directory.CreateDirectory(uploads); } if (model.File.Length > 0) { var filePath = Path.Combine(uploads, model.File.FileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await model.File.CopyToAsync(fileStream); } } var file = new Common.Entity.FileService.File(); file.DownloadDate = DateTime.Now; file.FileAccessId = Convert.ToInt32(model.AccessId); file.CategoryId = Convert.ToInt32(model.CategoryId); file.Description = model.Description; file.Name = model.File.FileName; file.Size = model.File.Length; var fileUrl = new FileUrl(); fileUrl.Url = uploads; var newFileUrl = db.FileUrls.Create(fileUrl); if (newFileUrl == null) { return(BadRequest()); } file.UserId = 1; file.FileUrlId = newFileUrl.Id; FileCard newFile = db.Files.Create(file); if (newFile == null) { return(BadRequest()); } return(Ok(newFile)); }
public object CreateFile(CreateFileModel model) { _ensureDisableEditing(); model.FilePath = _ensureRootPath(model.FilePath); var systemPath = model.FilePath.ToSystemPath(1); File.WriteAllText(systemPath + ".md", @"#Overview#"); return(new { Status = "Created." }); }
public async Task <ActionResult <int> > Upload([FromForm] CreateFileModel file) { var id = await _mediaService.Save(file?.FormFile); return(Created($"{Request.Path.Value}/{id}", id)); }
protected override void OnBeforeCreate(CreateFileModel createModel, FileEditorModel editorModel) { createModel.ParentId = editorModel.ParentId = FixedHiveIds.SystemRoot; }
public async Task Post(CreateFileModel crm) { IdentityUser me = await _userManager.FindByNameAsync(User.Identity.Name); await NoteDataManager.CreateNoteFile(_db, _userManager, me.Id, crm.NoteFileName, crm.NoteFileTitle); }
public CancelCommand(CreateFileModel createFileModel) { m_CreateFileModel = createFileModel; }
/// <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) { }
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.ToUmbracoAlias(removeSpaces: true) : (string)createModel.ParentId.Value + "/" + createModel.Name.ToUmbracoAlias(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.ToUmbracoAlias(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 })); } }