Beispiel #1
0
        // GET: Admin/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            // ApplicationUser applicationUser = db.ApplicationUsers.Find(id);
            userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            ApplicationUser applicationUser = userManager.FindById(id);

            if (applicationUser == null)
            {
                return(HttpNotFound());
            }
            // Get a list of roles the user has and put them into a viewbag as roles
            // along with a list of roles the user doesn't have, as noRoles
            var usrMgr   = new LogicLayer.UserManager();
            var allRoles = usrMgr.RetrieveEmployeeRoles();

            var roles   = userManager.GetRoles(id);
            var noRoles = allRoles.Except(roles);

            ViewBag.Roles   = roles;
            ViewBag.NoRoles = noRoles;

            return(View(applicationUser));
        }// End Details
Beispiel #2
0
        }// End Configuration()

        protected override void Seed(MVCPresentationLayer.Models.ApplicationDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.

            var userStore   = new UserStore <ApplicationUser>(context);
            var userManager = new UserManager <ApplicationUser>(userStore);

            const string admin         = "*****@*****.**";
            const string adminPassword = "******";

            // Note: There is purposely no using statment for LogicLayer. This is to force
            // programmers to use the fully qulaified name for our internal UserManager, to
            // keep it clear that this is not the Identity systesm UserManager class.
            LogicLayer.UserManager userMgr = new LogicLayer.UserManager();
            var roles = userMgr.RetrieveEmployeeRoles();

            foreach (var role in roles)
            {
                context.Roles.AddOrUpdate(r => r.Name, new IdentityRole()
                {
                    Name = role
                });
            }
            if (!roles.Contains("Administrator"))
            {
                // Note: even though Administrator should be in the list of roles, this check is to
                // remove any risk of it missing due to deletion from the internal database.
                context.Roles.AddOrUpdate(r => r.Name, new IdentityRole()
                {
                    Name = "Administrator"
                });
            }

            if (!context.Users.Any(u => u.UserName == admin))
            {
                var user = new ApplicationUser()
                {
                    UserName   = admin,
                    Email      = admin,
                    GivenName  = "Admin",
                    FamilyName = "Company"
                };
                IdentityResult result = userManager.Create(user, adminPassword);
                context.SaveChanges(); // updates the database

                if (result.Succeeded)
                {
                    userManager.AddToRole(user.Id, "Administrator");
                    context.SaveChanges();
                }
            }
        }// End Seed()
        protected override void Seed(SandwhichMVC.Models.ApplicationDbContext context)
        {
            var userStore   = new UserStore <ApplicationUser>(context);
            var userManager = new UserManager <ApplicationUser>(userStore);

            const string admin         = "*****@*****.**";
            const string adminPassword = "******";

            LogicLayer.UserManager userMg = new LogicLayer.UserManager();

            var roles = userMg.RetrieveEmployeeRoles();

            foreach (var role in roles)
            {
                context.Roles.AddOrUpdate(r => r.Name, new IdentityRole()
                {
                    Name = role
                });
            }
            if (!roles.Contains("Administrator"))
            {
                context.Roles.AddOrUpdate(r => r.Name, new IdentityRole()
                {
                    Name = "Administrator"
                });
            }

            if (!context.Users.Any(u => u.UserName == admin))
            {
                var user = new ApplicationUser()
                {
                    UserName   = admin,
                    Email      = admin,
                    GivenName  = "Admin",
                    FamilyName = "Company"
                };


                IdentityResult result = userManager.Create(user, adminPassword);
                context.SaveChanges();

                if (result.Succeeded)
                {
                    userManager.AddToRole(user.Id, "Administrator");
                    context.SaveChanges();
                }
            }
        }
Beispiel #4
0
        // GET: Admin/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            ApplicationUser applicationUser = userManager.FindById(id);

            if (applicationUser == null)
            {
                return(HttpNotFound());
            }
            var userMang = new LogicLayer.UserManager();
            var allRoles = userMang.RetrieveEmployeeRoles();

            var roles   = userManager.GetRoles(id);
            var noRoles = allRoles.Except(roles);

            ViewBag.Roles   = roles;
            ViewBag.NoRoles = noRoles;

            return(View(applicationUser));
        }