Service class for the store package model.
상속: StoreServiceBase
예제 #1
0
        private void DisplayPackageInfo()
        {
            string errorResponse = string.Empty;

            // check that store is configured
            if ( StoreService.OrganizationIsConfigured() )
            {

                PackageService packageService = new PackageService();
                var package = packageService.GetPackage( packageId, out errorResponse );

                // check for errors
                ErrorCheck( errorResponse );

                //lPackageName.Text = package.Name;
                imgPackageImage.ImageUrl = package.PackageIconBinaryFile.ImageUrl;

                if ( package.IsFree )
                {
                    //lCost.Text = "<div class='pricelabel free'><h4>Free</h4></div>";
                    lInstallMessage.Text = string.Format(_installFreeMessage, package.Name);
                }
                else
                {
                    //lCost.Text = string.Format( "<div class='pricelabel cost'><h4>${0}</h4></div>", package.Price );
                    lInstallMessage.Text = string.Format( _installPurchaseMessage, package.Name, package.Price.ToString() );
                }

                if ( package.IsPurchased )
                {
                    // check if it's installed
                    // determine the state of the install button (install, update, buy or installed)
                    InstalledPackage installedPackage = InstalledPackageService.InstalledPackageVersion( package.Id );

                    if ( installedPackage == null )
                    {
                        //lCost.Visible = false;
                        lInstallMessage.Text = _installPreviousPurchase;
                    }
                    else
                    {
                        //lCost.Visible = false;
                        lInstallMessage.Text = _updateMessage;
                        btnInstall.Text = "Update";
                    }

                }
            }
            else
            {
                var queryParams = new Dictionary<string, string>();
                queryParams.Add( "ReturnUrl", Request.RawUrl );

                NavigateToLinkedPage( "LinkOrganizationPage", queryParams );
            }
        }
예제 #2
0
        private void ShowPackage()
        {
            string errorResponse = string.Empty;

            // get package id
            int packageId = -1;

            if ( !string.IsNullOrWhiteSpace( PageParameter( "PackageId" ) ) )
            {
                packageId = Convert.ToInt32( PageParameter( "PackageId" ) );
            }

            PackageService packageService = new PackageService();
            var package = packageService.GetPackage( packageId, out errorResponse );

            string storeKey = StoreService.GetOrganizationKey();

            // check for errors
            ErrorCheck( errorResponse );

            lPackageName.Text = package.Name;
            lPackageDescription.Text = package.Description;
            lVendorName.Text = package.Vendor.Name;
            imgPackageImage.ImageUrl = package.PackageIconBinaryFile.ImageUrl;
            lbPackageLink.PostBackUrl = package.SupportUrl;
            lRatingSummary.Text = string.Format( "<div class='rating rating-{0} pull-left margin-r-sm'><small></small></div>", package.Rating.ToString().Replace( ".", "" ) );

            lAuthorInfo.Text = string.Format( "<a href='{0}'>{1}</a>", package.Vendor.Url, package.Vendor.Name );

            if ( package.IsFree )
            {
                lCost.Text = "<div class='pricelabel free'><h4>Free</h4></div>";
            }
            else
            {
                lCost.Text = string.Format( "<div class='pricelabel cost'><h4>${0}</h4></div>", package.Price );
            }

            // get latest version
            PackageVersion latestVersion = null;
            if ( package.Versions.Count > 0 )
            {
                RockSemanticVersion rockVersion = RockSemanticVersion.Parse( VersionInfo.GetRockSemanticVersionNumber() );
                latestVersion = package.Versions.Where( v => v.RequiredRockSemanticVersion <= rockVersion ).OrderByDescending(v => v.Id).FirstOrDefault();
            }

            // determine the state of the install button (install, update, buy or installed)
            InstalledPackage installedPackage = InstalledPackageService.InstalledPackageVersion( package.Id );

            if ( installedPackage == null )
            {
                // it's not installed
                // todo add logic that it's not installed but has been purchased
                if ( package.IsFree )
                {
                    // the package is free
                    lbInstall.Text = "Install";
                }
                else
                {
                    if ( package.IsPurchased )
                    {
                        lbInstall.Text = "Install";
                        lInstallNotes.Text = string.Format( "<small>Purchased {0}</small>", package.PurchasedDate.ToShortDateString());

                        // set rating link button
                        lbRate.Visible = true;
                        lbRate.PostBackUrl = string.Format( "http://www.rockrms.com/Store/Rate?OrganizationKey={0}&PackageId={1}", storeKey, packageId.ToString());
                    }
                    else
                    {
                        lbInstall.Text = "Buy";
                    }
                }
            }
            else
            {
                if ( installedPackage.VersionId == latestVersion.Id )
                {
                    // have the latest version installed
                    lbInstall.Text = "Installed";
                    lbInstall.Enabled = false;
                    lbInstall.CssClass = "btn btn-default btn-install";
                    lbInstall.Attributes.Add( "disabled", "disabled" );

                    // set rating link button
                    lbRate.Visible = true;
                    lbRate.PostBackUrl = string.Format( "http://www.rockrms.com/Store/Rate?OrganizationKey={0}&PackageId={1}&InstalledVersionId={2}", storeKey, packageId.ToString(), installedPackage.VersionId.ToString() );

                }
                else
                {
                    // have a previous version installed
                    lbInstall.Text = "Update";
                    lInstallNotes.Text = string.Format( "<small>You have {0} installed</small>", installedPackage.VersionLabel);

                    // set rating link button
                    lbRate.Visible = true;
                    lbRate.PostBackUrl = string.Format( "http://www.rockrms.com/Store/Rate?OrganizationKey={0}&PackageId={1}&InstalledVersionId={2}", storeKey, packageId.ToString(), installedPackage.VersionId.ToString() );

                }
            }

            if ( latestVersion != null )
            {

                rptScreenshots.DataSource = latestVersion.Screenshots;
                rptScreenshots.DataBind();

                lLatestVersionLabel.Text = latestVersion.VersionLabel;
                lLatestVersionDescription.Text = latestVersion.Description;

                // alert the user if a newer version exists but requires a rock update
                if ( package.Versions.Where( v => v.Id > latestVersion.Id ).Count() > 0 )
                {
                    var lastVersion = package.Versions.OrderByDescending( v => v.RequiredRockSemanticVersion ).FirstOrDefault();
                    lVersionWarning.Text = string.Format( "<div class='alert alert-info'>A newer version of this item is available but requires Rock v{0}.{1}.</div>",
                                                    lastVersion.RequiredRockSemanticVersion.Minor.ToString(),
                                                    lastVersion.RequiredRockSemanticVersion.Patch.ToString() );
                }

                lLastUpdate.Text = latestVersion.AddedDate.ToShortDateString();
                lRequiredRockVersion.Text = string.Format("v{0}.{1}",
                                                latestVersion.RequiredRockSemanticVersion.Minor.ToString(),
                                                latestVersion.RequiredRockSemanticVersion.Patch.ToString());
                lDocumenationLink.Text = string.Format( "<a href='{0}'>Support Link</a>", latestVersion.DocumentationUrl );

                // fill in previous version info
                rptAdditionalVersions.DataSource = package.Versions.Where( v => v.Id < latestVersion.Id );
                rptAdditionalVersions.DataBind();

                // get the details for the latest version
                PackageVersion latestVersionDetails = new PackageVersionService().GetPackageVersion( latestVersion.Id, out errorResponse );

                // check for errors
                ErrorCheck( errorResponse );
            }
            else
            {
                // hide install button
                lbInstall.Visible = false;

                // display info on what Rock version you need to be on to run this package
                if ( package.Versions.Count > 0 )
                {
                    var firstVersion = package.Versions.OrderBy( v => v.RequiredRockSemanticVersion ).FirstOrDefault();
                    var lastVersion = package.Versions.OrderByDescending( v => v.RequiredRockSemanticVersion ).FirstOrDefault();

                    if ( firstVersion == lastVersion )
                    {
                        lVersionWarning.Text = string.Format( "<div class='alert alert-warning'>This item requires Rock version v{0}.{1}.</div>",
                                                    lastVersion.RequiredRockSemanticVersion.Minor.ToString(),
                                                    lastVersion.RequiredRockSemanticVersion.Patch.ToString() );
                    }
                    else
                    {
                        lVersionWarning.Text = string.Format( "<div class='alert alert-warning'>This item requires at least Rock version v{0}.{1} but the latest version requires v{2}.{3}.</div>",
                                                    firstVersion.RequiredRockSemanticVersion.Minor.ToString(),
                                                    firstVersion.RequiredRockSemanticVersion.Patch.ToString(),
                                                    lastVersion.RequiredRockSemanticVersion.Minor.ToString(),
                                                    lastVersion.RequiredRockSemanticVersion.Patch.ToString() );
                    }
                }

            }
        }
        private void DisplayPackage()
        {
            // get package id
            int packageId = -1;

            if ( !string.IsNullOrWhiteSpace( PageParameter( "PackageId" ) ) )
            {
                packageId = Convert.ToInt32( PageParameter( "PackageId" ) );
            }

            PackageService packageService = new PackageService();
            var package = packageService.GetPackage( packageId );

            var mergeFields = new Dictionary<string, object>();

            mergeFields.Add( "Package", package );
            mergeFields.Add( "CurrentPerson", CurrentPerson );

            var globalAttributeFields = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields( CurrentPerson );
            globalAttributeFields.ToList().ForEach( d => mergeFields.Add( d.Key, d.Value ) );

            lOutput.Text = GetAttributeValue( "LavaTemplate" ).ResolveMergeFields( mergeFields );

            if ( GetAttributeValue( "SetPageTitle" ).AsBoolean() )
            {
                string pageTitle = package.Name;
                RockPage.PageTitle = pageTitle;
                RockPage.BrowserTitle = String.Format( "{0} | {1}", pageTitle, RockPage.Site.Name );
                RockPage.Header.Title = String.Format( "{0} | {1}", pageTitle, RockPage.Site.Name );
            }

            // show debug info
            if ( GetAttributeValue( "EnableDebug" ).AsBoolean() && IsUserAuthorized( Authorization.EDIT ) )
            {
                lDebug.Visible = true;
                lDebug.Text = mergeFields.lavaDebugInfo();
            }
        }
        private void DisplayPackages()
        {
            string errorResponse = string.Empty;

            // check that the store is configured with an organization
            if ( StoreService.OrganizationIsConfigured() )
            {
                PackageService packageService = new PackageService();
                var purchases = packageService.GetPurchasedPackages( out errorResponse );

                // check errors
                ErrorCheck( errorResponse );

                if ( purchases.Count == 0 )
                {
                    lMessages.Text = "<div class='alert alert-warning'>No packages have been purchased for this organization.</div>";
                }

                rptPurchasedProducts.DataSource = purchases;
                rptPurchasedProducts.DataBind();
            }
            else
            {
                var queryParams = new Dictionary<string, string>();
                queryParams.Add( "ReturnUrl", Request.RawUrl );

                NavigateToLinkedPage( "LinkOrganizationPage", queryParams );
            }
        }
        private void LoadPackages()
        {
            // get category
            int? categoryId = null;

            if ( !string.IsNullOrWhiteSpace( GetAttributeValue( "CategoryId" ) ) )
            {
                categoryId = Convert.ToInt32(GetAttributeValue( "CategoryId" ));
            }
            else if ( !string.IsNullOrWhiteSpace( PageParameter( "CategoryId" ) ) )
            {
                categoryId = Convert.ToInt32( PageParameter( "CategoryId" ) );
            }

            string categoryName = PageParameter( "CategoryName" );
            if ( GetAttributeValue( "SetPageTitle" ).AsBoolean() && !string.IsNullOrWhiteSpace(categoryName) )
            {
                string pageTitle = "Items for " + categoryName;
                RockPage.PageTitle = pageTitle;
                RockPage.BrowserTitle = String.Format( "{0} | {1}", pageTitle, RockPage.Site.Name );
                RockPage.Header.Title = String.Format( "{0} | {1}", pageTitle, RockPage.Site.Name );
            }

            PackageService packageService = new PackageService();
            var packages = packageService.GetAllPackages( categoryId );

            var mergeFields = new Dictionary<string, object>();
            mergeFields.Add( "CurrentPerson", CurrentPerson );

            // add link to detail page
            Dictionary<string, object> linkedPages = new Dictionary<string, object>();
            linkedPages.Add( "DetailPage", LinkedPageUrl( "DetailPage", null ) );
            mergeFields.Add( "LinkedPages", linkedPages );

            var globalAttributeFields = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields( CurrentPerson );
            globalAttributeFields.ToList().ForEach( d => mergeFields.Add( d.Key, d.Value ) );

            mergeFields.Add( "Packages", packages );

            lOutput.Text = GetAttributeValue( "LavaTemplate" ).ResolveMergeFields( mergeFields );

            // show debug info
            if ( GetAttributeValue( "EnableDebug" ).AsBoolean() && IsUserAuthorized( Authorization.EDIT ) )
            {
                lDebug.Visible = true;
                lDebug.Text = mergeFields.lavaDebugInfo(); ;
            }
        }
예제 #6
0
        private void DisplayPackage()
        {
            // get package id
            int packageId = -1;

            if ( !string.IsNullOrWhiteSpace( PageParameter( "PackageId" ) ) )
            {
                packageId = Convert.ToInt32( PageParameter( "PackageId" ) );
            }

            PackageService packageService = new PackageService();
            var package = packageService.GetPackage( packageId );

            var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( this.RockPage, this.CurrentPerson );

            mergeFields.Add( "Package", package );

            lOutput.Text = GetAttributeValue( "LavaTemplate" ).ResolveMergeFields( mergeFields );

            if ( GetAttributeValue( "SetPageTitle" ).AsBoolean() )
            {
                string pageTitle = package.Name;
                RockPage.PageTitle = pageTitle;
                RockPage.BrowserTitle = String.Format( "{0} | {1}", pageTitle, RockPage.Site.Name );
                RockPage.Header.Title = String.Format( "{0} | {1}", pageTitle, RockPage.Site.Name );
            }

            // show debug info
            if ( GetAttributeValue( "EnableDebug" ).AsBoolean() && IsUserAuthorized( Authorization.EDIT ) )
            {
                lDebug.Visible = true;
                lDebug.Text = mergeFields.lavaDebugInfo();
            }
        }