/// <summary> /// Gets the property. /// </summary> /// <param name="property">The property.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetProperty(Umbraco.Core.Models.Property property, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (property == null) { return(null); } var mediaService = new MediaService(new RepositoryFactory()); int id; if (!int.TryParse(property.Value.ToString(), out id)) { return(null); } var file = mediaService.GetById(id); if (file != null) { int bytes; int.TryParse(file.Properties["umbracoBytes"].Value.ToString(), out bytes); var img = new File { Id = file.Id, Name = file.Name, Src = file.Properties["umbracoFile"].Value.ToString(), Extension = file.Properties["umbracoExtension"].Value.ToString(), Size = bytes }; return(img); } return(null); }
protected override IMedia Update(int id, MediaRepresentation content) { var found = MediaService.GetById(id); if (found == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } //Validate properties var validator = new ContentPropertyValidator <IMedia>(ModelState, Services.DataTypeService); validator.ValidateItem(content, found); if (!ModelState.IsValid) { throw ValidationException(ModelState, content, id: id); } Mapper.Map(content, found); MediaService.Save(found); return(found); }
public async Task <IActionResult> Get(Guid id) { var media = await _service.GetById(id); if (media == null) { return(NotFound()); } return(Ok(media)); }
public override void OnActionExecuting(HttpActionContext actionContext) { var mediaItem = (MediaItemSave)actionContext.ActionArguments["contentItem"]; //We now need to validate that the user is allowed to be doing what they are doing. //Then if it is new, we need to lookup those permissions on the parent. IMedia contentToCheck = null; int contentIdToCheck; switch (mediaItem.Action) { case ContentSaveAction.Save: contentToCheck = mediaItem.PersistedContent; contentIdToCheck = contentToCheck.Id; break; case ContentSaveAction.SaveNew: contentToCheck = MediaService.GetById(mediaItem.ParentId); if (mediaItem.ParentId != Constants.System.Root) { contentToCheck = MediaService.GetById(mediaItem.ParentId); contentIdToCheck = contentToCheck.Id; } else { contentIdToCheck = mediaItem.ParentId; } break; default: //we don't support this for media actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.NotFound); return; } if (MediaController.CheckPermissions( actionContext.Request.Properties, Security.CurrentUser, MediaService, EntityService, contentIdToCheck, contentToCheck) == false) { throw new HttpResponseException(actionContext.Request.CreateUserNoAccessResponse()); } }
protected override ContentMetadataRepresentation GetMetadataForItem(int id) { var found = MediaService.GetById(id); if (found == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var result = new ContentMetadataRepresentation(LinkTemplate, id) { Fields = GetDefaultFieldMetaData(), Properties = Mapper.Map <IDictionary <string, ContentPropertyInfo> >(found), CreateTemplate = Mapper.Map <ContentTemplate>(found) }; return(result); }
/// <summary> /// Gets the property. /// </summary> /// <param name="property">The property.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetProperty(Umbraco.Core.Models.Property property, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (property == null) { return(null); } var mediaService = new MediaService(new RepositoryFactory()); int id; if (!int.TryParse(property.Value.ToString(), out id)) { return(null); } var image = mediaService.GetById(id); if (image != null) { int width; int.TryParse(image.Properties["umbracoWidth"].Value.ToString(), out width); int height; int.TryParse(image.Properties["umbracoHeight"].Value.ToString(), out height); int bytes; int.TryParse(image.Properties["umbracoBytes"].Value.ToString(), out bytes); var img = new Image { Id = image.Id, Alt = image.Name, Src = image.Properties["umbracoFile"].Value.ToString(), Width = width, Height = height, Extension = image.Properties["umbracoExtension"].Value.ToString(), Size = bytes }; return(img); } return(null); }
protected override IMedia GetItem(int id) { return(MediaService.GetById(id)); }