コード例 #1
0
        private string GetMenuClass(int menu, MODELEViewModel modelVm)
        {
            var result = "current";

            switch (menu)
            {
            case 2:
                result = "current";
                break;

            case 3:
                result = "current";
                break;

            case 4:
                result = "current";
                break;

            default:
                result = "current";
                break;
            }
            ;

            return(result);
        }
コード例 #2
0
        private string GetMetaDescription(int menu, MODELEViewModel modelVm)
        {
            var result = modelVm.menu1_meta_description;

            switch (menu)
            {
            case 2:
                result = modelVm.menu2_meta_description;
                break;

            case 3:
                result = modelVm.menu3_meta_description;
                break;

            case 4:
                result = modelVm.menu4_meta_description;
                break;

            default:
                result = modelVm.menu1_meta_description;
                break;
            }
            ;

            return(result);
        }
コード例 #3
0
        private string GetMetatitle(int menu, MODELEViewModel modelVm)
        {
            var result = modelVm.menu1_paragraphe1_titre;

            switch (menu)
            {
            case 2:
                result = modelVm.menu2_paragraphe1_titre;
                break;

            case 3:
                result = modelVm.menu3_paragraphe1_titre;
                break;

            case 4:
                result = modelVm.menu4_paragraphe1_titre;
                break;

            default:
                result = modelVm.menu1_paragraphe1_titre;
                break;
            }
            ;

            return(result);
        }
コード例 #4
0
        public ActionResult Home()
        {
            var             modeleId = Session["modeleId"];
            MODELEViewModel modelVm  = new MODELEViewModel();

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

            return(View(modelVm));
        }
コード例 #5
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();
                }
            }
        }
コード例 #6
0
        public int SaveTheme2(MODELEViewModel model, IEnumerable <HttpPostedFileBase> files)
        {
            int res  = 0;
            var path = "";

            foreach (var file in files)
            {
                if (file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    path = Path.Combine(Server.MapPath("~/App_Data"), fileName);
                    file.SaveAs(path);
                }
            }
            MODELE newmodel = new  MODELE();

            newmodel.logoUrl                    = path;
            newmodel.menu1_titre                = model.menu1_titre;
            newmodel.menu2_titre                = model.menu2_titre;
            newmodel.menu3_titre                = model.menu3_titre;
            newmodel.menu4_titre                = model.menu4_titre;
            newmodel.menu1_paragraphe1_titre    = model.menu1_paragraphe1_titre;
            newmodel.menu1_paragraphe2_titre    = model.menu1_paragraphe2_titre;
            newmodel.menu1_paragraphe1_photoUrl = path;
            newmodel.menu1_contenu1             = model.menu1_contenu1;
            newmodel.menu2_paragraphe1_titre    = model.menu2_paragraphe1_titre;
            newmodel.menu2_paragraphe2_titre    = model.menu2_paragraphe2_titre;
            newmodel.menu2_paragraphe1_photoUrl = path;
            newmodel.menu2_contenu2             = model.menu2_contenu1;
            newmodel.menu3_paragraphe1_titre    = model.menu3_paragraphe1_titre;
            newmodel.menu3_paragraphe2_titre    = model.menu3_paragraphe2_titre;
            newmodel.menu3_paragraphe1_photoUrl = path;
            newmodel.menu3_contenu1             = model.menu3_contenu1;
            newmodel.menu4_paragraphe1_titre    = model.menu4_paragraphe1_titre;
            newmodel.menu4_paragraphe2_titre    = model.menu4_paragraphe2_titre;
            newmodel.menu4_paragraphe1_photoUrl = path;
            newmodel.menu4_contenu1             = model.menu4_contenu1;

            db.MODELEs.Add(newmodel);
            try
            {
                res = db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(res);
            }

            return(res);
        }
コード例 #7
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);
        }
コード例 #8
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"));
            }
        }
コード例 #9
0
        public ActionResult SaveTheme(MODELEViewModel model, HttpPostedFileBase logoUrl,
                                      HttpPostedFileBase menu1_paragraphe1_photoUrl, HttpPostedFileBase menu1_paragraphe2_photoUrl,
                                      HttpPostedFileBase menu2_paragraphe1_photoUrl, HttpPostedFileBase menu2_paragraphe2_photoUrl,
                                      HttpPostedFileBase menu3_paragraphe1_photoUrl, HttpPostedFileBase menu3_paragraphe2_photoUrl,
                                      HttpPostedFileBase menu4_paragraphe1_photoUrl, HttpPostedFileBase menu4_paragraphe2_photoUrl,
                                      HttpPostedFileBase photoALaUneUrl, HttpPostedFileBase favicone, FormCollection collection)
        {
            var templateName = Session["TemplateName"].ToString();

            if (!string.IsNullOrEmpty(collection["nbmenu"]))
            {
                string nbmenu = collection["nbmenu"];
                Session["nbmenu"] = nbmenu;
            }

            string path = Server.MapPath("~/Themes/" + templateName);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            else
            {
                DeleteFiles(path);
            }
            string pathimg = Server.MapPath("~/Themes/" + templateName + "/img/");

            DeleteFiles(pathimg);

            MODELE newmodel = new MODELE();

            newmodel.logoUrl  = SavePhoto(logoUrl, templateName);
            newmodel.favicone = SaveFavicon(favicone, templateName);

            /*Menu 1 */
            newmodel.menu1_titre = model.menu1_titre;

            newmodel.menu1_paragraphe1_titre    = model.menu1_paragraphe1_titre;
            newmodel.menu1_paragraphe1_photoUrl = SavePhoto(menu1_paragraphe1_photoUrl, templateName);
            newmodel.menu1_p1_alt   = AltPhoto(menu1_paragraphe1_photoUrl, templateName);
            newmodel.menu1_contenu1 = model.menu1_contenu1;

            newmodel.menu1_paragraphe2_titre    = model.menu1_paragraphe2_titre;
            newmodel.menu1_paragraphe2_photoUrl = SavePhoto(menu1_paragraphe2_photoUrl, templateName);
            newmodel.menu1_p2_alt           = AltPhoto(menu1_paragraphe2_photoUrl, templateName);
            newmodel.menu1_contenu2         = model.menu1_contenu2;
            newmodel.menu1_meta_description = model.menu1_meta_description;

            /*Menu 2 */
            newmodel.menu2_titre = model.menu2_titre;

            newmodel.menu2_paragraphe1_titre    = model.menu2_paragraphe1_titre;
            newmodel.menu2_paragraphe2_titre    = model.menu2_paragraphe2_titre;
            newmodel.menu2_paragraphe1_photoUrl = SavePhoto(menu2_paragraphe1_photoUrl, templateName);
            newmodel.menu2_p1_alt = AltPhoto(menu2_paragraphe1_photoUrl, templateName);
            newmodel.menu2_paragraphe2_photoUrl = SavePhoto(menu2_paragraphe2_photoUrl, templateName);
            newmodel.menu2_p2_alt           = AltPhoto(menu2_paragraphe2_photoUrl, templateName);
            newmodel.menu2_contenu1         = model.menu2_contenu1;
            newmodel.menu2_contenu2         = model.menu2_contenu2;
            newmodel.menu2_meta_description = model.menu2_meta_description;

            /*Menu 3 */
            newmodel.menu3_titre = model.menu3_titre;

            newmodel.menu3_paragraphe1_titre    = model.menu3_paragraphe1_titre;
            newmodel.menu3_paragraphe2_titre    = model.menu3_paragraphe2_titre;
            newmodel.menu3_paragraphe1_photoUrl = SavePhoto(menu3_paragraphe1_photoUrl, templateName);
            newmodel.menu3_p1_alt = AltPhoto(menu3_paragraphe1_photoUrl, templateName);
            newmodel.menu3_paragraphe2_photoUrl = SavePhoto(menu3_paragraphe2_photoUrl, templateName);
            newmodel.menu3_p2_alt           = AltPhoto(menu3_paragraphe2_photoUrl, templateName);
            newmodel.menu3_contenu1         = model.menu3_contenu1;
            newmodel.menu3_contenu2         = model.menu3_contenu2;
            newmodel.menu3_meta_description = model.menu3_meta_description;

            /*Menu 4 */

            newmodel.menu4_titre = model.menu4_titre;

            newmodel.menu4_paragraphe1_titre    = model.menu4_paragraphe1_titre;
            newmodel.menu4_paragraphe2_titre    = model.menu4_paragraphe2_titre;
            newmodel.menu4_paragraphe1_photoUrl = SavePhoto(menu4_paragraphe1_photoUrl, templateName);
            newmodel.menu4_p1_alt = AltPhoto(menu4_paragraphe1_photoUrl, templateName);
            newmodel.menu4_paragraphe2_photoUrl = SavePhoto(menu4_paragraphe2_photoUrl, templateName);
            newmodel.menu4_p2_alt           = AltPhoto(menu4_paragraphe2_photoUrl, templateName);
            newmodel.menu4_contenu1         = model.menu4_contenu1;
            newmodel.menu4_contenu2         = model.menu4_contenu2;
            newmodel.menu4_meta_description = model.menu4_meta_description;

            /*A la une*/
            newmodel.photoALaUneUrl = SavePhoto(photoALaUneUrl, templateName);
            newmodel.site_url       = model.site_url;

            newmodel.modeleId   = Guid.NewGuid();
            Session["modeleId"] = newmodel.modeleId;

            db.MODELEs.Add(newmodel);
            try
            {
                int res = db.SaveChanges();
                if (res > 0)
                {
                    Templates         val        = new Templates();
                    TEMPLATEViewModel templateVm = new TEMPLATEViewModel();
                    templateVm.ListProjet = val.GetListProjetItem();
                    templateVm.ListTheme  = val.GetListThemeItem();

                    return(View("CreateTemplate", templateVm));
                }

                else
                {
                    return(View("ErrorException"));
                }
            }
            catch (Exception ex)
            {
                return(View("Theme1"));
            }
        }