当前位置: 首页>>代码示例>>C#>>正文


C# UsersContext类代码示例

本文整理汇总了C#中UsersContext的典型用法代码示例。如果您正苦于以下问题:C# UsersContext类的具体用法?C# UsersContext怎么用?C# UsersContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UsersContext类属于命名空间,在下文中一共展示了UsersContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main()
        {
            UsersContext context = new UsersContext();
            context.Database.Initialize(true);
                               
            #region //11.	Get Users by Email Provider
            //Console.WriteLine("Please enter email provider: ");
            //string emailProvider = Console.ReadLine();
            //GetUsersByEmailProvider(context, emailProvider);
            #endregion

            #region // 12.	Count Users with Bigger Pictures
            // Console.WriteLine("Please enter number of pixels: ");
            // int numberOfPixels = int.Parse(Console.ReadLine());
            // int countOfBigPictures = GetCountOfBiggerPictures(context, numberOfPixels);
            // Console.WriteLine($"{countOfBigPictures} users have profile pictures wider than {numberOfPixels} pixels");
            #endregion

            #region // 13.	Remove Inactive Users                
            //Console.WriteLine("Please enter a date: ");
            //string enteredDateString = Console.ReadLine();
            //DateTime enteredDate = DateTime.Parse(enteredDateString); 
            //RemoveInactiveUsers(context, enteredDate);
            #endregion
        }
开发者ID:borko9696,项目名称:SoftwareUniversity,代码行数:25,代码来源:Program.cs

示例2: Activate

        public String Activate(int id, string value, int? rowId,
               int? columnPosition, int? columnId, string columnName)
        {
            using (var db = new UsersContext())
            {

                var account = db.UserProfiles.FirstOrDefault(a => a.UserId == id);
                if (account == null)
                {
                    return "ID 为 " + id + " 的账号不存在";
                }
                switch (columnPosition)
                {
                    case 3:
                        bool activated = (int.Parse(value) == 1);
                        if (!activated)
                            return value;
                       try
                        {
                            var confirmationToken = db.Database.SqlQuery<string>("select ConfirmationToken from webpages_Membership where UserId={0}", new Object[] { id }).Single();
                            if (!WebSecurity.ConfirmAccount(account.UserName, confirmationToken))
                                throw new Exception("账号确认令牌无效");
                        }
                        catch (Exception e)
                        {
                            return "批准账号失败:" + e.Message;
                        }
                        break;
                    default:
                        break;
                }
                return value;
            }
        }
开发者ID:ISTang,项目名称:project_application,代码行数:34,代码来源:AccountController.cs

示例3: Initialize

 public static void Initialize()
 {
     if (!WebSecurityInitializer.isInitialized)
     {
         lock (WebSecurityInitializer.isInitializedSyncObject)
         {
             if (!WebSecurityInitializer.isInitialized)
             {
                 WebSecurityInitializer.isInitialized = true;
                 Database.SetInitializer<UsersContext>(null);
                 try
                 {
                     using (UsersContext context = new UsersContext())
                     {
                         if (!context.Database.Exists())
                         {
                             ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                         }
                     }
                     bool autoCreateTables = true;
                     WebSecurity.InitializeDatabaseConnection("db", "guestservice_UserProfile", "userId", "userName", autoCreateTables);
                 }
                 catch (System.Exception ex)
                 {
                     throw new System.InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                 }
             }
         }
     }
 }
开发者ID:alex-prokopenya,项目名称:GuestService_design,代码行数:30,代码来源:WebSecurityInitializer.cs

示例4: GetAllRoles

 public override string[] GetAllRoles()
 {
     using (var usersContext = new UsersContext())
     {
         return usersContext.Roles.Select(r => r.short_Title).ToArray();
     }
 }
开发者ID:ibadyer,项目名称:seed,代码行数:7,代码来源:CustomRoleProvider.cs

示例5: SimpleMembershipInitializer

			public SimpleMembershipInitializer()
			{
				Database.SetInitializer<UsersContext>(null);

				try
				{
					using (var context = new UsersContext())
					{
						if (!context.Database.Exists())
						{
							// Create the SimpleMembership database without Entity Framework migration schema
							((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
						}
					}

					WebSecurity.InitializeDatabaseConnection(
						"DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
				}
				catch (Exception ex)
				{
					throw new InvalidOperationException(
						"The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", 
						ex);
				}
			}
开发者ID:alexdresko,项目名称:knockout-bootstrap.modal,代码行数:25,代码来源:InitializeSimpleMembershipAttribute.cs

示例6: GetPropertyValues

        public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection)
        {
            using (UsersContext db = new UsersContext())
            {
                SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection();

                string userName = context["UserName"].ToString();
                UserProfile userProfile = db.UsersProfiles.Find(userName);

                if (userProfile == null)
                {
                    foreach (SettingsProperty profileProperty in collection)
                    {
                        SettingsPropertyValue value = new SettingsPropertyValue(collection[profileProperty.Name]);
                        value.PropertyValue = null;
                        settings.Add(value);
                    }
                }

                else

                {

                    foreach (SettingsProperty profileProperty in collection)
                    {
                        SettingsPropertyValue value = new SettingsPropertyValue(collection[profileProperty.Name]);
                        value.PropertyValue = userProfile.GetType().GetProperty(profileProperty.Name).GetValue(userProfile, null);
                        settings.Add(value);
                    }
                }

                return settings;
            }
        }
开发者ID:firsttimedeveloper,项目名称:mvc4gw7,代码行数:34,代码来源:SQLProfileProvider.cs

示例7: GetRolesForUser

 public override string[] GetRolesForUser(string username)
 {
     using (UsersContext db = new UsersContext())
     {
         User user = db.Users.Find(username);
         return user.UserInRoles.Select(x => x.Role).Select(y => y.Name).ToArray();
     }
 }
开发者ID:firsttimedeveloper,项目名称:mvc4gw7,代码行数:8,代码来源:SQLRoleProvider.cs

示例8: GetUsersByEmailProvider

 private static void GetUsersByEmailProvider(UsersContext context, string emailProvider)
 {
     IEnumerable<User> wantedUsers = context.Users.Where(user => user.Email.EndsWith(emailProvider));
     foreach (User wantedUser in wantedUsers)
     {
         Console.WriteLine($"{wantedUser.Username} {wantedUser.Password} - {wantedUser.Age}");
     }
 }   
开发者ID:borko9696,项目名称:SoftwareUniversity,代码行数:8,代码来源:Program.cs

示例9: IsUserInRole

 public override bool IsUserInRole(string username, string roleName)
 {
     var usersContext = new UsersContext();
     var user = usersContext.Users.SingleOrDefault(u => u.UserName == username);
     if (user == null)
         return false;
     return user.UserRoles != null && user.UserRoles.Select(
          u => u.Role).Any(r => r.RoleName == roleName);
 }
开发者ID:ryhoward,项目名称:HackathonAngular,代码行数:9,代码来源:CustomRoleProvider.cs

示例10: VerifySession

 public bool VerifySession(string ipAddress, string sessionId)
 {
     using (var ctx = new UsersContext())
     {
         DateTime timeout = DateTime.UtcNow.AddSeconds(-TimeoutSeconds);
         return ctx.UserSessions.Any(s => s.SqrlId == sessionId &&
                                          s.AuthenticatedDatetime == null &&
                                          s.CreatedDatetime >= timeout);
     }
 }
开发者ID:DerekAlfonso,项目名称:sqrl-net,代码行数:10,代码来源:EfSqrlAuthenticationProvider.cs

示例11: GetRolesForUser

 public override string[] GetRolesForUser(string username)
 {
     using (var usersContext = new UsersContext())
     {
         var user = usersContext.Users.SingleOrDefault(u => u.LASTNAME == username);
         if (user == null)
             return new string[]{};
         return user.UserRoles == null ? new string[] { } : user.UserRoles.Select(u => u.Role).Select(u => u.short_Title).ToArray();
     }
 }
开发者ID:ibadyer,项目名称:seed,代码行数:10,代码来源:CustomRoleProvider.cs

示例12: SaveChanges

        public SaveResult SaveChanges(JObject saveBundle)
        {
            var context = new UsersContext();
            var username = User.Identity.Name;
            var user = context.UserProfiles.SingleOrDefault(u => u.UserName == username);

            TheLogger.Write(string.Format("User {0} saved changes.", username), TraceEventType.Information);

            return _repository.SaveChanges(saveBundle);
        }
开发者ID:centaurustech,项目名称:CrowdFunding-1,代码行数:10,代码来源:AngelikooController.cs

示例13: GetRolesForUser

 public override string[] GetRolesForUser(string username)
 {
     var usersContext = new UsersContext();
     //var user = usersContext.Users.SingleOrDefault(u => u.UserName == username);
     var user = usersContext.GetUser(username);
     if (user == null)
         return new string[] { };
     return user.UserRoles == null
         ? new string[] { }
         : GetUserRoles(user.UserId).Select(u => u.Role).Select(u => u.RoleName).ToArray();
     //user.UserRoles.Select(u => u.Role).Select(u => u.RoleName).ToArray();
 }
开发者ID:ryhoward,项目名称:HackathonAngular,代码行数:12,代码来源:CustomRoleProvider.cs

示例14: Users

        public ActionResult Users()
        {
            IEnumerable<UserProfile> users;
            using (UsersContext db = new UsersContext())
            {
                users = db.UserProfiles.ToList();
            }

            ViewBag.Roles = System.Web.Security.Roles.GetAllRoles();

            return View(users);
        }
开发者ID:CaffGeek,项目名称:MBACNationals2014,代码行数:12,代码来源:MainController.cs

示例15: SimpleMembershipInitializer

            public SimpleMembershipInitializer()
            {
                Database.SetInitializer<UsersContext>(null);
                bool isInitDb = Boolean.Parse(ConfigurationManager.AppSettings["initdb"].ToString());
                if (!isInitDb)
                {
                    try
                    {
                        using (var context = new UsersContext())
                        {
                            if (!context.Database.Exists())
                            {
                                // Create the SimpleMembership database without Entity Framework migration schema
                                ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                            }
                        }

                        //WebSecurity.InitializeDatabaseConnection("DuozhiduocaiConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
                        //var roles = (SimpleRoleProvider)Roles.Provider;

                        if (!Roles.RoleExists("Admin"))
                            Roles.CreateRole("Admin");
                        if (!Roles.RoleExists("Member"))
                            Roles.CreateRole("Member");
                        if (!WebSecurity.UserExists("administrator"))
                        {
                            WebSecurity.CreateUserAndAccount(
                            "administrator",
                            "[email protected]");
                        }
                        if (!WebSecurity.UserExists("yangaiche"))
                        {
                            WebSecurity.CreateUserAndAccount("yangaiche", "[email protected]");
                        }
                        //var roles = Roles.GetRolesForUser("admin");
                        if (!Roles.GetRolesForUser("administrator").Contains("Admin"))
                        {
                            Roles.AddUsersToRoles(new[] { "administrator" }, new[] { "Admin" });
                        }
                        if (!Roles.GetRolesForUser("yangaiche").Contains("Admin"))
                        {
                            Roles.AddUsersToRoles(new[] { "yangaiche" }, new[] { "Admin" });
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                    }
                }
            }
开发者ID:yacwechat,项目名称:wechatv1,代码行数:50,代码来源:InitializeSimpleMembershipAttribute.cs


注:本文中的UsersContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。