Beispiel #1
0
        protected void btnNew_Click(object sender, EventArgs e)
        {
            TemplateViewModel model = new TemplateViewModel();

            model.Name     = "New Template";
            model.Title    = "Enter the subject";
            model.Text     = String.Empty;
            model.StatusId = value;

            templatecontroller.AddTemplate(model);

            TemplateViewModel modeldata = templatecontroller.GetTemplateByStatusIdLast(value);

            txtEdit.Text    = modeldata.Name;
            txtSubject.Text = modeldata.Title;
            btnSave.Enabled = true;
            btnNew.Enabled  = false;
        }
Beispiel #2
0
    protected void imgInstall_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            if (fileTemplateZip.HasFile && fileTemplateZip.PostedFile.FileName != string.Empty)
            {
                string fileName = fileTemplateZip.PostedFile.FileName;
                string cntType  = fileTemplateZip.PostedFile.ContentType;
                if (fileName.Substring(fileName.Length - 3, 3).ToLower() == "zip")
                {
                    string path               = HttpContext.Current.Server.MapPath("~/");
                    string temPath            = SageFrame.Core.RegisterModule.Common.TemporaryFolder;
                    string destPath           = Path.Combine(path, temPath);
                    string downloadPath       = SageFrame.Core.RegisterModule.Common.TemporaryTemplateFolder;
                    string downloadDestPath   = Path.Combine(path, downloadPath);
                    string templateName       = ParseFileNameWithoutPath(fileName.Substring(0, fileName.Length - 4));
                    string templateFolderPath = path + "Templates\\" + templateName;
                    if (!Directory.Exists(templateFolderPath))
                    {
                        if (!Directory.Exists(destPath))
                        {
                            Directory.CreateDirectory(destPath);
                        }

                        string filePath = destPath + "\\" + fileTemplateZip.FileName;
                        fileTemplateZip.SaveAs(filePath);
                        string ExtractedPath = string.Empty;
                        ZipUtil.UnZipFiles(filePath, destPath, ref ExtractedPath, SageFrame.Core.RegisterModule.Common.Password, SageFrame.Core.RegisterModule.Common.RemoveZipFile);
                        string[] dirs              = Directory.GetDirectories(ExtractedPath);
                        bool     foundCSSFolder    = false;
                        bool     foundImagesFolder = false;
                        bool     foundTemplateCss  = false;
                        bool     foundLayoutCss    = false;
                        foreach (string dir in dirs)
                        {
                            string folderName = ParseFileNameWithoutPath(dir);
                            if (folderName.ToLower() == "css")
                            {
                                foundCSSFolder = true;
                                string[] files = Directory.GetFiles(dir);
                                foreach (string file in files)
                                {
                                    if (file.Contains("template.css"))
                                    {
                                        foundTemplateCss = true;
                                    }
                                    if (file.Contains("layout.css"))
                                    {
                                        foundLayoutCss = true;
                                    }
                                }
                            }
                            if (folderName.ToLower() == "images")
                            {
                                foundImagesFolder = true;
                            }
                        }
                        if (foundCSSFolder && foundImagesFolder && foundTemplateCss && foundLayoutCss)
                        {
                            if (!Directory.Exists(downloadDestPath))
                            {
                                Directory.CreateDirectory(downloadDestPath);
                            }
                            fileTemplateZip.SaveAs(downloadDestPath + "\\" + fileTemplateZip.FileName);

                            Directory.Move(ExtractedPath, templateFolderPath);
                            TemplateController.AddTemplate(new TemplateInfo(templateName, txtAuthor.Text, txtTemplateDesc.Text, txtAuthorURL.Text, GetPortalID, GetUsername));
                            ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("TemplateManagement", "TemplateInstallSuccessfully"), "", SageMessageType.Success);
                            BindTemplate();
                            //PanelVisibility(false, true);
                            Response.Redirect(Request.Url.OriginalString);
                        }
                        else
                        {
                            Directory.Delete(destPath, true);
                            ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("TemplateManagement", "InvalidTemplate"), "", SageMessageType.Alert);
                        }
                    }
                    else
                    {
                        ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("TemplateManagement", "TemplateAlreadyInstall"), "", SageMessageType.Error);
                    }
                }
                else
                {
                    ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("TemplateManagement", "InvalidTemplateZip"), "", SageMessageType.Alert);
                }
            }
        }
        catch (Exception ex)
        {
            if (ex.Message.Equals(UnexpectedEOF, StringComparison.OrdinalIgnoreCase))
            {
                ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("TemplateManagement", "ZipFileIsCorrupt"), "", SageMessageType.Alert);
            }
            else
            {
                ProcessException(ex);
            }
        }
    }