Esempio n. 1
0
        /// <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;
                }));
            });
Esempio n. 2
0
        public virtual IActionResult CelebrityPictureAdd(int pictureId, int displayOrder,
                                                         string overrideAltAttribute, string overrideTitleAttribute, int celebrityId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCelebrities))
            {
                return(AccessDeniedView());
            }

            if (pictureId == 0)
            {
                throw new ArgumentException();
            }

            //try to get a celebrity with the specified id
            var celebrity = _celebrityService.GetCelebrityById(celebrityId)
                            ?? throw new ArgumentException("No celebrity found with the specified id");


            if (_celebrityService.GetCelebrityPicturesByCelebrityId(celebrityId).Any(p => p.PictureId == pictureId))
            {
                return(Json(new { Result = false }));
            }

            //try to get a picture with the specified id
            var picture = _pictureService.GetPictureById(pictureId)
                          ?? throw new ArgumentException("No picture found with the specified id");

            _pictureService.UpdatePicture(picture.Id,
                                          _pictureService.LoadPictureBinary(picture),
                                          picture.MimeType,
                                          picture.SeoFilename,
                                          overrideAltAttribute,
                                          overrideTitleAttribute);

            _pictureService.SetSeoFilename(pictureId, _pictureService.GetPictureSeName(celebrity.Name));

            _celebrityService.InsertCelebrityPicture(new CelebrityPicture
            {
                PictureId    = pictureId,
                CelebrityId  = celebrityId,
                DisplayOrder = displayOrder
            });

            return(Json(new { Result = true }));
        }