示例#1
0
        private void SeedRolesAndUsers(ETCCanadaContext context)
        {
            RoleManager<ApplicationRole> roleManager = new RoleManager<ApplicationRole>(new RoleStore<ApplicationRole>(context));

            if (!roleManager.RoleExists("Administrator"))
            {
                roleManager.Create(new ApplicationRole("Administrator"));
            }

            if (!roleManager.RoleExists("User"))
            {
                roleManager.Create(new ApplicationRole("User"));
            }

            List<ApplicationUser> users = new List<ApplicationUser>();
            ApplicationUser user1 = new ApplicationUser { UserName = "******", Email = "*****@*****.**", FirstName = "Administrator", LastName = "Administrator", IsApproved = true };
            ApplicationUser user2 = new ApplicationUser { UserName = "******", Email = "*****@*****.**", FirstName = "User", LastName = "User", IsApproved = true };
            users.Add(user1);
            users.Add(user2);

            SeedDefaultUser(context, user1, "Administrator");
            SeedDefaultUser(context, user2, "User");

            //http://stackoverflow.com/questions/20470623/asp-net-mvc-asp-net-identity-seeding-roles-and-users
            //http://stackoverflow.com/questions/19280527/mvc5-seed-users-and-roles
            //http://stackoverflow.com/questions/19745286/asp-net-identity-db-seed
        }
示例#2
0
        internal List<Models.Account.ApplicationUserModel> GetShareHoldingSummaryByCreatedUsers()
        {
            using (ETCCanadaContext context = new ETCCanadaContext())
            {
                List<ApplicationUserModel> createdUsersSummary = (from u in context.Users
                                                                  join s in context.Shares on u.Id equals s.CreatedUserId
                                                                  orderby s.PurchasedDateTimeUtc descending
                                                                  group s by s.CreatedUser into groupedShares
                                                                  select new ApplicationUserModel
                                                                  {
                                                                      Id = groupedShares.Key.Id,
                                                                      FirstName = groupedShares.Key.FirstName,
                                                                      LastName = groupedShares.Key.LastName,
                                                                      Email = groupedShares.Key.Email,
                                                                      Country = groupedShares.Key.Country,
                                                                      TotalNumberOfShares = groupedShares.Sum(x => x.NoOfShares),
                                                                      TotalGrossAmountOfShares = groupedShares.Sum(x => x.Amount),
                                                                      LastActivityDate = groupedShares.Max(x => x.PurchasedDateTimeUtc)

                                                                  }).ToList();

                return createdUsersSummary;

            }
        }
示例#3
0
        private bool SeedDefaultUser(ETCCanadaContext context, ApplicationUser user, string role)
        {
            UserManager<ApplicationUser> userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));

            if (userManager.FindByName(user.UserName) == null)
            {
                var result = userManager.Create(user, "123123");

                if (result.Succeeded)
                {
                    userManager.AddToRole(user.Id, role);
                    return true;
                }
            }
            return false;
        }
示例#4
0
 public void Seed(ETCCanadaContext context)
 {
     SeedRolesAndUsers(context);
     //SeedCountries(context);
 }