コード例 #1
0
        public static ApplicationUser GetApplicationUser(this IPrincipal principal, IssuesDb db)
        {
            var userId = principal.GetUserId();
            var user   = db.Users.Find(userId);

            return(user);
        }
コード例 #2
0
        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" }
            //    );
            //
        }
コード例 #3
0
ファイル: Article.cs プロジェクト: VladD2/BlackHolesPubs
        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;
        }
コード例 #4
0
        // 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);
            }
        }
コード例 #5
0
ファイル: Article.cs プロジェクト: VladD2/BlackHolesPubs
        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');
            }
        }
コード例 #6
0
 private static ApplicationUser GetUser(IssuesDb context, string email)
 {
     return(context.Users.Where(u => u.Email == email).SingleOrDefault());
 }
コード例 #7
0
ファイル: Article.cs プロジェクト: VladD2/BlackHolesPubs
 public void MakeArticleAuthorsViewModel(IPrincipal user, IssuesDb db)
 {
     MakeArticleAuthorsViewModel(user, db, this.AuthorsIds.ParseToIntArray());
 }
コード例 #8
0
 public static Issue GetActiveIssueOpt(this IssuesDb db)
 {
     return(db.Issues.Where(i => i.Active).OrderBy(i => i.Year).ThenBy(i => i.Number).FirstOrDefault());
 }