public async Task <WriterResult> UpdateTheme(string userId, SiteTheme theme)
        {
            try
            {
                using (var context = DataContextFactory.CreateContext())
                {
                    var user = context.Users
                               .Include(u => u.Settings)
                               .FirstOrDefault(x => x.Id == userId);
                    if (user == null)
                    {
                        return(new WriterResult(false, "User not found."));
                    }

                    user.Settings.Theme = theme;
                    await context.SaveChangesAsync().ConfigureAwait(false);
                }

                return(new WriterResult(true, "Successfully updated theme."));
            }
            catch (Exception)
            {
                return(new WriterResult(false));
            }
        }
示例#2
0
        public ActionResult Create(string fileTitle, HttpPostedFileBase fileUpload)
        {
            if (fileUpload != null && fileUpload.ContentLength > 0 && fileTitle.Trim().Length > 0)
            {
                string fileExtension = System.IO.Path.GetExtension(fileUpload.FileName);
                if (fileExtension != ".css")
                {
                    return(RedirectToAction("Index"));
                }

                var fileName = fileUpload.FileName;
                var theme    = new SiteTheme()
                {
                    Name = fileTitle,
                    Url  = string.Format("~/Content/Themes/{0}", fileName)
                };

                var fileLocation = System.IO.Path.Combine(Server.MapPath("~/Content/Themes/"), fileName);
                if (System.IO.File.Exists(fileLocation))
                {
                    System.IO.File.Delete(fileLocation);
                }

                fileUpload.SaveAs(fileLocation);

                db.SiteThemes.Add(theme);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
示例#3
0
 protected ViewResult ThemeView(IView view, object model = null, SiteTheme theme = SiteTheme.None)
 {
     var viewModel = model ?? new BaseViewModel();
     switch (theme)
     {
         case SiteTheme.None:
             theme = GetTheme();
             return View(string.Format("/App_Themes/{0}/Views/{1}/{2}.cshtml", theme, RouteData.Values["controller"], view), viewModel);
         default:
             return View(string.Format("/BaseViews/{0}.cshtml", view), viewModel);
     }
 }
示例#4
0
        public static SiteTheme DetectTheme(HttpContextBase context)
        {
            string    themeCookie = context.Request.Cookies[THEME_COOKIE_NAME]?.Value;
            SiteTheme theme       = SiteTheme.Dark;

            if (!string.IsNullOrEmpty(themeCookie))
            {
                Enum.TryParse(themeCookie, out theme);
            }

            return(theme);
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="db"></param>
        private static void ImportThemes(ApplicationDbContext db)
        {
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(System.IO.Path.Combine(HttpContext.Current.Server.MapPath(importDirectory), "SiteThemes.xml"));
            XmlNodeList defaults = xmldoc.GetElementsByTagName("defaults");

            foreach (XmlNode node in defaults)
            {
                SiteTheme t = new SiteTheme()
                {
                    Name = node["Key"].InnerText,
                    Url  = node["Url"].InnerText
                };
                db.SiteThemes.Add(t);
                db.SaveChanges();
            }
        }
示例#6
0
 public Theme(SiteTheme st)
 {
     _siteTheme = st;
 }
示例#7
0
 // GET api/themes/5
 public string GetUrl(int id)
 {
     return(Url.Content(SiteTheme.Get(id).Url));
 }
示例#8
0
 public Theme(SiteTheme st)
 {
     Value = st;
 }