本文整理汇总了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
}
示例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;
}
}
示例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);
}
}
}
}
}
示例4: GetAllRoles
public override string[] GetAllRoles()
{
using (var usersContext = new UsersContext())
{
return usersContext.Roles.Select(r => r.short_Title).ToArray();
}
}
示例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);
}
}
示例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;
}
}
示例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();
}
}
示例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}");
}
}
示例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);
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
}
}