• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# UsersContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: GetCountOfBiggerPictures

        private static int GetCountOfBiggerPictures(UsersContext context, int numberOfPixels)
        {
            IEnumerable<User> userWithPictures = context.Users.Where(user => user.ProfilePicture != null);
            int count = 0;

            foreach (User userWithPicture in userWithPictures)
            {
                if (userWithPicture.ProfileImage.Width > numberOfPixels)
                {
                    count++;
                }
            }

            return count;
        }
开发者ID:borko9696,项目名称:SoftwareUniversity,代码行数:15,代码来源:Program.cs


示例17: AddUser

 public bool AddUser(RegisterExternalLoginModel model)
 {
     using (var db = new UsersContext())
     {
         var user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
         // Check if user already exists
         if (user == null)
         {
             // Insert name into the profile table
             db.UserProfiles.Add(new UserProfile {UserName = model.UserName});
             db.SaveChanges();
             return true;
         }
         return false;
     }
 }
开发者ID:p4rtyz4n,项目名称:AppSkeleton,代码行数:16,代码来源:UserDbRepository.cs


示例18: DeleteProfiles

 public override int DeleteProfiles(string[] usernames)
 {
     using (UsersContext db = new UsersContext())
     {
         List<UserProfile> profiles = new List<UserProfile>();
         int i;
         for (i = 0; i < usernames.Count(); i++)
         {
             string userName=usernames[i];
             profiles.Add(db.UsersProfiles.Find(userName));
         }
         db.UsersProfiles.RemoveRange(profiles);
         db.SaveChanges();
         return i;
     }
 }
开发者ID:firsttimedeveloper,项目名称:mvc4gw7,代码行数:16,代码来源:SQLProfileProvider.cs


示例19: AddUsersToRoles

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            using (UsersContext db = new UsersContext())
            {
                foreach (string username in usernames)
                {
                    foreach (string rolename in roleNames)
                    {
                        UserInRole userInRole = new UserInRole();
                        userInRole.UserName = (string) Membership.GetUser(username).ProviderUserKey;
                        userInRole.RoleId = db.Roles.FirstOrDefault(x => x.Name == rolename).Id;
                        db.UsersInRoles.Add(userInRole);
                        db.SaveChanges();
                    }

                }
            }
        }
开发者ID:firsttimedeveloper,项目名称:mvc4gw7,代码行数:18,代码来源:SQLRoleProvider.cs


示例20: RemoveInactiveUsers

        private static void RemoveInactiveUsers(UsersContext context, DateTime logDate)
        {
            List<User> users = context.Users.Where(user => user.LastTimeLoggedIn < logDate && !user.IsDeleted).ToList();
            foreach (User user in users)
            {
                user.IsDeleted = true;
            }
            if (users.Count == 0)
            {
                Console.WriteLine("No users have been deleted");
            }
            else
            {
                Console.WriteLine($"{users.Count} user has been deleted");
            }

            context.SaveChanges();
        }
开发者ID:borko9696,项目名称:SoftwareUniversity,代码行数:18,代码来源:Program.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UsingDeclaration类代码示例发布时间:2022-05-24
下一篇:
C# Users类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap