public ActionResult CreateSubSite(CreateSubSiteViewModel model)
        {
            switch (model.Step)
            {
                case CreateSiteStep.SiteInformation:
                    ModelState.Clear();

                    // If it is the first time that we are here
                    if (String.IsNullOrEmpty(model.Title))
                    {
                        model.InheritPermissions = true;
                        using (var ctx = PnPPartnerPackContextProvider.GetAppOnlyClientContext(model.ParentSiteUrl))
                        {
                            Web web = ctx.Web;
                            ctx.Load(web, w => w.Language, w => w.RegionalSettings.TimeZone);
                            ctx.ExecuteQueryRetry();

                            model.Language = (Int32)web.Language;
                            model.TimeZone = web.RegionalSettings.TimeZone.Id;
                        }
                    }
                    break;
                case CreateSiteStep.TemplateParameters:
                    if (!ModelState.IsValid)
                    {
                        model.Step = CreateSiteStep.SiteInformation;
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(model.ProvisioningTemplateUrl) &&
                            model.ProvisioningTemplateUrl.IndexOf(PnPPartnerPackConstants.PnPProvisioningTemplates) > 0)
                        {
                            String templateSiteUrl = model.ProvisioningTemplateUrl.Substring(0, model.ProvisioningTemplateUrl.IndexOf(PnPPartnerPackConstants.PnPProvisioningTemplates));
                            String templateFileName = model.ProvisioningTemplateUrl.Substring(model.ProvisioningTemplateUrl.IndexOf(PnPPartnerPackConstants.PnPProvisioningTemplates) + PnPPartnerPackConstants.PnPProvisioningTemplates.Length + 1);
                            String templateFolder = String.Empty;

                            if (templateFileName.IndexOf("/") > 0)
                            {
                                templateFolder = templateFileName.Substring(0, templateFileName.LastIndexOf("/") - 1);
                                templateFileName = templateFileName.Substring(templateFolder.Length + 1);
                            }
                            model.TemplateParameters = PnPPartnerPackUtilities.GetProvisioningTemplateParameters(
                                    templateSiteUrl,
                                    templateFolder,
                                    templateFileName);
                        }
                    }
                    break;
                case CreateSiteStep.SiteCreated:
                    AntiForgery.Validate();
                    if (ModelState.IsValid)
                    {
                        // Prepare the Job to provision the Sub Site
                        SubSiteProvisioningJob job = new SubSiteProvisioningJob();

                        // Prepare all the other information about the Provisioning Job
                        job.SiteTitle = model.Title;
                        job.Description = model.Description;
                        job.Language = model.Language;
                        job.TimeZone = model.TimeZone;
                        job.ParentSiteUrl = model.ParentSiteUrl;
                        job.RelativeUrl = model.RelativeUrl;
                        job.SitePolicy = model.SitePolicy;
                        job.Owner = ClaimsPrincipal.Current.Identity.Name;
                        job.ProvisioningTemplateUrl = model.ProvisioningTemplateUrl;
                        job.InheritPermissions = model.InheritPermissions;
                        job.Title = String.Format("Provisioning of Sub Site \"{1}\" with Template \"{0}\" by {2}",
                            job.ProvisioningTemplateUrl,
                            job.RelativeUrl,
                            job.Owner);

                        job.TemplateParameters = model.TemplateParameters;

                        model.JobId = ProvisioningRepositoryFactory.Current.EnqueueProvisioningJob(job);
                    }
                    break;
                default:
                    break;
            }

            return PartialView(model.Step.ToString(), model);
        }
Ejemplo n.º 2
0
        public ActionResult CreateSubSite(CreateSubSiteViewModel model)
        {
            PnPPartnerPackSettings.ParentSiteUrl = model.ParentSiteUrl;

            if (model.Step == CreateSiteStep.SiteInformation)
            {
                ModelState.Clear();

                // If it is the first time that we are here
                if (String.IsNullOrEmpty(model.Title))
                {
                    model.InheritPermissions = true;
                    using (var ctx = PnPPartnerPackContextProvider.GetAppOnlyClientContext(model.ParentSiteUrl))
                    {
                        Web web = ctx.Web;
                        ctx.Load(web, w => w.Language, w => w.RegionalSettings.TimeZone);
                        ctx.ExecuteQueryRetry();

                        model.Language = (Int32)web.Language;
                        model.TimeZone = web.RegionalSettings.TimeZone.Id;
                    }
                }
            }
            if (model.Step == CreateSiteStep.TemplateParameters)
            {
                if (!ModelState.IsValid)
                {
                    model.Step = CreateSiteStep.SiteInformation;
                }
                else
                {
                    if (!String.IsNullOrEmpty(model.ProvisioningTemplateUrl) &&
                        !String.IsNullOrEmpty(model.TemplatesProviderTypeName))
                    {
                        var templatesProvider = PnPPartnerPackSettings.TemplatesProviders[model.TemplatesProviderTypeName];
                        if (templatesProvider != null)
                        {
                            var template = templatesProvider.GetProvisioningTemplate(model.ProvisioningTemplateUrl);
                            model.TemplateParameters = template.Parameters;
                        }

                        if (model.TemplateParameters == null || model.TemplateParameters.Count == 0)
                        {
                            model.Step = CreateSiteStep.SiteCreated;
                        }
                    }
                }
            }
            if (model.Step == CreateSiteStep.SiteCreated)
            {
                AntiForgery.Validate();
                if (ModelState.IsValid)
                {
                    // Prepare the Job to provision the Sub Site
                    SubSiteProvisioningJob job = new SubSiteProvisioningJob();

                    // Prepare all the other information about the Provisioning Job
                    job.SiteTitle = model.Title;
                    job.Description = model.Description;
                    job.Language = model.Language;
                    job.TimeZone = model.TimeZone;
                    job.ParentSiteUrl = model.ParentSiteUrl;
                    job.RelativeUrl = model.RelativeUrl;
                    job.SitePolicy = model.SitePolicy;
                    job.Owner = ClaimsPrincipal.Current.Identity.Name;
                    job.ApplyTenantBranding = model.ApplyTenantBranding;

                    job.ProvisioningTemplateUrl = model.ProvisioningTemplateUrl;
                    job.TemplatesProviderTypeName = model.TemplatesProviderTypeName;
                    job.InheritPermissions = model.InheritPermissions;
                    job.Title = String.Format("Provisioning of Sub Site \"{1}\" with Template \"{0}\" by {2}",
                        job.ProvisioningTemplateUrl,
                        job.RelativeUrl,
                        job.Owner);

                    job.TemplateParameters = model.TemplateParameters;

                    model.JobId = ProvisioningRepositoryFactory.Current.EnqueueProvisioningJob(job);
                }
            }

            return PartialView(model.Step.ToString(), model);
        }
        public ActionResult CreateSubSite()
        {
            CreateSubSiteViewModel model = new CreateSubSiteViewModel();
            model.Scope = TemplateScope.Web;
            model.ParentSiteUrl = HttpContext.Request["SPHostUrl"];

            return View("CreateSite", model);
        }
Ejemplo n.º 4
0
        public ActionResult CreateSubSite()
        {
            CreateSubSiteViewModel model = new CreateSubSiteViewModel();
            model.Scope = TargetScope.Web;
            model.ParentSiteUrl = HttpContext.Request["SPHostUrl"];

            PnPPartnerPackSettings.ParentSiteUrl = model.ParentSiteUrl;

            return View("CreateSite", model);
        }