public ImageLabel GetImageByIndex(Topic topic, uint index) { #region validation if (topic == null) { throw new ArgumentNullException(nameof(topic)); } #endregion // get all imagefile paths IEnumerable <string> imageFilePaths = GetImagePaths(topic); if (imageFilePaths.Count() > index) { // get imagefilepath for specified index string imagePath = GetImagePaths(topic).ElementAt((int)index); // create default imagelabel and set index ImageLabel imageLabel = CreateImageLabel(imagePath); imageLabel.Index = index; imageLabel.SetImageUrl(HttpContextAccessor.HttpContext, topic); SetImageSize(topic, imageLabel); return(imageLabel); } return(null); }
private IEnumerable <ImageLabel> GetImageLabels(Topic topic) { #region validation if (topic == null) { throw new ArgumentNullException(nameof(topic)); } #endregion List <ImageLabel> imageLabelList = new List <ImageLabel>(); long index = 0L; foreach (string imagePath in GetImagePaths(topic)) { string imageFileName = FileNameUtil.GetFileNameFromPath(imagePath); ImageLabel imgLabel = CreateImageLabel(imagePath); imgLabel.Index = index++; imgLabel.SetImageUrl(HttpContextAccessor.HttpContext, topic); imageLabelList.Add(imgLabel); } return(imageLabelList); }
public ImageLabel GetImageLabelById(Topic topic, string imageId) { #region validation if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (string.IsNullOrEmpty(imageId)) { throw new ArgumentNullException(nameof(imageId)); } #endregion // get all imagefile paths List <string> imageFilePaths = new List <string>(GetImagePaths(topic)); foreach (string imageFilePath in imageFilePaths) { if (imageId.Equals(FileNameUtil.GetFileNameFromPath(imageFilePath))) { //create default imagelabel and set index ImageLabel imageLabel = CreateImageLabel(imageFilePath); imageLabel.Index = imageFilePaths.IndexOf(imageFilePath); imageLabel.SetImageUrl(HttpContextAccessor.HttpContext, topic); SetImageSize(topic, imageLabel); return(imageLabel); } } return(null); }