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);
        }
        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);
        }
        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; 
        }
        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"] });
        }