From bb6adcab92dffdf008c88d4847ccc7caeb3f0f7a Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 28 Aug 2013 09:50:15 +1000 Subject: [PATCH] Fixed up new actions in MediaController --- src/Umbraco.Web/Editors/MediaController.cs | 24 +++++++++---------- .../Models/ContentEditing/ContentItemBasic.cs | 6 +---- .../Models/ContentEditing/EntityBasic.cs | 4 ++++ .../Models/ContentEditing/MediaFolderSave.cs | 22 ----------------- src/Umbraco.Web/Umbraco.Web.csproj | 1 - 5 files changed, 17 insertions(+), 40 deletions(-) delete mode 100644 src/Umbraco.Web/Models/ContentEditing/MediaFolderSave.cs diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs index 0fe23d641f..ba8618652d 100644 --- a/src/Umbraco.Web/Editors/MediaController.cs +++ b/src/Umbraco.Web/Editors/MediaController.cs @@ -208,33 +208,33 @@ namespace Umbraco.Web.Editors } //shorthand to use with the media dialog - public MediaItemDisplay PostAddFolder(MediaFolderSave folder) + public MediaItemDisplay PostAddFolder(EntityBasic folder) { - var mediaService = base.ApplicationContext.Services.MediaService; - var f = mediaService.CreateMedia(folder.Name, folder.ParentId, "Folder"); + var mediaService = ApplicationContext.Services.MediaService; + var f = mediaService.CreateMedia(folder.Name, folder.ParentId, Constants.Conventions.MediaTypes.Folder); mediaService.Save(f); return Mapper.Map(f); } //short hand to use with the uploader in the media dialog - public HttpResponseMessage PostAddFile() + public HttpResponseMessage PostAddFile(int parentId) { var context = UmbracoContext.HttpContext; - if(context.Request.Files.Count > 0){ - var parentId = int.Parse(context.Request.Form[0]); - var file = context.Request.Files[0]; - var name = file.FileName; + if(context.Request.Files.Count > 0) + { + var postedFile = context.Request.Files[0]; + var name = postedFile.FileName; var mediaService = base.ApplicationContext.Services.MediaService; - var f = mediaService.CreateMedia(name, parentId, "Image"); - f.SetValue("umbracoFile", file); + var f = mediaService.CreateMedia(name, parentId, Constants.Conventions.MediaTypes.Image); + f.SetValue(Constants.Conventions.Media.File, postedFile); mediaService.Save(f); - return new HttpResponseMessage( HttpStatusCode.OK); + return new HttpResponseMessage(HttpStatusCode.OK); } - return new HttpResponseMessage(HttpStatusCode.InternalServerError); + return new HttpResponseMessage(HttpStatusCode.NotFound); } diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentItemBasic.cs b/src/Umbraco.Web/Models/ContentEditing/ContentItemBasic.cs index 8123ee2155..fe7534e71b 100644 --- a/src/Umbraco.Web/Models/ContentEditing/ContentItemBasic.cs +++ b/src/Umbraco.Web/Models/ContentEditing/ContentItemBasic.cs @@ -20,11 +20,7 @@ namespace Umbraco.Web.Models.ContentEditing [DataMember(Name = "createDate")] public DateTime CreateDate { get; set; } - - [DataMember(Name = "parentId", IsRequired = true)] - [Required] - public int ParentId { get; set; } - + [DataMember(Name = "owner")] public UserBasic Owner { get; set; } diff --git a/src/Umbraco.Web/Models/ContentEditing/EntityBasic.cs b/src/Umbraco.Web/Models/ContentEditing/EntityBasic.cs index 6c14463f7d..625b3a0ece 100644 --- a/src/Umbraco.Web/Models/ContentEditing/EntityBasic.cs +++ b/src/Umbraco.Web/Models/ContentEditing/EntityBasic.cs @@ -22,5 +22,9 @@ namespace Umbraco.Web.Models.ContentEditing [DataMember(Name = "icon")] public string Icon { get; set; } + + [DataMember(Name = "parentId", IsRequired = true)] + [Required] + public int ParentId { get; set; } } } diff --git a/src/Umbraco.Web/Models/ContentEditing/MediaFolderSave.cs b/src/Umbraco.Web/Models/ContentEditing/MediaFolderSave.cs deleted file mode 100644 index 9b8c18e83a..0000000000 --- a/src/Umbraco.Web/Models/ContentEditing/MediaFolderSave.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; - -namespace Umbraco.Web.Models.ContentEditing -{ - [DataContract(Name = "media", Namespace = "")] - public class MediaFolderSave - { - [DataMember(Name = "name", IsRequired = true)] - [Required] - public string Name { get; set; } - - [DataMember(Name = "parentId", IsRequired = true)] - [Required] - public int ParentId { get; set; } - } -} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 427ba38685..80a3f57692 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -307,7 +307,6 @@ -