/// <summary> /// Prepare paged celebrity picture list model /// </summary> /// <param name="searchModel">Celebrity picture search model</param> /// <param name="celebrity">Celebrity</param> /// <returns>Celebrity picture list model</returns> public virtual CelebrityPictureListModel PrepareCelebrityPictureListModel(CelebrityPictureSearchModel searchModel, Celebrity celebrity) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (celebrity == null) { throw new ArgumentNullException(nameof(celebrity)); } //get celebrity pictures var celebrityPictures = _celebrityService.GetCelebrityPicturesByCelebrityId(celebrity.Id).ToPagedList(searchModel); //prepare grid model var model = new CelebrityPictureListModel().PrepareToGrid(searchModel, celebrityPictures, () => { return(celebrityPictures.Select(celebrityPicture => { //fill in model values from the entity var celebrityPictureModel = celebrityPicture.ToModel <CelebrityPictureModel>(); //fill in additional values (not existing in the entity) var picture = _pictureService.GetPictureById(celebrityPicture.PictureId) ?? throw new Exception("Picture cannot be loaded"); celebrityPictureModel.PictureUrl = _pictureService.GetPictureUrl(ref picture); celebrityPictureModel.OverrideAltAttribute = picture.AltAttribute; celebrityPictureModel.OverrideTitleAttribute = picture.TitleAttribute; return celebrityPictureModel; })); });
/// <summary> /// Prepare celebrity picture search model /// </summary> /// <param name="searchModel">Celebrity picture search model</param> /// <param name="celebrity">Celebrity</param> /// <returns>Celebrity picture search model</returns> protected virtual CelebrityPictureSearchModel PrepareCelebritySearchModel(CelebrityPictureSearchModel searchModel, Celebrity celebrity) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (celebrity == null) { throw new ArgumentNullException(nameof(celebrity)); } searchModel.CelebrityId = celebrity.Id; //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }