Exemple #1
0
        public async Task <IActionResult> Templates(string templateId = null)
        {
            var site           = base.Site;
            var productContext = await _clientManager.GetProductContextAsync(site.ClientProductAppId);

            var model = new SiteTemplateViewModel();

            model.SiteId             = site.Id;
            model.AvailableTemplates = productContext.SiteTemplates;
            model.ActiveTemplate     = model.AvailableTemplates.FirstOrDefault(x => x.Id == site.SiteTemplateId);

            if (templateId != null)
            {
                model.SelectedTemplate = model.AvailableTemplates.FirstOrDefault(x => x.Id == templateId);
            }
            else
            {
                model.SelectedTemplate = model.ActiveTemplate;
            }

            if (model.SelectedTemplate.Id == site.SiteTemplateId)
            {
                model.SelectedTheme = model.SelectedTemplate.Themes.First(x => x.Id == site.ThemeId);
            }
            else
            {
                model.SelectedTheme = model.SelectedTemplate.Themes.First(x => x.IsDefault);
            }

            return(View(model));
        }
Exemple #2
0
        public async Task <ActionResult> Create(SiteTemplateViewModel model)
        {
            var pnpFile = await _pnpFileService.Read(model.PnpFileGuid);

            if (pnpFile.PnpTemplate == null)
            {
                return(RedirectToAction("PickFile", new { SPHostUrl = Request.QueryString["SPHostUrl"] }));
            }


            pnpFile.PnpTemplate.ComposedLook.BackgroundFile = model.FileBgBlobLocation;
            pnpFile.PnpTemplate.ComposedLook.SiteLogo       = model.LogoBlobLocation;
            pnpFile.PnpTemplate.ComposedLook.ColorFile      = model.FileClrBlobLocation;
            pnpFile.PnpTemplate.ComposedLook.FontFile       = model.FontBlobLocation;

            var siteTemplate = new SiteTemplate
            {
                Id                = Guid.NewGuid(),
                Name              = model.SiteTemplateName,
                Description       = model.Description,
                PnpTemplate       = pnpFile.PnpTemplate,
                CreationTimeStamp = DateTime.Now
            };

            await _siteTemplateService.Insert(siteTemplate);

            return(RedirectToAction("Index", new { SPHostUrl = Request.QueryString["SPHostUrl"] }));
        }
Exemple #3
0
        public async Task <ActionResult> SaveExternFile(SiteTemplateViewModel model, string fileType, string location)
        {
            int    pos;
            string padnaam;
            var    fileLocation = model.SiteTemplateGuid.ToString();

            if (location == "on")
            {
                fileLocation = "Default";
            }

            try
            {
                if (model.ExternFileBg != null && fileType == "Background.jpg")
                {
                    await _templateFilesBlobService.SaveFile(model.ExternFileBg, fileLocation);

                    pos     = model.ExternFileBg.FileName.LastIndexOf("\\", StringComparison.Ordinal) + 1;
                    padnaam = _templateFilesBlobService.FileInBlob(model.ExternFileBg.FileName.Substring(pos, model.ExternFileBg.FileName.Length - pos), model.SiteTemplateName);

                    return(Json(new { pad = padnaam }));
                }
                if (model.ExternFileClr != null && fileType == "Color.spcolor")
                {
                    await _templateFilesBlobService.SaveFile(model.ExternFileClr, fileLocation);

                    pos     = model.ExternFileClr.FileName.LastIndexOf("\\", StringComparison.Ordinal) + 1;
                    padnaam = _templateFilesBlobService.FileInBlob(model.ExternFileClr.FileName.Substring(pos, model.ExternFileClr.FileName.Length - pos), model.SiteTemplateName);

                    return(Json(new { pad = padnaam }));
                }
                if (model.ExternFileFont != null && fileType == "Font.spfont")
                {
                    await _templateFilesBlobService.SaveFile(model.ExternFileFont, fileLocation);

                    pos     = model.ExternFileFont.FileName.LastIndexOf("\\", StringComparison.Ordinal) + 1;
                    padnaam = _templateFilesBlobService.FileInBlob(model.ExternFileFont.FileName.Substring(pos, model.ExternFileFont.FileName.Length - pos), model.SiteTemplateName);

                    return(Json(new { pad = padnaam }));
                }
                if (model.ExternFileLogo != null && fileType == "Logo.png")
                {
                    await _templateFilesBlobService.SaveFile(model.ExternFileLogo, fileLocation);

                    pos     = model.ExternFileLogo.FileName.LastIndexOf("\\", StringComparison.Ordinal) + 1;
                    padnaam = _templateFilesBlobService.FileInBlob(model.ExternFileLogo.FileName.Substring(pos, model.ExternFileLogo.FileName.Length - pos), model.SiteTemplateName);

                    return(Json(new { pad = padnaam }));
                }
            }
            catch (Exception e)
            {
                return(Json(new { pad = e.ToString() }));
            }

            return(null);
        }
Exemple #4
0
        public async Task <ViewResult> Edit(string id)
        {
            var model = await _siteTemplateService.Read(id);

            var returnValue = new SiteTemplateViewModel
            {
                SiteTemplateName = model.Name,
                Description      = model.Description
            };

            return(View(returnValue));
        }
Exemple #5
0
        public ViewResult Create(Guid id)
        {
            var model = new SiteTemplateViewModel();

            model.SiteTemplateGuid         = Guid.NewGuid();
            model.PnpFileGuid              = id;
            model.UsesDefaultTemplateFiles = false;

            model.LogoBlobLocation    = "";
            model.FileBgBlobLocation  = "";
            model.FileClrBlobLocation = "";
            model.FontBlobLocation    = "";

            var templateFolder = model.SiteTemplateGuid.ToString();

            return(View(model));
        }