예제 #1
0
        public void Run()
        {
            //若Model发生改变,则自动更新数据库.
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <BlogEngineContext, Configuration>());

            using (var context = new BlogEngineContext())
            {
                if (!context.Database.Exists())
                {
                    //初始化数据
                    var user    = CreateUser();
                    var channel = CreateChannel();
                    var group   = CreateGroup(channel);
                    var post    = CreatePost(user, group);
                    var comment = CreateComment(post);
                    var board   = CreateBoard();

                    //保存数据
                    context.Set <User>().Add(user);
                    context.Set <Channel>().Add(channel);
                    context.Set <Group>().Add(group);
                    context.Set <Post>().Add(post);
                    context.Set <Comment>().Add(comment);
                    context.Set <Board>().Add(board);
                    context.SaveChanges();
                }
            }
        }
예제 #2
0
 public AccountService(UserManager <User> user, RoleManager <Role> role, SignInManager <User> signInManager, IOptions <IdentityOptions> identityOptions, BlogEngineContext context, IHttpContextAccessor httpAccessor, IMapper mapper)
 {
     _context = context;
     _context.CurrentUserId = httpAccessor.HttpContext?.User.FindFirst(OpenIdConnectConstants.Claims.Subject)?.Value?.Trim();
     _userManager           = user;
     _roleManager           = role;
     _signInManager         = signInManager;
     _identityOptions       = identityOptions;
     _mapper = mapper;
 }
예제 #3
0
 public CommentRepository(BlogEngineContext context)
 {
     _context = context;
 }
예제 #4
0
 public UserRepository(BlogEngineContext context) : base(context)
 {
 }
 public PostTagRepository(BlogEngineContext context) : base(context)
 {
 }
예제 #6
0
 public EntityBaseRepository(BlogEngineContext context)
 {
     _context = context;
 }
예제 #7
0
 public CommentRepository(BlogEngineContext context) : base(context)
 {
 }
예제 #8
0
 public GenericRepository(BlogEngineContext context)
 {
     this._context = context;
     this.dbSet    = context.Set <TEntity>();
 }
예제 #9
0
 public CategoryRepository(BlogEngineContext context) : base(context)
 {
 }
예제 #10
0
 public UserRepository(BlogEngineContext context)
 {
     _context = context;
 }
예제 #11
0
        private static void AddTestData(BlogEngineContext context)
        {
            #region Roles

            Rol rolWriter = new Rol()
            {
                Id   = 1,
                Code = "1",
                Name = "Writer"
            };
            context.Roles.Add(rolWriter);

            Rol rolEditor = new Rol()
            {
                Id   = 2,
                Code = "2",
                Name = "Editor"
            };
            context.Roles.Add(rolEditor);

            #endregion

            #region Writer 1

            User writer1 = new User
            {
                Id       = 1,
                UserName = "******",
                FullName = "Julian Mendez",
                Rol      = rolWriter
            };
            context.Users.Add(writer1);

            // PASS: Z3moga.852
            PasswordByUser passwordByUserWriter1 = new PasswordByUser()
            {
                Id     = 1,
                UserId = 1,
                Hash   = "0f27e5f3b235de0bd3a6e4dc771f6892a5b84410ba7c54973bfb2735a072e303",
                Salt   = "f6Mv"
            };
            context.PasswordByUsers.Add(passwordByUserWriter1);

            #endregion

            #region Writer 2

            User writer2 = new User
            {
                Id       = 2,
                UserName = "******",
                FullName = "Maikol Bonilla",
                Rol      = rolWriter
            };
            context.Users.Add(writer2);

            // PASS: Z3moga.852
            PasswordByUser passwordByUserWriter2 = new PasswordByUser()
            {
                Id     = 2,
                UserId = 2,
                Hash   = "0f27e5f3b235de0bd3a6e4dc771f6892a5b84410ba7c54973bfb2735a072e303",
                Salt   = "f6Mv"
            };
            context.PasswordByUsers.Add(passwordByUserWriter2);

            #endregion

            #region Edtior 1

            User editor1 = new User
            {
                Id       = 3,
                UserName = "******",
                FullName = "Andres Tovar",
                Rol      = rolEditor
            };
            context.Users.Add(editor1);

            // PASS: Z3moga.963
            PasswordByUser passwordByUserEditor1 = new PasswordByUser()
            {
                Id     = 3,
                UserId = 3,
                Hash   = "40331eb73de18b87602e67b28d4e22a7f9e449f2a446c7f1144b5d5a03d3a185",
                Salt   = "hON0"
            };
            context.PasswordByUsers.Add(passwordByUserEditor1);

            #endregion

            #region Editor 2

            User editor2 = new User
            {
                Id       = 4,
                UserName = "******",
                FullName = "Oscar Zapata",
                Rol      = rolEditor
            };
            context.Users.Add(editor2);

            // PASS: Z3moga.963
            PasswordByUser passwordByUserEditor2 = new PasswordByUser()
            {
                Id     = 4,
                UserId = 4,
                Hash   = "40331eb73de18b87602e67b28d4e22a7f9e449f2a446c7f1144b5d5a03d3a185",
                Salt   = "hON0"
            };
            context.PasswordByUsers.Add(passwordByUserEditor2);

            #endregion

            context.SaveChanges();
        }