本文整理汇总了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();
}
}
示例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();
}
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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;
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
}