public virtual IActionResult VendorPictureList(VendorPictureSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors)) { return(AccessDeniedKendoGridJson()); } //try to get a vendor with the specified id var vendor = _vendorService.GetVendorById(searchModel.VendorId) ?? throw new ArgumentException("No vendor found with the specified id"); //prepare model var model = this.PrepareVendorPictureListModel(searchModel, vendor); return(Json(model)); }
/// <summary> /// Prepare paged vendor picture list model /// </summary> /// <param name="searchModel">Vendor picture search model</param> /// <param name="vendor">Vendor</param> /// <returns>Vendor picture list model</returns> public virtual VendorPictureListModel PrepareVendorPictureListModel(VendorPictureSearchModel searchModel, Vendor vendor) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (vendor == null) { throw new ArgumentNullException(nameof(vendor)); } //get vendor pictures var vendorPictures = this.GetVendorPicturesByVendorId(vendor.Id); //prepare grid model var model = new VendorPictureListModel { Data = vendorPictures.PaginationByRequestModel(searchModel).Select(vendorPicture => { //fill in model values from the entity var vendorPictureModel = new VendorPictureModel { Id = vendorPicture.Id, VendorId = vendorPicture.VendorId, PictureId = vendorPicture.PictureId, DisplayOrder = vendorPicture.DisplayOrder }; //fill in additional values (not existing in the entity) var picture = _pictureService.GetPictureById(vendorPicture.PictureId) ?? throw new Exception("Picture cannot be loaded"); vendorPictureModel.PictureUrl = _pictureService.GetPictureUrl(picture); vendorPictureModel.OverrideAltAttribute = picture.AltAttribute; vendorPictureModel.OverrideTitleAttribute = picture.TitleAttribute; return(vendorPictureModel); }), Total = vendorPictures.Count }; return(model); }