Fixed up new actions in MediaController

This commit is contained in:
Shannon
2013-08-28 09:50:15 +10:00
parent 8fc127e195
commit bb6adcab92
5 changed files with 17 additions and 40 deletions

View File

@@ -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<IMedia, MediaItemDisplay>(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);
}

View File

@@ -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; }

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -307,7 +307,6 @@
<Compile Include="Models\ContentEditing\DataTypeDisplay.cs" />
<Compile Include="Models\ContentEditing\DataTypeSave.cs" />
<Compile Include="Models\ContentEditing\EntityBasic.cs" />
<Compile Include="Models\ContentEditing\MediaFolderSave.cs" />
<Compile Include="Models\ContentEditing\PreValueFieldDisplay.cs" />
<Compile Include="Models\ContentEditing\PreValueFieldSave.cs" />
<Compile Include="Models\ContentEditing\PropertyEditorBasic.cs" />