Esempio n. 1
0
        public ActionResult Home()
        {
            var             modeleId = Session["modeleId"];
            MODELEViewModel modelVm  = new MODELEViewModel();

            modelVm = new Modeles().GetDetailsModele(Guid.Parse(modeleId.ToString()));

            return(View(modelVm));
        }
Esempio n. 2
0
        private void CreateFiles(int nb_menu, string menu1_html)
        {
            var             templateName = Session["TemplateName"].ToString();
            string          pathHtml     = "";
            MODELEViewModel modelVm      = new MODELEViewModel();

            modelVm = new Modeles().GetDetailsModele((Guid)Session["modeleId"]);
            var html = menu1_html;

            for (int i = 1; i <= nb_menu; i++)
            {
                pathHtml = "~/Themes/" + templateName;

                if (i == 1)
                {
                    pathHtml = pathHtml + "/index.html";
                }
                else
                {
                    string title = GetMenuTitle(i, modelVm);
                    pathHtml = pathHtml + "/" + removeDiacritics(title.ToLower()).Replace("_", "-") + ".html";
                }

                Session["Menu"] = i;

                modelVm.meta_title       = GetMetatitle(i, modelVm);
                modelVm.meta_description = GetMetaDescription(i, modelVm);
                modelVm.menu1_link_class = (i == 1) ? "current" : "";
                modelVm.menu2_link_class = (i == 2) ? "current" : "";
                modelVm.menu3_link_class = (i == 3) ? "current" : "";
                modelVm.menu4_link_class = (i == 4) ? "current" : "";

                modelVm.menu1_link = removeDiacritics(modelVm.menu1_titre.ToLower());
                modelVm.menu2_link = !string.IsNullOrEmpty(modelVm.menu2_titre) ? removeDiacritics(modelVm.menu2_titre.ToLower()) : "";
                modelVm.menu3_link = !string.IsNullOrEmpty(modelVm.menu3_titre) ? removeDiacritics(modelVm.menu3_titre.ToLower()) :"";
                modelVm.menu4_link = !string.IsNullOrEmpty(modelVm.menu4_titre) ? removeDiacritics(modelVm.menu4_titre.ToLower()) : "";

                html = RenderViewAsString("Home", modelVm);

                if (!System.IO.File.Exists(Server.MapPath(pathHtml)))
                {
                    FileInfo info = new FileInfo(Server.MapPath(pathHtml));
                }

                using (StreamWriter w = new StreamWriter(Server.MapPath(pathHtml), false))
                {
                    w.WriteLine(html); // Write the text
                    w.Close();
                }
            }
        }
Esempio n. 3
0
        private TEMPLATEViewModel SetTemplateVM()
        {
            Templates         val        = new Templates();
            TEMPLATEViewModel templateVm = new TEMPLATEViewModel();

            templateVm.ListProjet = val.GetListProjetItem();
            templateVm.ListTheme  = val.GetListThemeItem();
            var             modeleId = Session["modeleId"];
            MODELEViewModel modelVm  = new MODELEViewModel();

            modelVm        = new Modeles().GetDetailsModele(Guid.Parse(modeleId.ToString()));
            templateVm.url = modelVm.site_url;
            return(templateVm);
        }
Esempio n. 4
0
 private void removeModeleButton_Click(object sender, RoutedEventArgs e)
 {
     if (SelectedModele == null || !Modeles.Contains(SelectedModele))
     {
         MessageBox.Show("Veuillez sélectionner un modèle à supprimer", "Erreur sélection", MessageBoxButton.OK, MessageBoxImage.Exclamation);
     }
     else
     {
         MessageBoxResult res = MessageBox.Show("Etes vous certain de vouloir supprimer ce modèle ?", "Vérification", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
         if (res == MessageBoxResult.Yes)
         {
             DataAccess.RemoveFromModeles(SelectedModele);
             Modeles = new ObservableCollection <Modele>(Modele.Ensemble);
             MessageBox.Show("Modele supprimé", "Succès !", MessageBoxButton.OK, MessageBoxImage.Information);
         }
     }
     RefreshProperties();
 }
Esempio n. 5
0
        public ActionResult SaveTemplate(TEMPLATEViewModel model, FormCollection collection)
        {
            int res = 0;

            var    selectedProjetId = model.listprojetId;
            var    selectedThemeId  = model.listThemeId;
            string ftpdir           = "";

            if (!string.IsNullOrEmpty(collection["ftpdirs"]))
            {
                ftpdir = collection["ftpdirs"];
            }

            if (!string.IsNullOrEmpty(Request.QueryString["currentid"]))
            {
                _userId = Guid.Parse(Request.QueryString["currentid"]);
                Session["currentid"] = Request.QueryString["currentid"];
            }
            else if (!string.IsNullOrEmpty(HttpContext.User.Identity.Name))
            {
                _userId = Guid.Parse(HttpContext.User.Identity.Name);
            }

            MODELEViewModel modelVm = new MODELEViewModel();

            modelVm         = new Modeles().GetDetailsModele((Guid)Session["modeleId"]);
            Session["Menu"] = "1";
            var html = RenderViewAsString("Home", modelVm);

            TEMPLATE newtemplate = new TEMPLATE();

            newtemplate.dateCreation = DateTime.Now;
            newtemplate.url          = model.url;
            newtemplate.ftpUser      = model.ftpUser;
            newtemplate.ftpPassword  = model.ftpPassword;
            newtemplate.modeleId     = (Guid)Session["modeleId"];
            newtemplate.ip           = model.ip;
            newtemplate.userId       = _userId;
            newtemplate.PROJET       = db.PROJETS.Find(selectedProjetId);
            newtemplate.projetId     = selectedProjetId;
            var   selectedTheme = model.THEME.theme_name;
            THEME currentTheme  = db.THEMES.FirstOrDefault(x => x.theme_name.Contains(selectedTheme.TrimEnd()));

            if (currentTheme == null)
            {
                currentTheme = new THEME {
                    themeId = Guid.NewGuid(), theme_name = selectedTheme
                };
                db.THEMES.Add(currentTheme);
                db.SaveChanges();
            }

            newtemplate.THEME   = currentTheme;
            newtemplate.themeId = currentTheme.themeId;

            newtemplate.html = html;


            var results =
                newtemplate.templateId = Guid.NewGuid();

            db.TEMPLATEs.Add(newtemplate);
            try
            {
                res = db.SaveChanges();
                if (res > 0)
                {
                    var templateName = Session["TemplateName"].ToString();

                    int nb_menu = (Session["nbmenu"] == null) ? 1 : int.Parse(Session["nbmenu"].ToString());

                    CreateFiles(nb_menu, html);

                    //Send Ftp
                    string pathParent = Server.MapPath("~/Themes/" + templateName);
                    string pathCss    = pathParent + "/css/";
                    string pathImg    = pathParent + "/img";
                    string pathJs     = pathParent + "/js";
                    int    result     = SendToFtp(ftpdir, model.url, model.ftpUser, model.ftpPassword, pathCss, pathParent, pathImg, pathJs);

                    //return new FilePathResult(path, "text/html");
                    if (result == 0)
                    {
                        return(View("CreateTemplateConfirmation"));
                    }
                    else
                    {
                        return(View("ErrorException"));
                    }
                }
                else
                {
                    return(View("ErrorException"));
                }
            }
            catch (Exception ex)
            {
                return(View("ErrorException"));
            }
        }