Esempio n. 1
0
        public async Task <ActionResult> CreateSite(SiteCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.TenantKey = model.TenantKey.FormatTenantKey();

                if (await ValidateDuplicateSiteTitleAsync(model.ClientId, model.Title, "") == false)
                {
                    return(BadRequest(ModelState));
                }

                if (await ValidateDuplicateSiteTenantKeyAsync(model.ClientId, model.TenantKey, "") == false)
                {
                    return(BadRequest(ModelState));
                }

                var site = new Site()
                {
                    ClientId           = model.ClientId,
                    ClientProductAppId = model.ClientProductAppId,
                    Title          = model.Title,
                    TenantKey      = model.TenantKey,
                    SiteTemplateId = model.TemplateId,
                    SecurityPoolId = model.UserPoolKey
                };
                site.DefaultCultureKey = _localizationOptions.Value.DefaultRequestCulture.Culture.Name;
                site.Cultures.Add(new SiteCulture()
                {
                    CultureKey = site.DefaultCultureKey
                });

                // Create & Initialize Site
                await _siteManager.CreateAsync(site);

                await _sitePublisher.CreateInitialVersion(site);

                // Update model values from newly created site
                model.Id          = site.Id;
                model.UserPoolKey = site.SecurityPoolId;

                return(Ok(model));
            }
            return(BadRequest(ModelState));
        }