/// <inheritdoc /> public static ImageViewModel GetRelatedImage(DynamicContent item, string fieldName) { if (item == null) throw new ArgumentNullException("item", "Item cannot be null"); if (String.IsNullOrEmpty(fieldName)) throw new ArgumentException(message: "Value cannot be null or empty", paramName: "fieldName"); ImageViewModel imageModel = new ImageViewModel(); var image = item.GetRelatedItems<Image>(fieldName).FirstOrDefault(); if (image != null) { imageModel.Title = image.Title; imageModel.ThumbnailUrl = image.GetDefaultUrl(); imageModel.ImageUrl = image.MediaUrl; imageModel.AlternativeText = image.AlternativeText; } return imageModel; }
/// <summary> /// Renders the image. /// </summary> /// <param name="helper">The helper.</param> /// <param name="image">The image.</param> /// <param name="className">Name of the class.</param> /// <param name="height">The height.</param> /// <param name="width">The width.</param> /// <returns>Html helper for image</returns> public static IHtmlString RenderImage(this HtmlHelper helper, ImageViewModel image, string className = "", string height = "", string width = "") { if (image == null) { var libManager = LibrariesManager.GetManager(); var libImage = libManager.GetImages().Where(i => i.Title == ConfigurationManager.AppSettings["defaultImageTitle"]).First(); image = new ImageViewModel { ImageUrl = libImage.MediaUrl, AlternativeText = libImage.AlternativeText }; } return new HtmlString(string.Format( "<img src=\"{0}\" alt=\"{1}\" class=\"{2}\" heigth=\"{3}\" width=\"{4}\" />", image.ImageUrl, image.AlternativeText, className, height, width )); }