Beispiel #1
0
        protected void Application_Start()
        {
            if (!Roles.RoleExists("CanPostNews"))
                Roles.CreateRole("CanPostNews");

            if (Membership.GetUser("admin") == null)
            {
                Membership.CreateUser("admin", "*****@*****.**", "*****@*****.**");
                Roles.AddUserToRole("admin", "CanPostNews");
            }

            var db = new pmiEntities();
            var si = db.SiteInfoes.Find(1);

            if (si == null)
            {
                var defaultSiteInfo = new SiteInfo();
                defaultSiteInfo.theme = "Default";
                defaultSiteInfo.footer = "footer";
                db.SiteInfoes.Add(defaultSiteInfo);
                db.SaveChanges();
            }

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            RegisterViewEngine(ViewEngines.Engines);
        }
Beispiel #2
0
        public static string ThemeLayout(this UrlHelper url)
        {
            var defaultPath = "~/Views/Shared/_Layout.cshtml";

            var themeLayout = defaultPath;
            var db = new pmiEntities();
            var theme = db.SiteInfoes.Find(1).theme;

            if (!string.IsNullOrEmpty(theme))
                themeLayout = ThemePath + theme + "/Views/Shared/_Layout.cshtml";

            if (!System.IO.File.Exists(HttpContext.Current.Server.MapPath(themeLayout)))
                themeLayout = defaultPath;

            return themeLayout;
        }
Beispiel #3
0
        private RazorViewEngine CreatePMIViewEngine()
        {
            var pmiViewEngine = new RazorViewEngine();
            var db = new pmiEntities();

            this.theme = db.SiteInfoes.FirstOrDefault().theme;

            pmiViewEngine.PartialViewLocationFormats = new []
                {
                    "~/Themes/" + theme + "/Views/{1}/{0}.cshtml",
                    "~/Themes/" + theme + "/Views/Shared/{0}.cshtml",
                    "~/Themes/" + theme + "/Views/Shared/{1}/{0}.cshtml"
                }.Union(pmiViewEngine.PartialViewLocationFormats).ToArray();

            pmiViewEngine.AreaPartialViewLocationFormats = new[]
                {
                    "~/Themes/" + theme + "/Areas/{2}/Views/{1}/{0}.cshtml",
                    "~/Themes/" + theme + "/Areas/{2}/Views/Shared/{0}.cshtml",
                    "~/Themes/" + theme + "/Areas/{2}/Views/Shared/{1}/{0}.cshtml",
                }.Union(pmiViewEngine.AreaPartialViewLocationFormats).ToArray();

            pmiViewEngine.ViewLocationFormats = new []
                {
                    "~/Themes/" + theme + "/Views/{1}/{0}.cshtml"
                }.Union(pmiViewEngine.ViewLocationFormats).ToArray();

            pmiViewEngine.AreaViewLocationFormats = new[]
                {
                    "~/Themes/" + theme + "/Areas/{2}/Views/{1}/{0}.cshtml"
                }.Union(pmiViewEngine.AreaViewLocationFormats).ToArray();

            pmiViewEngine.MasterLocationFormats = new []
                {
                    "~/Themes/" + theme + "/Views/{1}/{0}.cshtml",
                    "~/Themes/" + theme + "/Views/Shared/{0}.cshtml",
                    "~/Themes/" + theme + "/Views/Shared/{1}/{0}.cshtml"
                }.Union(pmiViewEngine.MasterLocationFormats).ToArray();

            pmiViewEngine.AreaMasterLocationFormats = new[]
                {
                    "~/Themes/" + theme + "/Areas/{2}/Views/{1}/{0}.cshtml",
                    "~/Themes/" + theme + "/Areas/{2}/Views/Shared/{0}.cshtml",
                    "~/Themes/" + theme + "/Areas/{2}/Views/Shared/{1}/{0}.cshtml",
                }.Union(pmiViewEngine.AreaMasterLocationFormats).ToArray();

            return pmiViewEngine;
        }
Beispiel #4
0
        public static string ThemeContent(this UrlHelper url, string path)
        {
            var db = new pmiEntities();
            var theme = db.SiteInfoes.Find(1).theme; // there wouldn't be any other key than 1. If there is, something's wrong!

            var finalPath = ThemePath;

            if (string.IsNullOrEmpty(theme))
                finalPath = finalPath + "Default/";
            else
                finalPath = finalPath + theme + "/";

            // path cleaning
            if (path.StartsWith("~/"))
                path = path.Remove(0, 2);

            if (path.StartsWith("/"))
                path = path.Remove(0, 1);

            path = path.Replace("../", string.Empty);
            finalPath = finalPath + path;

            return VirtualPathUtility.ToAbsolute(finalPath);
        }
Beispiel #5
0
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var db = new pmiEntities();
            var currentPost = db.Posts.Where(p => p.id == this.id).FirstOrDefault();

            // edit post
            if (currentPost != null)
            {
                // case where there's no image change
                if (!string.IsNullOrEmpty(currentPost.image))
                {
                    this.image = currentPost.image;
                }

                this.updated = DateTime.Now;

                if (this.writer != currentPost.writer)
                    yield return new ValidationResult(PostModelResources.WriterError, new[] { "Title" });
            }
            else // new post
            {
                this.created = DateTime.Now;
                this.updated = DateTime.Now;
            }

            if (String.IsNullOrEmpty(this.englishTitle))
            {
                this.englishTitle = BingTranslator.Translate(this.title, "id", "en");
            }

            if (String.IsNullOrEmpty(this.englishContent))
            {
                this.englishContent = BingTranslator.Translate(this.content, "id", "en");
            }
        }