Пример #1
0
        public ActionResult Edit(string subName)
        {
            var sub = _subDao.GetSubByName(subName);

            if (sub == null)
            {
                throw new NotFoundException();
            }

            if (!_permissionDao.CanUserManageSubStyles(_userContext.CurrentUser, sub.Id))
            {
                throw new UnauthorizedException();
            }

            var model = new StylesEditModel();

            model.Sub = sub;
            model.StyledEnabledForUser = _userContext.CurrentUser.EnableStyles;

            if (Request.Cookies.ContainsKey("preview-" + sub.Name.ToLower()))
            {
                var preview = HttpContext.Session.Get <StylesPreviewModel>("preview-" + sub.Name.ToLower());
                if (preview != null)
                {
                    _mapper.Map(preview, model);
                    return(View(model));
                }
            }

            var styles = _subStylesDao.GetStylesForSub(sub.Id);

            if (styles == null)
            {
                styles         = new SubCss();
                styles.CssType = CssType.None;
            }

            _mapper.Map(styles, model);

            return(View(model));
        }
Пример #2
0
        public IViewComponentResult Invoke(string subName)
        {
            // the user doesn't want to see any styles!
            if (_userContext.CurrentUser != null && !_userContext.CurrentUser.EnableStyles)
            {
                return(Content(string.Empty));
            }

            var sub = _subDao.GetSubByName(subName);

            if (sub == null)
            {
                return(Content(string.Empty));
            }

            var isPreviewing = false;

            var header = Request.Headers.ContainsKey(HeaderNames.SetCookie);

            if (ViewContext.HttpContext.Response.Headers.ContainsKey(HeaderNames.SetCookie))
            {
                var setCookie = ViewContext.HttpContext.Response.Headers[HeaderNames.SetCookie];
                foreach (var value in setCookie)
                {
                    if (!string.IsNullOrEmpty(value))
                    {
                        if (value.Contains($"preview-{sub.Name.ToLower()}=;"))
                        {
                            isPreviewing = true;
                            break;
                        }
                    }
                }
            }
            else if (Request.Cookies.ContainsKey($"preview-{sub.Name.ToLower()}"))
            {
                isPreviewing = true;
            }

            if (isPreviewing)
            {
                var preview = HttpContext.Session.Get <StylesPreviewModel>($"preview-{sub.Name.ToLower()}");
                if (preview != null)
                {
                    ViewBag.IsPreview            = true;
                    ViewBag.PreviewStylesSubName = sub.Name;

                    return(View(_mapper.Map <StylesPreviewModel, SubCss>(preview)));
                }
            }

            var styles = _subCssDao.GetStylesForSub(sub.Id);

            if (styles == null)
            {
                return(Content(string.Empty));
            }

            ViewBag.IsPreview = false;
            return(View(styles));
        }