Example #1
0
        public static string GetUserManagerEmail(this IIdentity identity)
        {
            WebProjectUserManager userManager = HttpContext.Current.GetOwinContext().GetUserManager <WebProjectUserManager>();
            User user = userManager.FindById(HttpContext.Current.User.Identity.GetUserId());

            if (user != null)
            {
                return(user.DirectManagerEmail);
            }
            return("");
        }
Example #2
0
        public static WebProjectUserManager Create(
            IdentityFactoryOptions <WebProjectUserManager> options,
            IOwinContext context)
        {
            WebProjectDbContext   dbContext   = context.Get <WebProjectDbContext>();
            WebProjectUserManager userManager = new WebProjectUserManager(new UserStore <User>(dbContext));

            userManager.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 6,
            };
            userManager.UserValidator = new UserValidator <User>(userManager)
            {
                AllowOnlyAlphanumericUserNames = true,
                RequireUniqueEmail             = true
            };

            return(userManager);
        }
Example #3
0
        public void PerformInitialSetup(WebProjectDbContext context)
        {
            WebProjectUserManager userMgr = new WebProjectUserManager(new UserStore <User>(context));
            WebProjectRoleManager roleMgr = new WebProjectRoleManager(new RoleStore <Role>(context));

            string roleName    = "Admin";
            string managerRole = "Manager";

            string userName = "******";
            string password = "******";
            string email    = "*****@*****.**";
            string fullName = "testadmin fullname";

            string userName1 = "manager";
            string password1 = "123456";
            string email1    = "*****@*****.**";
            string fullName1 = "testManager DisplayName";

            string userName2 = "test";
            string password2 = "123456";
            string email2    = "*****@*****.**";
            string fullName2 = "testuser fullname";

            if (!roleMgr.RoleExists(roleName))
            {
                roleMgr.Create(new Role(roleName));
            }
            if (!roleMgr.RoleExists(managerRole))
            {
                roleMgr.Create(new Role(managerRole));
            }

            User user = userMgr.FindByName(userName);

            if (user == null)
            {
                User localUser = new User();
                localUser.UserName           = userName;
                localUser.Email              = email;
                localUser.FullName           = fullName;
                localUser.DirectManagerEmail = email;

                userMgr.Create(localUser, password);
                user = userMgr.FindByName(userName);
            }

            if (!userMgr.IsInRole(user.Id, roleName))
            {
                userMgr.AddToRole(user.Id, roleName);
            }
            if (!userMgr.IsInRole(user.Id, managerRole))
            {
                userMgr.AddToRole(user.Id, managerRole);
            }

            User user1 = userMgr.FindByName(userName1);

            if (user1 == null)
            {
                User localUser = new User();
                localUser.UserName           = userName1;
                localUser.Email              = email1;
                localUser.FullName           = fullName1;
                localUser.DirectManagerEmail = email;

                userMgr.Create(localUser, password1);
                user1 = userMgr.FindByName(userName1);
            }

            if (!userMgr.IsInRole(user1.Id, managerRole))
            {
                userMgr.AddToRole(user1.Id, managerRole);
            }

            User user2 = userMgr.FindByName(userName2);

            if (user2 == null)
            {
                User localUser = new User();
                localUser.UserName           = userName2;
                localUser.Email              = email2;
                localUser.FullName           = fullName2;
                localUser.DirectManagerEmail = email1;

                userMgr.Create(localUser, password2);
            }

            //Add a new WorkingTime object to the new created Database
            WorkingTime workingTime = new WorkingTime();

            workingTime.StartTime           = new DateTime(2000, 1, 1, 9, 0, 0);
            workingTime.EndTime             = new DateTime(2000, 1, 1, 18, 0, 0);
            workingTime.LunchBreakStartTime = new DateTime(2000, 1, 1, 12, 0, 0);
            workingTime.LunchBreakEndTime   = new DateTime(2000, 1, 1, 13, 0, 0);
            context.WorkingTimes.Add(workingTime);
            context.SaveChanges();

            //Initialize a new CompanyVacationPolicy object
            CompanyVacationPolicy companyVacationPolicy = new CompanyVacationPolicy();

            companyVacationPolicy.AnnualLeaveInitialDays = 10;
            companyVacationPolicy.AnnualLeaveMaxDays     = 20;
            context.CompanmyVacationPolicies.Add(companyVacationPolicy);
            context.SaveChanges();

            //Initialize MeetingRooms when it create the new database
            MeetingRoom meetingRoom1 = new MeetingRoom();

            meetingRoom1.Id   = "1";
            meetingRoom1.Name = "会议室一";
            meetingRoom1.IsHaveingProjector  = true;
            meetingRoom1.IsHaveingProjector  = true;
            meetingRoom1.IsHavingVideoDevice = true;
            meetingRoom1.IsHavingVoiceDevice = true;
            MeetingRoom meetingRoom2 = new MeetingRoom();

            meetingRoom2.Id   = "2";
            meetingRoom2.Name = "会议室二";
            meetingRoom2.IsHaveingProjector  = true;
            meetingRoom2.IsHaveingProjector  = true;
            meetingRoom2.IsHavingVideoDevice = false;
            meetingRoom2.IsHavingVoiceDevice = true;
            MeetingRoom meetingRoom3 = new MeetingRoom();

            meetingRoom3.Id   = "3";
            meetingRoom3.Name = "会议室三";
            meetingRoom3.IsHaveingProjector  = true;
            meetingRoom3.IsHaveingProjector  = true;
            meetingRoom3.IsHavingVideoDevice = true;
            meetingRoom3.IsHavingVoiceDevice = false;
            context.MeetingRooms.Add(meetingRoom1);
            context.MeetingRooms.Add(meetingRoom2);
            context.MeetingRooms.Add(meetingRoom3);
            context.SaveChanges();
        }