// GET ----------------------------------------------------------------------
 public async Task <IEnumerable <T> > GetObjectsAsync()
 {
     using (var context = new ObjectDbContext())
     {
         return(await context.Set <T>().AsNoTracking().ToListAsync());
     }
 }
Example #2
0
        // private static async Task SeedMenuAsync(
        //     ObjectDbContext dbContext,
        //     RoleManager<ApplicationRole> roleManager)
        // {
        //     var menuDbSet = dbContext.Set<Menu>();

        //     if (!await menuDbSet.AnyAsync())
        //     {
        //         string adminRole = "Administrators";
        //         ApplicationRole role = await roleManager.FindByNameAsync(adminRole);

        //         if (role != null)
        //         {
        //             DateTime utcNow = DateTime.UtcNow;

        //             IEnumerable<Menu> menus = new List<Menu>
        //             {
        //                 new Menu
        //                 {
        //                     Title = "Dashboard",
        //                     Url = "/admin/dashboard",
        //                     Icon = "fa fa-dashboard",
        //                     Priority = 1,
        //                     Active = true,
        //                     RoleMenus = new List<ApplicationRoleMenu>
        //                     {
        //                         new ApplicationRoleMenu
        //                         {
        //                             Role = role,
        //                             Permission = (int)Permission.Full,
        //                             CreatedOnUtc = utcNow
        //                         }
        //                     }
        //                 },
        //                 new Menu
        //                 {
        //                     Title = "Users",
        //                     Icon = "fa fa-users",
        //                     Priority = 10,
        //                     Active = true,
        //                     RoleMenus = new List<ApplicationRoleMenu>
        //                     {
        //                         new ApplicationRoleMenu
        //                         {
        //                             Role = role,
        //                             Permission = (int)Permission.Full,
        //                             CreatedOnUtc = utcNow
        //                         }
        //                     },
        //                     SubMenus = new List<Menu>
        //                     {
        //                         new Menu
        //                         {
        //                             Title = "Users",
        //                             Url = "/admin/user",
        //                             Icon = "fa fa-circle-o",
        //                             Priority = 1,
        //                             Active = true,
        //                             RoleMenus = new List<ApplicationRoleMenu>
        //                             {
        //                                 new ApplicationRoleMenu
        //                                 {
        //                                     Role = role,
        //                                     Permission = (int)Permission.Full,
        //                                     CreatedOnUtc = utcNow
        //                                 }
        //                             }
        //                         },
        //                         new Menu
        //                         {
        //                             Title = "User Roles",
        //                             Url = "/admin/role",
        //                             Icon = "fa fa-circle-o",
        //                             Priority = 2,
        //                             Active = true,
        //                             RoleMenus = new List<ApplicationRoleMenu>
        //                             {
        //                                 new ApplicationRoleMenu
        //                                 {
        //                                     Role = role,
        //                                     Permission = (int)Permission.Full,
        //                                     CreatedOnUtc = utcNow
        //                                 }
        //                             }
        //                         },
        //                         new Menu
        //                         {
        //                             Title = "Access Control List",
        //                             Url = "/admin/acl",
        //                             Icon = "fa fa-circle-o",
        //                             Priority = 3,
        //                             Active = true,
        //                             RoleMenus = new List<ApplicationRoleMenu>
        //                             {
        //                                 new ApplicationRoleMenu
        //                                 {
        //                                     Role = role,
        //                                     Permission = (int)Permission.Full,
        //                                     CreatedOnUtc = utcNow
        //                                 }
        //                             }
        //                         }
        //                     }
        //                 },
        //                 new Menu
        //                 {
        //                     Title = "Configuration",
        //                     Icon = "fa fa-gears",
        //                     Priority = 30,
        //                     Active = true,
        //                     RoleMenus = new List<ApplicationRoleMenu>
        //                     {
        //                         new ApplicationRoleMenu
        //                         {
        //                             Role = role,
        //                             Permission = (int)Permission.Full,
        //                             CreatedOnUtc = utcNow
        //                         }
        //                     },
        //                     SubMenus = new List<Menu>
        //                     {
        //                         new Menu
        //                         {
        //                             Title = "Email Accounts",
        //                             Url = "/admin/emailaccount",
        //                             Icon = "fa fa-circle-o",
        //                             Priority = 1,
        //                             Active = true,
        //                             RoleMenus = new List<ApplicationRoleMenu>
        //                             {
        //                                 new ApplicationRoleMenu
        //                                 {
        //                                     Role = role,
        //                                     Permission = (int)Permission.Full,
        //                                     CreatedOnUtc = utcNow
        //                                 }
        //                             }
        //                         }
        //                     }
        //                 },
        //                 new Menu
        //                 {
        //                     Title = "System",
        //                     Icon = "fa fa-cubes",
        //                     Priority = 40,
        //                     Active = true,
        //                     RoleMenus = new List<ApplicationRoleMenu>
        //                     {
        //                         new ApplicationRoleMenu
        //                         {
        //                             Role = role,
        //                             Permission = (int)Permission.Full,
        //                             CreatedOnUtc = utcNow
        //                         }
        //                     },
        //                     SubMenus = new List<Menu>
        //                     {
        //                         new Menu
        //                         {
        //                             Title = "Menus",
        //                             Url = "/admin/menu",
        //                             Icon = "fa fa-circle-o",
        //                             Priority = 1,
        //                             Active = true,
        //                             RoleMenus = new List<ApplicationRoleMenu>
        //                             {
        //                                 new ApplicationRoleMenu
        //                                 {
        //                                     Role = role,
        //                                     Permission = (int)Permission.Full,
        //                                     CreatedOnUtc = utcNow
        //                                 }
        //                             }
        //                         },
        //                         new Menu
        //                         {
        //                             Title = "Log",
        //                             Url = "/admin/log",
        //                             Icon = "fa fa-circle-o",
        //                             Priority = 2,
        //                             Active = true,
        //                             RoleMenus = new List<ApplicationRoleMenu>
        //                             {
        //                                 new ApplicationRoleMenu
        //                                 {
        //                                     Role = role,
        //                                     Permission = (int)Permission.Full,
        //                                     CreatedOnUtc = utcNow
        //                                 }
        //                             }
        //                         }
        //                     }
        //                 }

        //             };

        //             await menuDbSet.AddRangeAsync(menus);

        //             await dbContext.SaveChangesAsync();
        //         }
        //     }
        // }

        private static async Task SeedEmailAccountAsync(ObjectDbContext dbContext)
        {
            string email    = "*****@*****.**";
            string password = "******";

            var emailAccountDbSet = dbContext.Set <EmailAccount>();

            if (!await emailAccountDbSet.AnyAsync(e => e.Email == email))
            {
                await emailAccountDbSet.AddAsync(new EmailAccount
                {
                    Email                 = email,
                    DisplayName           = "No Reply",
                    Host                  = "smtp.gmail.com",
                    Port                  = 587,
                    UserName              = email,
                    Password              = password,
                    EnableSsl             = false,
                    UseDefaultCredentials = true,
                    IsDefaultEmailAccount = true
                });

                await dbContext.SaveChangesAsync();
            }
        }
 // ADD ----------------------------------------------------------------------
 public async Task AddObjectAsync(T obj)
 {
     using (var context = new ObjectDbContext())
     {
         context.Set <T>().Add(obj);
         await context.SaveChangesAsync();
     }
 }
 // UPDATE -------------------------------------------------------------------
 public async Task UpdateObjectAsync(T obj)
 {
     using (var context = new ObjectDbContext())
     {
         context.Set <T>().Add(obj);
         context.SaveChanges();
     }
 }
 // DELETE
 public async Task DeleteObjectAsync(T obj)
 {
     using (var context = new ObjectDbContext())
     {
         context.Set <T>().Remove(obj);
         context.SaveChanges();
     }
 }
        // UPDATE ALL OBJECTS -------------------------------------------------------
        public async Task UpdateObjectsAsync(List <T> objects)
        {
            using (var context = new ObjectDbContext())
            {
                foreach (T obj in objects)
                {
                    context.Set <T>().Add(obj);
                    context.SaveChanges();
                }

                context.SaveChanges();
            }
        }
        public override void Load()
        {
            var builder = new DbContextOptionsBuilder<ObjectDbContext>();
            OptionsAction(builder);

            using (var dbContext = new ObjectDbContext(builder.Options))
            {
                dbContext.Database.EnsureCreated();
                var settings = dbContext.Set<Setting>();

                Data = !settings.Any()
                    ? new SeedDataSettings().EnsurePopulated(dbContext)
                    : settings.ToDictionary(s => s.Name, s => s.Value);
            }
        }
Example #8
0
        private static async Task Initialize(
            ObjectDbContext dbContext,
            RoleManager <ApplicationRole> roleManager,
            UserManager <ApplicationUser> userManager)
        {
            await dbContext.Database.EnsureCreatedAsync();

            await SeedIdentityAsync(roleManager, userManager);

            await SeedEmailAccountAsync(dbContext);

            await SeedActivityLogTypeAsync(dbContext);

            //await SeedMenuAsync(dbContext, roleManager);
        }
Example #9
0
        public IDictionary<string, string> EnsurePopulated(ObjectDbContext dbContext)
        {
            IDictionary<string, string> configSettings = new Dictionary<string, string>
            {
                { "cache.memory.minutes", (60 * 2).ToString() },
                { "cache.session.timeout", "20" },
                // SMTP.
                { "smtp.server", "smtp.gmail.com" },
                { "smtp.port", "587" },
                { "smtp.user", "*****@*****.**" },
                { "smtp.alias", "APEX-NoReply" },
                { "smtp.password", "******" },
                { "smtp.usessl", "true" },
                { "smtp.requiresauthentication", "true" },
                { "smtp.preferredencoding", string.Empty }
            };

            dbContext.Set<Setting>().AddRange(
                configSettings.Select(kvp => new Setting { Name = kvp.Key, Value = kvp.Value }));

            dbContext.SaveChanges();

            return configSettings;
        }
Example #10
0
 public ActivityLogService(
     ObjectDbContext dbContext,
     IActivityLogTypeService activityLogTypeService) : base(dbContext)
 {
     _activityLogTypeService = activityLogTypeService;
 }
Example #11
0
        private static async Task SeedActivityLogTypeAsync(ObjectDbContext dbContext)
        {
            var activityLogTypeDbSet = dbContext.Set <ActivityLogType>();

            if (!await activityLogTypeDbSet.AnyAsync())
            {
                await activityLogTypeDbSet.AddRangeAsync(new ActivityLogType[]
                {
                    new ActivityLogType
                    {
                        SystemKeyword = Apex.Services.Constants.SystemKeyword.UpdateActivityLogTypes,
                        Name          = "Update an Activity Log Type",
                        Enabled       = true
                    },
                    new ActivityLogType
                    {
                        SystemKeyword = Apex.Services.Constants.SystemKeyword.CreateEmailAccounts,
                        Name          = "Add a new Email Account",
                        Enabled       = true
                    },
                    new ActivityLogType
                    {
                        SystemKeyword = Apex.Services.Constants.SystemKeyword.UpdateEmailAccounts,
                        Name          = "Update an Email Account",
                        Enabled       = true
                    },
                    new ActivityLogType
                    {
                        SystemKeyword = Apex.Services.Constants.SystemKeyword.DeleteEmailAccounts,
                        Name          = "Delete an Email Account",
                        Enabled       = true
                    },
                    new ActivityLogType
                    {
                        SystemKeyword = Apex.Services.Constants.SystemKeyword.CreateUsers,
                        Name          = "Add a new User",
                        Enabled       = true
                    },
                    new ActivityLogType
                    {
                        SystemKeyword = Apex.Services.Constants.SystemKeyword.UpdateUsers,
                        Name          = "Update an User",
                        Enabled       = true
                    },
                    new ActivityLogType
                    {
                        SystemKeyword = Apex.Services.Constants.SystemKeyword.DeleteUsers,
                        Name          = "Delete an User",
                        Enabled       = true
                    },
                    new ActivityLogType
                    {
                        SystemKeyword = Apex.Services.Constants.SystemKeyword.ResetPasswordUsers,
                        Name          = "Reset password of an User",
                        Enabled       = true
                    }
                });

                await dbContext.SaveChangesAsync();
            }
        }
Example #12
0
 public BlobService(ObjectDbContext dbContext)
     : base(dbContext)
 {
 }
Example #13
0
 public FunctionService(ObjectDbContext dbContext)
     : base(dbContext)
 {
 }
Example #14
0
 public EmailAccountService(
     ObjectDbContext dbContext,
     IMemoryCacheService memoryCacheService) : base(dbContext)
 {
     _memoryCacheService = memoryCacheService;
 }
Example #15
0
 public ActivityLogTypeService(
     ObjectDbContext dbContext,
     IMemoryCacheService memoryCacheService) : base(dbContext)
 {
     _memoryCacheService = memoryCacheService;
 }
Example #16
0
 public LogService(ObjectDbContext dbContext)
     : base(dbContext)
 {
 }
Example #17
0
 public QueuedEmailService(ObjectDbContext dbContext)
     : base(dbContext)
 {
 }
Example #18
0
 public void FixtureTearDown()
 {
     CleanupNakedObjectsFramework(this);
     ObjectDbContext.Delete();
 }
Example #19
0
 public BaseService(ObjectDbContext dbContext)
 {
     _dbContext = dbContext;
     _dbSet     = dbContext.Set <T>();
 }