public static ApplicationUser GetApplicationUser(this IPrincipal principal, IssuesDb db) { var userId = principal.GetUserId(); var user = db.Users.Find(userId); return(user); }
protected override void Seed(IssuesDb context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // }
private void MakeArticleAuthorsViewModel(IPrincipal user, IssuesDb db, int[] authorsIds) { var query = db.Authors.FilterByOwner(user); if (authorsIds != null && authorsIds.Length != 0) { query = query.Where(a => !authorsIds.Contains(a.Id)); } var other = query.ToList(); var newArticleAuthors = new ArticleAuthorsViewModel() { ArticleAuthors = this.Authors ?? new List <Author>(), AvailableAuthors = other }; this.AuthorsViewModel = newArticleAuthors; }
// In this method we will create default User roles and Admin user for login private void CreateRolesandUsers(IAppBuilder app) { var context = new IssuesDb(); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); userManager.UserValidator = new UserValidator <ApplicationUser>(userManager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true }; var editor1 = GetUser(context, "*****@*****.**"); if (editor1 != null) { AddRole(editor1, roleManager, userManager, Constants.EditorRole); } var editor2 = GetUser(context, "*****@*****.**"); if (editor2 != null) { AddRole(editor2, roleManager, userManager, Constants.EditorRole); } var editor3 = GetUser(context, "*****@*****.**"); if (editor3 != null) { RemoveRole(editor3, roleManager, userManager, Constants.AdminRole); AddRole(editor3, roleManager, userManager, Constants.EditorRole); } var admin = GetUser(context, "*****@*****.**"); if (admin != null) { AddRole(admin, roleManager, userManager, Constants.AdminRole); AddRole(admin, roleManager, userManager, Constants.EditorRole); } }
public void FillPrperties(IssuesDb db) { var authorsIds = this.AuthorsIds.ParseToIntArray(); if (this.Authors == null) { this.Authors = new List <Author>(); } else { this.Authors.Clear(); } var authors = db.Authors.Where(a => authorsIds.Contains(a.Id)).ToList(); this.Authors.AddRange(authors); this.Modified = DateTime.UtcNow; if (this.References != null) { this.References = this.References.Trim(' ', '\t', '\r', '\n'); } }
private static ApplicationUser GetUser(IssuesDb context, string email) { return(context.Users.Where(u => u.Email == email).SingleOrDefault()); }
public void MakeArticleAuthorsViewModel(IPrincipal user, IssuesDb db) { MakeArticleAuthorsViewModel(user, db, this.AuthorsIds.ParseToIntArray()); }
public static Issue GetActiveIssueOpt(this IssuesDb db) { return(db.Issues.Where(i => i.Active).OrderBy(i => i.Year).ThenBy(i => i.Number).FirstOrDefault()); }