public ActionResult Edit(Guid id, StyleModel model)
        {
            if (ModelState.IsValid)
            {
                var style = _styleRepo.GetBy(s => s.Id == id);

                style.Css = model.Css;
                _styleRepo.Update(style);

                return Json(new { success = true });
            }

            return PartialView("EditStyleModal", model);
        }
        public ActionResult SaveBlogTemplate(StyleModel model)
        {
            if (ModelState.IsValid)
            {
                var blogTemplate = _styleRepo.GetLatestEditForBlog(CurrentBlog.Id);
                if (CurrentBlog.BlogTemplateId == blogTemplate.Id)
                {
                    if (blogTemplate.Css != model.Css ||
                        blogTemplate.HtmlTemplate != model.HtmlTemplate ||
                        blogTemplate.TemplateMode != model.TemplateMode)
                    {
                        //create a new version
                        _styleRepo.Create(new BlogTemplate
                        {
                            Css = model.Css,
                            HtmlTemplate = model.HtmlTemplate,
                            TemplateMode = model.TemplateMode,
                            LastModified = DateTime.Now,
                            BlogId = CurrentBlog.Id
                        });
                    }
                }
                else
                {

                    blogTemplate.Css = model.Css;
                    blogTemplate.HtmlTemplate = model.HtmlTemplate;
                    blogTemplate.TemplateMode = model.TemplateMode;
                    blogTemplate.LastModified = DateTime.Now;
                    _styleRepo.Update(blogTemplate);
                }

                return Json(new { success = true });
            }

            return Json(new { success = false });
        }
        public ActionResult ApplyBlogTemplate(StyleModel model)
        {
            var currentBlog = _blogRepo.GetCurrentBlog(_httpContext);

            if (ModelState.IsValid)
            {
                var blogTemplate = _styleRepo.GetLatestEditForBlog(currentBlog.Id);
                if (currentBlog.BlogTemplateId == blogTemplate.Id)
                {
                    //no need to apply we already are
                    return Json(new { success = true });
                }

                blogTemplate.Css = model.Css;
                blogTemplate.HtmlTemplate = model.HtmlTemplate;
                blogTemplate.TemplateMode = model.TemplateMode;
                blogTemplate.LastModified = DateTime.Now;
                _styleRepo.Update(blogTemplate);

                currentBlog.BlogTemplateId = blogTemplate.Id;
                _blogRepo.Update(currentBlog);

                return Json(new { success = true });
            }

            return Json(new { success = false });
        }