Beispiel #1
0
        private void createRolesandUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));


            // In Startup iam creating first Admin Role and creating a default Admin User
            if (!roleManager.RoleExists("Admin"))
            {
                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

                //Here we create a Admin super user who will maintain the website

                var user = new ApplicationUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";

                string userPWD = "Saddam";

                var chkUser = UserManager.Create(user, userPWD);

                //Add default User to Role Admin
                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");
                }
            }
        }
Beispiel #2
0
        private void createRolesandUsers(string username, string userType)
        {
            ApplicationDbContext context = new ApplicationDbContext();

            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));


            if (!roleManager.RoleExists("Employee") && userType == "1")
            {
                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Employee";
                roleManager.Create(role);
            }
            if (!roleManager.RoleExists("Customer") && userType == "2")
            {
                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Customer";
                roleManager.Create(role);
            }
            string s;

            if (userType == "1")
            {
                s = "Employee";
            }
            else
            {
                s = "Customer";
            }
            var result1 = UserManager.AddToRole(username, s);
        }
Beispiel #3
0
        public IIdentityManagerService Create()
        {
#if USE_INT_PRIMARYKEY
            var db      = new IdentityDbContext <CustomUser, CustomRole, int, CustomUserLogin, CustomUserRole, CustomUserClaim>(connString);
            var store   = new UserStore <CustomUser, CustomRole, int, CustomUserLogin, CustomUserRole, CustomUserClaim>(db);
            var usermgr = new UserManager <CustomUser, int>(store);
            usermgr.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 3
            };

            var rolestore = new RoleStore <CustomRole, int, CustomUserRole>(db);
            var rolemgr   = new RoleManager <CustomRole, int>(rolestore);

            var svc     = new Thinktecture.IdentityManager.AspNetIdentity.AspNetIdentityManagerService <CustomUser, int, CustomRole, int>(usermgr, rolemgr);
            var dispose = new DisposableIdentityManagerService(svc, db);
            return(dispose);
#else
            var db        = new IdentityDbContext <IdentityUser>(this.connString);
            var userstore = new UserStore <IdentityUser>(db);
            var usermgr   = new Microsoft.AspNet.Identity.UserManager <IdentityUser>(userstore);
            usermgr.PasswordValidator = new Microsoft.AspNet.Identity.PasswordValidator
            {
                RequiredLength = 3
            };

            var rolestore = new RoleStore <IdentityRole>(db);
            var rolemgr   = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(rolestore);

            var svc     = new Thinktecture.IdentityManager.AspNetIdentity.AspNetIdentityManagerService <IdentityUser, string, IdentityRole, string>(usermgr, rolemgr);
            var dispose = new DisposableIdentityManagerService(svc, db);
            return(dispose);
#endif
        }
Beispiel #4
0
        public ActionResult Create(Order order, Item item, Request request)
        {
            if (ModelState.IsValid)
            {
                order.DateMade = DateTime.Now;

                db.Orders.Add(order);
                db.Items.Add(item);
                db.Requests.Add(request);


                db.SaveChanges();
                db.Items.Remove(item);
                db.SaveChanges();
                return(RedirectToAction("CreateWithVendor"));
            }

            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));

            string Supervisor = roleManager.FindByName("Supervisor").Id;

            ViewBag.StatusID     = new SelectList(db.Statuses.Where(s => s.StatusName == "Pending"), "Id", "StatusName");
            ViewBag.BudgetCodeID = new SelectList(db.BudgetCodes, "Id", "BudgetCodeName");
            ViewBag.EmployeeID   = new SelectList(db.Users.Where(i => i.Email.Equals(HttpContext.User.Identity.Name.ToString())), "ID", "Email");
            ViewBag.SupervisorID = new SelectList(db.Users.Where(u => u.Roles.Any(r => r.RoleId == Supervisor)).ToList(), "ID", "Email");
            return(View(request));
        }
        // GET: Divisions/Create
        public ActionResult CreateDivisionWithSupervisor()
        {
            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));

            string Supervisor = roleManager.FindByName("Supervisor").Id;

            ViewBag.SupervisorID = new SelectList(db.Users.Where(u => u.Roles.Any(r => r.RoleId == Supervisor)).ToList(), "ID", "Email");
            return(View());
        }
Beispiel #6
0
        public AccountController()
        {
            var userStore = new UserStore <ApplicationUser>(new Identity.IdentityDbContext());

            userManager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(userStore);

            var roleStore = new RoleStore <ApplicationRole>(new Identity.IdentityDbContext());

            roleManager = new Microsoft.AspNet.Identity.RoleManager <ApplicationRole>(roleStore);
        }
Beispiel #7
0
        private void CreateRole(WebShopContext context, string roleName)
        {
            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(
                new RoleStore <IdentityRole>(context));

            var result = roleManager.Create(new IdentityRole(roleName));

            if (!result.Succeeded)
            {
                throw new Exception(string.Join(";", result.Errors));
            }
        }
Beispiel #8
0
        public ActionResult AddRole(string RoleName)
        {
            var          roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db));
            IdentityRole role        = new IdentityRole();

            if (!roleManager.RoleExists(RoleName))
            {
                role      = new IdentityRole();
                role.Name = RoleName;
                roleManager.Create(role);
            }
            return(RedirectToAction("CreateRoles"));
        }
        public ActionResult CreateDivisionWithSupervisor(Division division)
        {
            if (ModelState.IsValid)
            {
                db.Divisions.Add(division);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));

            string Supervisor = roleManager.FindByName("Supervisor").Id;

            ViewBag.SupervisorID = new SelectList(db.Users.Where(u => u.Roles.Any(r => r.RoleId == Supervisor)).ToList(), "ID", "Email");
            return(View(division));
        }
Beispiel #10
0
        public void createRole()
        {
            var          manger = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db));
            IdentityRole role   = new IdentityRole();

            if (!manger.RoleExists("Admin"))
            {
                role.Name = "Admin";
                manger.Create(role);
            }
            if (!manger.RoleExists("User"))
            {
                role.Name = "User";
                manger.Create(role);
            }
        }
Beispiel #11
0
        public ActionResult Create()
        {
            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));

            string Supervisor = roleManager.FindByName("Supervisor").Id;

            ViewBag.EmployeeID   = new SelectList(db.Users.Where(i => i.Email.Equals(HttpContext.User.Identity.Name.ToString())), "ID", "Email");
            ViewBag.SupervisorID = new SelectList(db.Employees.Where(u => u.Roles.Any(r => r.RoleId == Supervisor && u.Department.DepartmentName.Equals("STEM"))).ToList(), "ID", "Email");

            ViewBag.BudgetCodeID = new SelectList(db.BudgetCodes, "Id", "BudgetCodeName");
            ViewBag.StatusID     = new SelectList(db.Statuses.Where(s => s.StatusName == "Pending"), "Id", "StatusName");
            ViewBag.CategoryID   = new SelectList(db.Categories, "Id", "CategoryName");


            return(View());
        }
Beispiel #12
0
        private void CreateRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

            if (!roleManager.RoleExists("Admin"))
            {
                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

                var user = new ApplicationUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";

                string userPWD = "HuaTheDogN0se!";

                var chkUser = UserManager.Create(user, userPWD);


                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");
                }
            }

            // creating Creating Manager role
            if (!roleManager.RoleExists("Employee"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Employee";
                roleManager.Create(role);
            }

            // creating Creating Employee role
            if (!roleManager.RoleExists("Customer"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Customer";
                roleManager.Create(role);
            }
        }
Beispiel #13
0
        public ActionResult CreateRole(FormCollection form)
        {
            ViewBag.RoleUyari = "";
            string RoleName    = form["RoleName"];
            var    roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            if (!roleManager.RoleExists(RoleName))
            {
                var role = new IdentityRole(RoleName);
                roleManager.Create(role);
            }
            else
            {
                ViewBag.RoleUyari = "The role you want to add is already registered.";
                return(View());
            }
            return(View());
        }
Beispiel #14
0
        private void CreateRoles()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            if (!roleManager.RoleExists("Visitor"))
            {
                var role = new IdentityRole();
                role.Name = "Visitor";
                roleManager.Create(role);
            }
            if (!roleManager.RoleExists("Admin"))
            {
                var role = new IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);
            }
        }
Beispiel #15
0
        private void createRolesandUsers(string username)
        {
            ApplicationDbContext context = new ApplicationDbContext();

            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));


            // In Startup iam creating first Admin Role and creating a default Admin User
            if (!roleManager.RoleExists("Administrator"))
            {
                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Administrator";
                roleManager.Create(role);
            }
            var result1 = UserManager.AddToRole(username, "Administrator");
        }
Beispiel #16
0
        AspNetIdentityManagerService(UserManager <TUser, TUserKey> userManager, RoleManager <TRole, TRoleKey> roleManager)
        {
            if (userManager == null)
            {
                throw new ArgumentNullException("userManager");
            }
            if (roleManager == null)
            {
                throw new ArgumentNullException("roleManager");
            }

            if (!userManager.SupportsQueryableUsers)
            {
                throw new InvalidOperationException("UserManager must support queryable users.");
            }

            this.userManager = userManager;
            this.roleManager = roleManager;

            if (userManager.UserTokenProvider == null)
            {
                userManager.UserTokenProvider = new TokenProvider <TUser, TUserKey>();
            }

            var keyType = typeof(TUserKey);

            if (keyType == typeof(string))
            {
                ConvertUserSubjectToKey = subject => (TUserKey)ParseString(subject);
            }
            else if (keyType == typeof(int))
            {
                ConvertUserSubjectToKey = subject => (TUserKey)ParseInt(subject);
            }
            else if (keyType == typeof(uint))
            {
                ConvertRoleSubjectToKey = subject => (TRoleKey)ParseUInt32(subject);
            }
            else if (keyType == typeof(long))
            {
                ConvertUserSubjectToKey = subject => (TUserKey)ParseLong(subject);
            }
            else if (keyType == typeof(Guid))
            {
                ConvertUserSubjectToKey = subject => (TUserKey)ParseGuid(subject);
            }
            else
            {
                throw new InvalidOperationException("User Key type not supported");
            }

            keyType = typeof(TRoleKey);
            if (keyType == typeof(string))
            {
                ConvertRoleSubjectToKey = subject => (TRoleKey)ParseString(subject);
            }
            else if (keyType == typeof(int))
            {
                ConvertRoleSubjectToKey = subject => (TRoleKey)ParseInt(subject);
            }
            else if (keyType == typeof(uint))
            {
                ConvertRoleSubjectToKey = subject => (TRoleKey)ParseUInt32(subject);
            }
            else if (keyType == typeof(long))
            {
                ConvertRoleSubjectToKey = subject => (TRoleKey)ParseLong(subject);
            }
            else if (keyType == typeof(Guid))
            {
                ConvertRoleSubjectToKey = subject => (TRoleKey)ParseGuid(subject);
            }
            else
            {
                throw new InvalidOperationException("Role Key type not supported");
            }
        }
        protected override void  Seed(TrainerClientADOnet.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.


            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Admin"
                };

                manager.Create(role);
            }



            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <ApplicationUser>(context);
                var manager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(store);
                var user    = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**"
                };

                manager.Create(user, "Teodora!1");
                context.Users.Add(user);
                manager.AddToRole(user.Id, "Admin");
            }


            //   if (!context.Roles.Any(u => u.Name == "Trener"))
            //   {
            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <ApplicationUser>(context);
                var manager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(store);
                var user    = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**"
                };

                manager.Create(user, "Teodora!1");
                context.Users.Add(user);
                manager.AddToRole(user.Id, "Trener");
            }
            //  }



            if (!context.Roles.Any(u => u.Name == "Trener"))
            {
                if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
                {
                    var store   = new UserStore <ApplicationUser>(context);
                    var manager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(store);
                    var user    = new ApplicationUser {
                        UserName = "******", Email = "*****@*****.**"
                    };

                    manager.Create(user, "Teodora!1");
                    context.Users.Add(user);
                    manager.AddToRole(user.Id, "Trener");
                }
            }

            /////////////////////
            ///

            if (!context.Roles.Any(r => r.Name == "Klijent"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Klijent"
                };

                manager.Create(role);
            }



            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <ApplicationUser>(context);
                var manager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(store);
                var user    = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**"
                };

                manager.Create(user, "Teodora!1");
                context.Users.Add(user);
                manager.AddToRole(user.Id, "Klijent");
            }
        }