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


C# Security.SaveChanges方法代码示例

本文整理汇总了C#中Security.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# Security.SaveChanges方法的具体用法?C# Security.SaveChanges怎么用?C# Security.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Security的用法示例。


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

示例1: CreateRole

 public void CreateRole(string roleName)
 {
     using (var context = new Security())
     {
         context.Roles.AddObject(new Roles() { Name = roleName });
         context.SaveChanges();
     }
 }
开发者ID:macper,项目名称:Helper,代码行数:8,代码来源:SecurityObjectProvider.cs

示例2: AddUsersToRoles

 public void AddUsersToRoles(string[] usernames, string[] roleNames)
 {
     using (var context = new Security())
     {
         var users = from usr in context.Users where usernames.Contains(usr.Name) select usr;
         var roles = from rol in context.Roles where roleNames.Contains(rol.Name) select rol;
         foreach (var u in users)
         {
             foreach (var r in roles)
             {
                 r.UserToRole.Add(new UserToRole() { Roles = r, Users = u });
             }
         }
         context.SaveChanges();
     }
 }
开发者ID:macper,项目名称:Helper,代码行数:16,代码来源:SecurityObjectProvider.cs

示例3: ChangePassword

 public bool ChangePassword(string userName, string oldPassword, string newPassword)
 {
     using (Security context = new Security())
     {
         Users user = context.Users.FirstOrDefault(f => f.Name == userName);
         if (user == null)
             return false;
         string hash = GetSHA1Hash(oldPassword);
         if (user.Password == hash)
         {
             user.Password = GetSHA1Hash(newPassword);
             context.SaveChanges();
             return true;
         }
     }
     return false;
 }
开发者ID:macper,项目名称:Helper,代码行数:17,代码来源:SecurityObjectProvider.cs

示例4: DeleteRole

 public bool DeleteRole(string roleName)
 {
     using (var context = new Security())
     {
         var role = context.Roles.FirstOrDefault(f => f.Name == roleName);
         if (role == null)
         {
             return false;
         }
         context.Roles.DeleteObject(role);
         context.SaveChanges();
         return true;
     }
 }
开发者ID:macper,项目名称:Helper,代码行数:14,代码来源:SecurityObjectProvider.cs

示例5: CreateUser

 public MembershipUser CreateUser(string userName, string password, out MembershipCreateStatus status)
 {
     using (Security context = new Security())
     {
         Users usrDuplicate = context.Users.FirstOrDefault(f => f.Name == userName);
         if (usrDuplicate != null)
         {
             throw new SecurityException("Istnieje już użytkownik o tej nazwie");
         }
         Users user = context.CreateObject<Users>();
         user.Name = userName;
         user.Password = GetSHA1Hash(password);
         context.Users.AddObject(user);
         context.SaveChanges();
         status = MembershipCreateStatus.Success;
         return new MembershipUser("MyProvider", userName, user.Id, null, null, null, true, false, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue);
     }
 }
开发者ID:macper,项目名称:Helper,代码行数:18,代码来源:SecurityObjectProvider.cs

示例6: ValidateUser

 public bool ValidateUser(string username, string password)
 {
     using (var context = new Security())
     {
         string hash = GetSHA1Hash(password);
         var usr = context.Users.FirstOrDefault(f => f.Name == username && f.Password == hash );
         if (usr == null)
         {
             return false;
         }
         usr.LastLogin = DateTime.Now;
         context.SaveChanges();
         return true;
     }
 }
开发者ID:macper,项目名称:Helper,代码行数:15,代码来源:SecurityObjectProvider.cs

示例7: UpdateUser

 public void UpdateUser(MembershipUser user)
 {
     using (var context = new Security())
     {
         var usrToUpdate = context.Users.FirstOrDefault(f => f.Id == (int)user.ProviderUserKey);
         usrToUpdate.Name = user.UserName;
         usrToUpdate.Password = user.GetPassword();
         usrToUpdate.LastLogin = user.LastLoginDate;
         context.SaveChanges();
     }
 }
开发者ID:macper,项目名称:Helper,代码行数:11,代码来源:SecurityObjectProvider.cs

示例8: RemoveUsersFromRoles

 public void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
 {
     using (var context = new Security())
     {
         var sel = from utr in context.UserToRole where usernames.Contains(utr.Users.Name) && roleNames.Contains(utr.Roles.Name) select utr;
         foreach (var s in sel)
         {
             context.UserToRole.DeleteObject(s);
         }
         context.SaveChanges();
     }
 }
开发者ID:macper,项目名称:Helper,代码行数:12,代码来源:SecurityObjectProvider.cs

示例9: DeleteUser

        public bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            using (Security context = new Security())
            {
                Users user = context.Users.FirstOrDefault(f => f.Name == username);
                if (user == null)
                    return false;

                context.Users.DeleteObject(user);
                context.SaveChanges();
                return true;
            }
        }
开发者ID:macper,项目名称:Helper,代码行数:13,代码来源:SecurityObjectProvider.cs


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