예제 #1
0
        private async Task AddLogAsync(string message, string detail = "", LogType type = LogType.Info, string source = "")
        {
            if (!Engine.Services.Installed)
            {
                return;
            }

            if (Engine.Configuration.LogLevel == LogLevel.None)
            {
                return;
            }

            switch (type)
            {
            case LogType.Error:
                if (Engine.Configuration.LogLevel >= LogLevel.None)
                {
                    return;
                }
                break;

            case LogType.Warning:
                if (Engine.Configuration.LogLevel >= LogLevel.Error)
                {
                    return;
                }
                break;

            case LogType.Info:
                if (Engine.Configuration.LogLevel >= LogLevel.Warning)
                {
                    return;
                }
                break;

            default:
                if (Engine.Configuration.LogLevel >= LogLevel.Information)
                {
                    return;
                }
                break;
            }

            string userId = null;

            if (Engine.Account != null)
            {
                userId = Engine.Account.GetLocalUserId();
            }

            string url = null;

            if (_contextAccessor.HttpContext != null)
            {
                url = _contextAccessor.HttpContext.GetSiteUrl(true, true);
            }

            using (HoodDbContext context = _hoodDbContext)
            {
                Log log = new Log()
                {
                    Type      = type,
                    Source    = source,
                    Detail    = detail,
                    Time      = DateTime.UtcNow,
                    Title     = message,
                    UserId    = userId,
                    SourceUrl = url
                };
                context.Logs.Add(log);
                await context.SaveChangesAsync();
            }
        }
예제 #2
0
 public virtual async Task UpdateUserAsync(ApplicationUser user)
 {
     _db.Update(user);
     await _db.SaveChangesAsync();
 }
예제 #3
0
        public async Task <PropertyListing> AddAsync(PropertyListing property)
        {
            _db.Properties.Add(property);
            await _db.SaveChangesAsync();

            return(property);
        }
예제 #4
0
        public async Task <Content> AddAsync(Content content)
        {
            // create the slug
            KeyGenerator generator = new KeyGenerator();

            content.Slug = generator.UrlSlug();
            while (await SlugExists(content.Slug))
            {
                content.Slug = generator.UrlSlug();
            }

            _db.Content.Add(content);
            await _db.SaveChangesAsync();

            content = await GetContentByIdAsync(content.Id);
            await RefreshMetasAsync(content);

            _eventService.TriggerContentChanged(this);
            return(content);
        }