Beispiel #1
0
        public async Task <bool> IsDatabaseSetUpAsync(string strDefaultConnection)
        {
            var optionsBuilder = new DbContextOptionsBuilder <BlazorBlogsContext>();

            optionsBuilder.UseSqlServer(strDefaultConnection);

            try
            {
                using (var context = new BlazorBlogsContext(optionsBuilder.Options))
                {
                    // If we can get Version Number database is set up
                    var VersionNumber = await context.Settings
                                        // Use AsNoTracking to disable EF change tracking
                                        .AsNoTracking()
                                        .Where(x => x.SettingName.ToLower() == "versionnumber")
                                        .FirstOrDefaultAsync();

                    if (VersionNumber == null)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            catch
            {
                return(false);
            }
        }
Beispiel #2
0
        public async Task <bool> AdminExistsAsync(string strDefaultConnection)
        {
            var optionsBuilder = new DbContextOptionsBuilder <BlazorBlogsContext>();

            optionsBuilder.UseSqlServer(strDefaultConnection);

            using (var context = new BlazorBlogsContext(optionsBuilder.Options))
            {
                // Get Admin Role
                var AdminRoleList = await context.AspNetRoles
                                    // Use AsNoTracking to disable EF change tracking
                                    .AsNoTracking()
                                    .Where(x => x.Name.ToLower() == "Administrators")
                                    .ToListAsync();

                if (AdminRoleList.Count == 0)
                {
                    return(false);
                }

                var AdminRole = AdminRoleList.FirstOrDefault();

                // Get number of users in that role
                var UsersInAdminRole = await context.AspNetUserRoles
                                       // Use AsNoTracking to disable EF change tracking
                                       .AsNoTracking()
                                       .Where(x => x.RoleId == AdminRole.Id)
                                       .CountAsync();

                return(UsersInAdminRole > 0);
            }
        }
Beispiel #3
0
 public BlogsService(BlazorBlogsContext context)
 {
     _context = context;
 }
Beispiel #4
0
 public GeneralSettingsService(BlazorBlogsContext context)
 {
     _context = context;
 }
Beispiel #5
0
 public BlogsService(BlazorBlogsContext context,
                     IWebHostEnvironment environment)
 {
     _context     = context;
     _environment = environment;
 }
Beispiel #6
0
 public EmailService(BlazorBlogsContext context, GeneralSettingsService generalSettingsService)
 {
     _context = context;
     _generalSettingsService = generalSettingsService;
 }
Beispiel #7
0
 public EmailSender(BlazorBlogsContext context, EmailService EmailService, GeneralSettingsService generalSettingsService)
 {
     _context                = context;
     _EmailService           = EmailService;
     _GeneralSettingsService = generalSettingsService;
 }