Skip to content

Commit 8b3053c

Browse files
committed
Crop method for retrieving URL & updated documentation.
1 parent 697fc64 commit 8b3053c

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/Umbraco.Cms.Integrations.DAM.Aprimo/Models/ViewModels/AprimoMediaWithCropsViewModel.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,35 @@ public class AprimoMediaWithCropsViewModel
1212
/// </summary>
1313
/// <param name="name"></param>
1414
/// <returns>Crop URL</returns>
15-
public string GetImageUrl(string name)
15+
public string GetCropUrl(string name)
1616
{
1717
var crop = Crops.FirstOrDefault(p => p.Name == name);
1818
if (crop != null)
1919
return crop.Url;
2020

2121
return string.Empty;
2222
}
23+
24+
/// <summary>
25+
/// Get image URL by size
26+
/// </summary>
27+
/// <param name="name"></param>
28+
/// <returns>Crop URL</returns>
29+
public string GetCropUrl(int? width, int? height)
30+
{
31+
if (!width.HasValue && !height.HasValue)
32+
throw new ArgumentException("Width and height cannot be both NULL.");
33+
34+
var crop = width.HasValue && height.HasValue
35+
? Crops.FirstOrDefault(p => p.ResizeWidth == width && p.ResizeHeight == height)
36+
: (width.HasValue
37+
? Crops.FirstOrDefault(p => p.ResizeWidth == width)
38+
: Crops.FirstOrDefault(p => p.ResizeHeight == height));
39+
if (crop != null)
40+
return crop.Url;
41+
42+
return string.Empty;
43+
}
2344
}
2445

2546
public class AprimoMediaItemViewModel

src/Umbraco.Cms.Integrations.DAM.Aprimo/readme.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,12 @@ Properties available from the strongly-typed model:
7676
- Title
7777
- Thumbnail
7878
- Crops
79-
- Asset fields
79+
- Asset fields
80+
81+
### Working with Crops
82+
For the selected media asset you can retrieve the crops details using the `MediaWithCrops` object.
83+
84+
It contains the details of the original asset, the list of available crops and a method to retrieve the crop URL based on name and width/height.
85+
86+
### Working with fields
87+
The asset's fields are grouped in an object containing their label and a dictionary of values based on the available cultures for that asset.

0 commit comments

Comments
 (0)