Exemplo n.º 1
0
        public async Task <CurrentSiteModel> CurrentSiteAsync()
        {
            var currentSite = await _cacheManager.GetOrSetAsync(CacheKeys.CurrentSite("Default"), () =>
                                                                _dbContext.Sites.FirstOrDefaultAsync(x => x.Name == "Default"));

            return(new CurrentSiteModel
            {
                Id = currentSite.Id,
                Name = currentSite.Name,
                Title = currentSite.Title,
                Theme = currentSite.PublicTheme,
                CssPublic = currentSite.PublicCss,
                CssAdmin = currentSite.AdminCss,
                Language = currentSite.Language,
                Privacy = Markdown.ToHtml(currentSite.Privacy),
                Terms = Markdown.ToHtml(currentSite.Terms),
                HeadScript = currentSite.HeadScript
            });
        }
Exemplo n.º 2
0
        public async Task UpdateAsync(UpdateSite command)
        {
            await _updateValidator.ValidateCommandAsync(command);

            var site = await _dbContext.Sites
                       .FirstOrDefaultAsync(x =>
                                            x.Id == command.SiteId);

            if (site == null)
            {
                throw new DataException($"Site with Id {command.SiteId} not found.");
            }

            site.UpdateDetails(command.Title,
                               command.Theme,
                               command.Css,
                               command.Language,
                               command.Privacy,
                               command.Terms,
                               command.HeadScript);

            _dbContext.Events.Add(new Event(site.Id,
                                            command.UserId,
                                            EventType.Updated,
                                            typeof(Site),
                                            site.Id,
                                            new
            {
                site.Title,
                site.PublicTheme,
                site.PublicCss,
                site.Language,
                site.Privacy,
                site.Terms,
                site.HeadScript
            }));

            await _dbContext.SaveChangesAsync();

            _cacheManager.Remove(CacheKeys.CurrentSite(site.Name));
        }