示例#1
0
        private static void SeedIdentity(UserManager <IdentityUser> userManager, SiriusDbContext context)
        {
            var users = SeedUsers(userManager);

            context.SaveChanges();

            var devUser   = users[0]; //Dev
            var adminUser = users[1]; //Admin

            var adminUserRoles = userManager.GetRolesAsync(devUser).Result;

            if (adminUserRoles.Count == 0)
            {
                userManager.AddToRoleAsync(devUser, SiriusEnums.Roles.Dev.ToString()).Wait();
            }

            context.SaveChanges();

            var powerUserRoles = userManager.GetRolesAsync(adminUser).Result;

            if (powerUserRoles.Count == 0)
            {
                userManager.AddToRoleAsync(adminUser, SiriusEnums.Roles.Admin.ToString()).Wait();
            }

            context.SaveChanges();
        }
示例#2
0
        public static void Seed(IServiceProvider serviceProvider, SiriusDbContext context)
        {
            #region Identity

            if (!context.Users.Any())
            {
                //Initializing custom roles
                var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();
                var userManager = serviceProvider.GetRequiredService <UserManager <IdentityUser> >();
                var roleNames   = SiriusHelper.GetStringListFromEnum <SiriusEnums.Roles>();

                foreach (var roleName in roleNames)
                {
                    var roleExist = roleManager.RoleExistsAsync(roleName).Result;
                    if (!roleExist)
                    {
                        //Create the roles and seed them to the database
                        roleManager.CreateAsync(new IdentityRole(roleName)).Wait();
                    }
                }

                context.SaveChanges();

                SeedIdentity(userManager, context);

                SeedSettings(context);
            }

            #endregion

            #region AppSettings

            if (!context.AppSettings.Any())
            {
                var appSettings = new AppSettings
                {
                    AppLogo = InitialAppSettings.ImageData,
                    AppName = InitialAppSettings.AppName,
                    City    = "Hong Kong",
                    Country = new Country {
                        Name = "China", CreationUser = "******", CreationDate = DateTime.Now,
                    }
                };

                context.AppSettings.Add(appSettings);

                context.SaveChanges();
            }

            #endregion
        }
示例#3
0
        public IdentityUser Create(IdentityUser user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_context.Users.Any(x => x.UserName == user.UserName))
            {
                throw new AppException("Username \"" + user.UserName + "\" is already taken");
            }

            CreatePasswordHash(password + SiriusConfiguration.Salt, out var passwordHash);
            user.PasswordHash = Encoding.UTF8.GetString(passwordHash, 0, passwordHash.Length);

            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }
示例#4
0
        /// <summary>
        /// Metodo para salvar usuários
        /// </summary>
        /// <param name="user">objeto do tipo UserEntity que será salvo.</param>
        public void SaveUser(UserEntity user)
        {
            if (user.Id == 0)
            {
                context.Add(user);
            }
            else
            {
                context.Update(user);
            }

            context.SaveChanges();
        }
        /// <summary>
        /// Salva Recusa
        /// </summary>
        /// <param name="customerRf">Objeto do tipo CompanyEntity será salvo </param>
        public void SaveRefusal(CustomerRefusalEntity customerRf)
        {
            if (customerRf.Id == 0)
            {
                context.Add(customerRf);
            }
            else
            {
                context.Update(customerRf);
            }

            context.SaveChanges();
        }
示例#6
0
        /// <summary>
        /// Salvar Contrato Inteligente
        /// </summary>
        /// <param name="contract">Objeto do tipo SmartContract que será salvo.</param>
        public void SaveSmartContract(SmartContractEntity contract)
        {
            if (contract.Id == 0)
            {
                context.Add(contract);
            }
            else
            {
                context.Update(contract);
            }

            context.SaveChanges();
        }
示例#7
0
        /// <summary>
        /// Salva empresa
        /// </summary>
        /// <param name="company">Objeto do tipo CompanyEntity será salvo </param>
        public void SaveCompany(CompanyEntity company)
        {
            if (company.Id == 0)
            {
                context.Add(company);
            }
            else
            {
                context.Update(company);
            }

            context.SaveChanges();
        }
示例#8
0
        public void SaveSign(SmartContractSignedEntity customerSnd)
        {
            if (customerSnd.Id == 0)
            {
                context.Add(customerSnd);
            }
            else
            {
                context.Update(customerSnd);
            }

            context.SaveChanges();
        }
示例#9
0
        public static void SeedSettings(SiriusDbContext context)
        {
            #region Countries

            var countryChina = new Country
            {
                Name         = "China",
                CreationDate = DateTime.Now,
                CreationUser = Constants.SystemSeed,
            };

            if (!context.Countries.Any())
            {
                var countryThailand = new Country
                {
                    Name         = "Thailand",
                    CreationDate = DateTime.Now,
                    CreationUser = Constants.SystemSeed,
                };
                context.Countries.Add(countryChina);
                context.Countries.Add(countryThailand);
            }

            #endregion

            #region TransactionSourceTypes

            if (!context.TransactionSourceTypes.Any())
            {
                var tstBank = new TransactionSourceType
                {
                    Name         = "Bank Account",
                    CreationDate = DateTime.Now,
                    CreationUser = Constants.SystemSeed,
                };
                var tstChurch = new TransactionSourceType
                {
                    Name         = "Church Account",
                    CreationDate = DateTime.Now,
                    CreationUser = Constants.SystemSeed,
                };
                var tstExpense = new TransactionSourceType
                {
                    Name         = "Expenses Account",
                    CreationDate = DateTime.Now,
                    CreationUser = Constants.SystemSeed,
                };
                context.TransactionSourceTypes.Add(tstBank);
                context.TransactionSourceTypes.Add(tstChurch);
                context.TransactionSourceTypes.Add(tstExpense);
            }

            #endregion

            #region AppSettings

            var appSettings = new AppSettings
            {
                AppName      = Constants.AppName,
                AppLogo      = Constants.AppLogo,
                Country      = countryChina,
                City         = "Hong Kong",
                CreationDate = DateTime.Now,
                CreationUser = Constants.SystemSeed,
            };
            context.AppSettings.Add(appSettings);

            #endregion

            #region ExpenseTypes

            var expenseType1 = new ExpenseType
            {
                Name         = "Presents",
                CreationDate = DateTime.Now,
                CreationUser = Constants.SystemSeed,
            };
            var expenseType2 = new ExpenseType
            {
                Name         = "Food",
                CreationDate = DateTime.Now,
                CreationUser = Constants.SystemSeed,
            };
            var expenseType3 = new ExpenseType
            {
                Name         = "Rent",
                CreationDate = DateTime.Now,
                CreationUser = Constants.SystemSeed,
            };
            var expenseType4 = new ExpenseType
            {
                Name         = "Transportation",
                CreationDate = DateTime.Now,
                CreationUser = Constants.SystemSeed,
            };
            var expenseType5 = new ExpenseType
            {
                Name         = "Charity",
                CreationDate = DateTime.Now,
                CreationUser = Constants.SystemSeed,
            };
            var expenseType6 = new ExpenseType
            {
                Name         = "Maintenance",
                CreationDate = DateTime.Now,
                CreationUser = Constants.SystemSeed,
            };
            var expenseType7 = new ExpenseType
            {
                Name         = "Labour",
                CreationDate = DateTime.Now,
                CreationUser = Constants.SystemSeed,
            };
            var expenseType8 = new ExpenseType
            {
                Name         = "Other",
                CreationDate = DateTime.Now,
                CreationUser = Constants.SystemSeed,
            };
            context.ExpenseTypes.Add(expenseType1);
            context.ExpenseTypes.Add(expenseType2);
            context.ExpenseTypes.Add(expenseType3);
            context.ExpenseTypes.Add(expenseType4);
            context.ExpenseTypes.Add(expenseType5);
            context.ExpenseTypes.Add(expenseType6);
            context.ExpenseTypes.Add(expenseType7);
            context.ExpenseTypes.Add(expenseType8);

            #endregion

            context.SaveChanges();
        }
示例#10
0
 public void DeleteCustomerRequest(CustomerRequestEntity customerRequest)
 {
     context.RequestCustomers.Remove(customerRequest);
     context.SaveChanges();
 }
示例#11
0
 public void DeleteCustomer(CustomerEntity customer)
 {
     context.Customers.Remove(customer);
     context.SaveChanges();
 }