Exemplo n.º 1
0
        public ActionResult CreateRole(NewAppRoleViewModel model)
        {
            var context                  = new AppSecurityContext();
            var rolRepository            = new RoleRepository(context);
            var permissionRepository     = new PermissionRepository(context);
            var rolePermissionRepository = new RolePermissionRepository(context);

            if (ModelState.IsValid)
            {
                var role = mapper.Map <AppRole>(model);
                role.Id = Guid.NewGuid().ToString();
                rolRepository.Add(role);
                if (model.SelectedPermissions == null)
                {
                    model.SelectedPermissions = new int[0];
                }

                foreach (var permissionId in model.SelectedPermissions)
                {
                    rolePermissionRepository.Add(new AppRolePermission {
                        PermissionId = permissionId, RoleId = role.Id
                    });
                }
                context.SaveChanges();
                return(RedirectToAction("Roles", "SecuritySettings"));
            }

            var permissions = permissionRepository.GetAll();

            model.AvailablePermissions = mapper.Map <ICollection <AppPermissionViewModel> >(permissions);
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task Initialize()
        {
            ApplicationDbFactory = new ApplicationDbFactory("InMemoryDatabase");
            await ApplicationDbFactory.Create().Database.EnsureDeletedAsync();

            await ApplicationDbFactory.Create().Database.EnsureCreatedAsync();

            ApplicationDbFactory.Create().ResetValueGenerators();
            ApplicationUserRepository = new UserRepository(ApplicationDbFactory.Create(), ApplicationUserValidator);
            FollowerRepository        = new FollowerRepository(ApplicationDbFactory.Create(), FollowerValidator);
            CredentialRepository      = new CredentialRepository(ApplicationDbFactory.Create(), CredentialValidator);
            CredentialTypeRepository  = new CredentialTypeRepository(ApplicationDbFactory.Create(), CredentialTypeValidator);
            RoleRepository            = new RoleRepository(ApplicationDbFactory.Create(), RoleValidator);
            UserRoleRepository        = new UserRoleRepository(ApplicationDbFactory.Create(), UserRoleValidator);
            RolePermissionRepository  = new RolePermissionRepository(ApplicationDbFactory.Create(), RolePermissionValidator);
            PermissionRepository      = new PermissionRepository(ApplicationDbFactory.Create(), PermissionValidator);
            HttpContextAccessor       = new HttpContextAccessor(); // NOTE: Don't actually use it, when using Startup it will inject the HttpContext. (here it will always be null)
            UserManager = new UserManager(ApplicationUserRepository, CredentialTypeRepository, CredentialRepository, RoleRepository, UserRoleRepository, RolePermissionRepository, PermissionRepository, HttpContextAccessor, Hasher, SaltGenerator);
            UserService = new UserService(UserManager, ApplicationUserRepository, FollowerRepository);

            // A Credential type is required for a user to be able to login or register.
            await CredentialTypeRepository.CreateAsync(new CredentialType
            {
                Code     = "Email",
                Name     = "Email",
                Position = 1
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// To get all the role permission details.
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public IList <RolePermission> GetRolePermissions(string accessToken)
        {
            IList <RolePermission> lstRolePermissions = null;

            try
            {
                dynamic session = null;
                if (!string.IsNullOrEmpty(accessToken))
                {
                    session = _sessionManager.GetSessionValues(accessToken);
                }
                if (!string.IsNullOrEmpty(session.DatabaseId()) || _isNonPCR)
                {
                    using (var repository = new RolePermissionRepository(session.DatabaseId()))
                    {
                        lstRolePermissions = repository.GetRolePermissions();
                    }
                }
                else
                {
                    throw new Exception("Unable to get database connection.");
                }
            }
            catch
            {
                throw;
            }
            return(lstRolePermissions);
        }
Exemplo n.º 4
0
        /// <summary>
        /// To get the role permission details by id.
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public RolePermission GetRolePermissionByID(int id, string accessToken)
        {
            RolePermission rolePermission = null;

            try
            {
                dynamic session = null;
                if (!string.IsNullOrEmpty(accessToken))
                {
                    session = _sessionManager.GetSessionValues(accessToken);
                }
                if (!string.IsNullOrEmpty(session.DatabaseId()) || _isNonPCR)
                {
                    using (var repository = new RolePermissionRepository(session.DatabaseId()))
                    {
                        rolePermission = repository.GetRolePermissionIDDetails(id);
                    }
                }
                else
                {
                    throw new Exception("Unable to get database connection.");
                }
            }
            catch
            {
                throw;
            }
            return(rolePermission);
        }
Exemplo n.º 5
0
        public async Task InitializeAsync()
        {
            ApplicationDbFactory = new ApplicationDbFactory("InMemoryDatabase");
            await ApplicationDbFactory.Create().Database.EnsureDeletedAsync();

            await ApplicationDbFactory.Create().Database.EnsureCreatedAsync();

            ApplicationDbFactory.Create().ResetValueGenerators();

            ApplicationUserRepository = new UserRepository(ApplicationDbFactory.Create(), ApplicationUserValidator);
            FollowerRepository        = new FollowerRepository(ApplicationDbFactory.Create(), FollowerValidator);
            CredentialRepository      = new CredentialRepository(ApplicationDbFactory.Create(), CredentialValidator);
            CredentialTypeRepository  = new CredentialTypeRepository(ApplicationDbFactory.Create(), CredentialTypeValidator);
            RoleRepository            = new RoleRepository(ApplicationDbFactory.Create(), RoleValidator);
            UserRoleRepository        = new UserRoleRepository(ApplicationDbFactory.Create(), UserRoleValidator);
            RolePermissionRepository  = new RolePermissionRepository(ApplicationDbFactory.Create(), RolePermissionValidator);
            PermissionRepository      = new PermissionRepository(ApplicationDbFactory.Create(), PermissionValidator);
            HttpContextAccessor       = new HttpContextAccessor(); // NOTE: Don't actually use it, when using Startup it will inject the HttpContext. (here it will always be null)

            UserManager     = new UserManager(ApplicationUserRepository, CredentialTypeRepository, CredentialRepository, RoleRepository, UserRoleRepository, RolePermissionRepository, PermissionRepository, HttpContextAccessor, Hasher, SaltGenerator);
            UserService     = new UserService(UserManager, ApplicationUserRepository, FollowerRepository);
            FollowerService = new FollowerService(FollowerRepository, ApplicationUserRepository);

            // A Credential type is required for a user to be able to login or register.
            await CredentialTypeRepository.CreateAsync(new CredentialType
            {
                Code     = "Email",
                Name     = "Email",
                Position = 1
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });
        }
Exemplo n.º 6
0
        public void UpdateFromAPI(long id, RolePermissionUpdate rolePermissionUpdate)
        {
            RolePermissionRepository rolePermissionRepository = new RolePermissionRepository();

            rolePermissionRepository.Roleid       = rolePermissionUpdate.Roleid;
            rolePermissionRepository.Permissionid = rolePermissionUpdate.Permissionid;
            this.rolePermissionStoreRepository.Update(id, rolePermissionRepository);
        }
Exemplo n.º 7
0
 public RolePermissionDetail(RolePermissionRepository rolePermissionRepository)
 {
     this.Id           = rolePermissionRepository.Id;
     this.Roleid       = rolePermissionRepository.Roleid;
     this.Permissionid = rolePermissionRepository.Permissionid;
     this.Permission   = (new PermissionItem(rolePermissionRepository.Permission));
     this.Role         = (new RoleItem(rolePermissionRepository.Role));
 }
Exemplo n.º 8
0
        public void CreateFromAPI(RolePermissionCreate rolePermissionCreate)
        {
            RolePermissionRepository rolePermissionRepository = new RolePermissionRepository();

            rolePermissionRepository.Roleid       = rolePermissionCreate.Roleid;
            rolePermissionRepository.Permissionid = rolePermissionCreate.Permissionid;
            this.rolePermissionStoreRepository.Create(rolePermissionRepository);
        }
Exemplo n.º 9
0
        /// <summary>
        /// To update the role permission details by id.
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="rolepermission"></param>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public bool UpdateRolePermission(int id, RolePermission rolepermission, string accessToken)
        {
            try
            {
                dynamic session = null;
                if (!string.IsNullOrEmpty(accessToken))
                {
                    session = _sessionManager.GetSessionValues(accessToken);
                }
                if (!string.IsNullOrEmpty(session.DatabaseId()) || _isNonPCR)
                {
                    using (var repository = new RolePermissionRepository(session.DatabaseId()))
                    {
                        bool isExistRoleAndPermission = repository.CheckRoleAndPermission(rolepermission.RoleID, rolepermission.PermissionID);
                        if (isExistRoleAndPermission)
                        {
                            var rolePermissionDetails = repository.GetRolePermissionIDDetails(id);
                            if (rolePermissionDetails != null)
                            {
                                int rs = repository.FindRolePermission(id, (rolepermission.RoleID == 0 ? rolePermissionDetails.RoleID : rolepermission.RoleID), (rolepermission.PermissionID == 0 ? rolePermissionDetails.PermissionID : rolepermission.PermissionID));
                                if (rs > 0)
                                {
                                    throw new Exception("RolePermission is already exist.");
                                }
                                else
                                {
                                    rolePermissionDetails.RoleID       = rolepermission.RoleID;
                                    rolePermissionDetails.PermissionID = rolepermission.PermissionID;
                                }

                                rolePermissionDetails.UpdatedBy        = rolepermission.UpdatedBy;
                                rolePermissionDetails.UpdatedDate      = DateTime.Now;
                                rolePermissionDetails.RolePermissionID = id;
                                rolePermissionDetails.CreatedBy        = rolePermissionDetails.CreatedBy;
                                rolePermissionDetails.CreatedDate      = rolePermissionDetails.CreatedDate;
                                repository.ModifiedRolePermission(rolePermissionDetails);
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception("Unable to get database connection.");
                }
            }
            catch
            {
                throw;
            }
            return(false);
        }
        public void Scoped()
        {
            //using (var scope = _scopeFactory.CreateScope())
            //{
            var scope = _scopeFactory.CreateScope();

            _rolePermissionRepository = scope.ServiceProvider.GetRequiredService <RolePermissionRepository>();

            //}
            // Other code
        }
Exemplo n.º 11
0
        public bool IsRoleHavePermission(string role, string permission)
        {
            RoleRepository       roleRepository       = this.roleQueryRepository.FindByName(role);
            PermissionRepository permissionRepository = this.permissionQueryRepository.FindByName(permission);
            long roleId       = roleRepository.Id;
            long permissionId = permissionRepository.Id;

            RolePermissionRepository rolePermissionRepository = this.rolePermissionQueryRepository.FindByRoleAndPermission(roleId, permissionId);

            return(rolePermissionRepository.Id != 0);
        }
Exemplo n.º 12
0
        public async Task Initialize()
        {
            ApplicationDbFactory = new ApplicationDbFactory("InMemoryDatabase");
            await ApplicationDbFactory.Create().Database.EnsureDeletedAsync();

            await ApplicationDbFactory.Create().Database.EnsureCreatedAsync();

            ApplicationDbFactory.Create().ResetValueGenerators();

            MemeRepository            = new MemeRepository(ApplicationDbFactory.Create(), MemeValidator);
            ApplicationUserRepository = new UserRepository(ApplicationDbFactory.Create(), ApplicationUserValidator);
            FollowerRepository        = new FollowerRepository(ApplicationDbFactory.Create(), FollowerValidator);
            CredentialRepository      = new CredentialRepository(ApplicationDbFactory.Create(), CredentialValidator);
            CredentialTypeRepository  = new CredentialTypeRepository(ApplicationDbFactory.Create(), CredentialTypeValidator);
            RoleRepository            = new RoleRepository(ApplicationDbFactory.Create(), RoleValidator);
            UserRoleRepository        = new UserRoleRepository(ApplicationDbFactory.Create(), UserRoleValidator);
            RolePermissionRepository  = new RolePermissionRepository(ApplicationDbFactory.Create(), RolePermissionValidator);
            PermissionRepository      = new PermissionRepository(ApplicationDbFactory.Create(), PermissionValidator);
            CommentRepository         = new CommentRepository(ApplicationDbFactory.Create(), CommentValidator);
            HttpContextAccessor       = new HttpContextAccessor(); // NOTE: Don't actually use it, when using Startup it will inject the HttpContext. (here it will always be null)

            UserManager    = new UserManager(ApplicationUserRepository, CredentialTypeRepository, CredentialRepository, RoleRepository, UserRoleRepository, RolePermissionRepository, PermissionRepository, HttpContextAccessor, Hasher, SaltGenerator);
            UserService    = new UserService(UserManager, ApplicationUserRepository, FollowerRepository);
            CommentService = new CommentService(CommentRepository, MemeRepository);

            // A Credential type is required for a user to be able to login or register.
            await CredentialTypeRepository.CreateAsync(new CredentialType
            {
                Code     = "Email",
                Name     = "Email",
                Position = 1
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            Meme meme = new Meme
            {
                Id       = "a0Q558q",
                ImageUrl = "https://images-cdn.9gag.com/photo/a0Q558q_700b.jpg",
                VideoUrl = "http://img-9gag-fun.9cache.com/photo/a0Q558q_460sv.mp4",
                PageUrl  = "http://9gag.com/gag/a0Q558q",
                Title    = "Old but Gold"
            };
            await MemeRepository.CreateAsync(meme);
        }
Exemplo n.º 13
0
        private IEnumerable <Claim> GetUserPermissionClaims(Role role)
        {
            List <Claim>      claims        = new List <Claim>();
            IEnumerable <int> permissionIds = new RolePermissionRepository(storage).All(role.Id).Select(rp => rp.PermissionId).ToList();

            if (permissionIds != null)
            {
                foreach (int permissionId in permissionIds)
                {
                    Permission permission = new PermissionRepository(storage).One(permissionId);

                    claims.Add(new Claim("Permission", permission.Code));
                }
            }

            return(claims);
        }
Exemplo n.º 14
0
 /// <summary>
 /// To add the role permission details.
 /// </summary>
 /// <param name="rolepermission"></param>
 /// <param name="accessToken"></param>
 /// <returns></returns>
 public bool AddRolePermission(RolePermission rolepermission, string accessToken)
 {
     try
     {
         dynamic session = null;
         if (!string.IsNullOrEmpty(accessToken))
         {
             session = _sessionManager.GetSessionValues(accessToken);
         }
         if (!string.IsNullOrEmpty(session.DatabaseId()) || _isNonPCR)
         {
             using (var repository = new RolePermissionRepository(session.DatabaseId()))
             {
                 bool IsExistRoleAndPermission = repository.CheckRoleAndPermission(rolepermission.RoleID, rolepermission.PermissionID);
                 if (IsExistRoleAndPermission)
                 {
                     bool IsexistRolePermissionCount = repository.ExistRolePermission(rolepermission.RoleID, rolepermission.PermissionID);
                     if (IsexistRolePermissionCount)
                     {
                         rolepermission.CreatedDate = DateTime.Now;
                         rolepermission.UpdatedDate = DateTime.Now;
                         repository.AddRolePermission(rolepermission);
                         return(true);
                     }
                     else
                     {
                         return(false);
                     }
                 }
             }
         }
         else
         {
             throw new Exception("Unable to get database connection.");
         }
     }
     catch
     {
         throw;
     }
     return(false);
 }
Exemplo n.º 15
0
        public ActionResult EditRole(string id)
        {
            var context = new AppSecurityContext();
            var rolePermissionRepository = new RolePermissionRepository(context);
            var permissionRepository     = new PermissionRepository(context);

            var role = context.Roles.Find(id);
            var permissionsResult = rolePermissionRepository.GetPermissionByRoleId(id);
            var permissions       = permissionRepository.GetAll();
            var model             = mapper.Map <EditAppRoleViewModel>(role);

            if (permissionsResult.Count() > 0)
            {
                model.SelectedPermissions = permissionsResult.Select(x => x.Id).ToArray();
            }

            model.AvailablePermissions = mapper.Map <ICollection <AppPermissionViewModel> >(permissions);

            return(View(model));
        }
Exemplo n.º 16
0
 public void Dispose()
 {
     this._userRepository               = null;
     this._permissionRepository         = null;
     this._roleRepository               = null;
     this._rolePermissionRepository     = null;
     this._investigatorRepository       = null;
     this._institutionRepository        = null;
     this._interestAreaRepository       = null;
     this._programRepository            = null;
     this._investigationGroupRepository = null;
     this._commissionRepository         = null;
     this._draftLawRepository           = null;
     this._conceptRepository            = null;
     this._badLanguageRepository        = null;
     this._tagRepository = null;
     this._conceptStatusLogRepository       = null;
     this._debateSpeakerRepository          = null;
     this._educationalInstitutionRepository = null;
     this._knowledgeAreaRepository          = null;
     this._academicLevelRepository          = null;
     this._educationLevelRepository         = null;
     this._snieRepository                     = null;
     this._meritRangeRepository               = null;
     this._investigatorCommissionRepository   = null;
     this._investigatorInterestAreaRepository = null;
     this._configurationRepository            = null;
     this._notificationRepository             = null;
     this._conceptDebateSpeakerRepository     = null;
     this._consultationRepository             = null;
     this._consultationInterestAreaRepository = null;
     this._draftLawStatusRepository           = null;
     this._periodRepository                   = null;
     this._originRepository                   = null;
     this._userInstitutionRepository          = null;
     this._consultationTypeRepository         = null;
     this._reasonRejectRepository             = null;
     _context.Dispose();
 }
Exemplo n.º 17
0
        /// <summary>
        /// To delete the role permission details by id.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public string DeleteRolePermission(int id, string accessToken)
        {
            string msg = string.Empty;

            try
            {
                dynamic session = null;
                if (!string.IsNullOrEmpty(accessToken))
                {
                    session = _sessionManager.GetSessionValues(accessToken);
                }
                if (!string.IsNullOrEmpty(session.DatabaseId()) || _isNonPCR)
                {
                    using (var repository = new RolePermissionRepository(session.DatabaseId()))
                    {
                        var rolepermission = repository.GetRolePermissionIDDetails(id);
                        if (rolepermission != null)
                        {
                            repository.DeleteRolePermission(rolepermission);
                            msg = "RolePermission has been deleted successfully.";
                        }
                        else
                        {
                            msg = "Content not found by Id =" + id;
                        }
                    }
                }
                else
                {
                    throw new Exception("Unable to get database connection.");
                }
            }
            catch
            {
                throw;
            }
            return(msg);
        }
Exemplo n.º 18
0
        public ActionResult DetailsRole(string id)
        {
            var context                  = new AppSecurityContext();
            var roleRepository           = new RoleRepository(context);
            var rolePermissionRepository = new RolePermissionRepository(context);

            var role = roleRepository.Find(id);

            var permissionsResult = rolePermissionRepository.GetPermissionsByRoleIncludingActionResource(id);

            var model = mapper.Map <DetailsAppRoleViewModel>(role);

            model.Permissions = new List <AppPermissionViewModel>();

            foreach (var result in permissionsResult)
            {
                model.Permissions.Add(new AppPermissionViewModel {
                    ActionName = result.Action.Name, ResourceName = result.Resource.Name
                });
            }

            return(View(model));
        }
Exemplo n.º 19
0
        public ActionResult EditRole(string id, EditAppRoleViewModel model)
        {
            var context = new AppSecurityContext();
            var rolePermissionRepository = new RolePermissionRepository(context);
            var permissionRepository     = new PermissionRepository(context);
            var roleRepostory            = new RoleRepository(context);

            if (ModelState.IsValid)
            {
                var role = mapper.Map <AppRole>(model);
                roleRepostory.UpdateRoleWithPermissions(role, model.SelectedPermissions);
                context.SaveChanges();
                return(RedirectToAction("Roles", "SecuritySettings"));
            }
            var permissions = roleRepostory.GetAll();

            if (permissions.Count() > 0)
            {
                model.AvailablePermissions = mapper.Map <ICollection <AppPermissionViewModel> >(permissions);
            }

            return(View(model));
        }
        public bool IsValid()
        {
            RolePermissionRepository rolePermissionRepository = this.rolePermissionApplication.DetailByRolePermission(this.roleid, this.permissionid);

            return(rolePermissionRepository.Id > 0 && rolePermissionRepository.Id != this.id);
        }
Exemplo n.º 21
0
 public RolePermissionService()
 {
     _rolePermissionRepository = new RolePermissionRepository(new DatabaseContext());
 }
Exemplo n.º 22
0
 public RolePermissionService()
 {
     _rolePermissionRepository = new RolePermissionRepository(base.Provider, base.OInfo);
 }
Exemplo n.º 23
0
 public RoleService(RoleRepository roleRepository, RolePermissionRepository rolePermissionRepository, RoleMenuRepository roleMenuRepository)
 {
     _repository = roleRepository;
     _rolePermissionRepository = rolePermissionRepository;
     _roleMenuRepository       = roleMenuRepository;
 }
Exemplo n.º 24
0
 /// <summary>
 /// 因为此服务被webUI调用,此处没有配置,因此需要
 /// </summary>
 /// <param name="connString"></param>
 public RolePermissionService(string connString) : base(connString)
 {
     _rolePermissionRepository = new RolePermissionRepository(base.Provider, base.OInfo);
 }
Exemplo n.º 25
0
 public AspRolesService(IAspRolesRepository aspRoleRepo, IUnitOperation unitOp, RolePermissionRepository rpRepo)
 {
     this.aspRolesRepository       = aspRoleRepo;
     this.unitOperation            = unitOp;
     this.rolePermissionRepository = rpRepo;
 }
Exemplo n.º 26
0
 public RoleRepositoryImpl(DBEntities db, RolePermissionRepository rolePermission) : base(db)
 {
     this.rolePermission = rolePermission;
 }
Exemplo n.º 27
0
 public RolePermissionItem(RolePermissionRepository rolePermissionRepository)
 {
     this.Id           = rolePermissionRepository.Id;
     this.Roleid       = rolePermissionRepository.Roleid;
     this.Permissionid = rolePermissionRepository.Permissionid;
 }
Exemplo n.º 28
0
 public RoleBL()
 {
     oUnitOfWork  = new UnitOfWork(ConfigurationManager.ConnectionStrings["SSREntities"].ConnectionString);
     oRepositorio = oUnitOfWork.RoleRepository;
     oRolePermissionRepository = oUnitOfWork.RolePermissionRepository;
 }
Exemplo n.º 29
0
        public async Task InitializeAsync()
        {
            ApplicationDbFactory = new ApplicationDbFactory("InMemoryDatabase");
            await ApplicationDbFactory.Create().Database.EnsureDeletedAsync();

            await ApplicationDbFactory.Create().Database.EnsureCreatedAsync();

            ApplicationDbFactory.Create().ResetValueGenerators();

            MemeRepository            = new MemeRepository(ApplicationDbFactory.Create(), MemeValidator);
            SharedMemeRepository      = new SharedMemeRepository(ApplicationDbFactory.Create(), SharedMemeValidator);
            ApplicationUserRepository = new UserRepository(ApplicationDbFactory.Create(), ApplicationUserValidator);
            FollowerRepository        = new FollowerRepository(ApplicationDbFactory.Create(), FollowerValidator);
            CredentialRepository      = new CredentialRepository(ApplicationDbFactory.Create(), CredentialValidator);
            CredentialTypeRepository  = new CredentialTypeRepository(ApplicationDbFactory.Create(), CredentialTypeValidator);
            RoleRepository            = new RoleRepository(ApplicationDbFactory.Create(), RoleValidator);
            UserRoleRepository        = new UserRoleRepository(ApplicationDbFactory.Create(), UserRoleValidator);
            RolePermissionRepository  = new RolePermissionRepository(ApplicationDbFactory.Create(), RolePermissionValidator);
            PermissionRepository      = new PermissionRepository(ApplicationDbFactory.Create(), PermissionValidator);
            CommentRepository         = new CommentRepository(ApplicationDbFactory.Create(), CommentValidator);
            HttpContextAccessor       = new HttpContextAccessor(); // NOTE: Don't actually use it, when using Startup it will inject the HttpContext. (here it will always be null)

            UserManager        = new UserManager(ApplicationUserRepository, CredentialTypeRepository, CredentialRepository, RoleRepository, UserRoleRepository, RolePermissionRepository, PermissionRepository, HttpContextAccessor, Hasher, SaltGenerator);
            UserService        = new UserService(UserManager, ApplicationUserRepository, FollowerRepository);
            FollowerService    = new FollowerService(FollowerRepository, ApplicationUserRepository);
            MemeSharingService = new MemeSharingService(SharedMemeRepository, ApplicationUserRepository);

            // NOTE: A CredentialType is required for a user to be able to login or register.
            await CredentialTypeRepository.CreateAsync(new CredentialType
            {
                Code     = "Email",
                Name     = "Email",
                Position = 1
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            await UserService.SignUpAsync(new RegisterUserDto
            {
                Email    = "*****@*****.**",
                Password = "******",
                UserName = "******"
            });

            FollowerDto followerDto1 = new FollowerDto
            {
                UserId         = 1,
                FollowerUserId = 2
            };
            FollowerDto followerDto2 = new FollowerDto
            {
                UserId         = 2,
                FollowerUserId = 1
            };
            await FollowerService.FollowUserAsync(followerDto1);

            await FollowerService.FollowUserAsync(followerDto2);

            Meme meme1 = new Meme
            {
                Id       = "a0Q558q",
                ImageUrl = "https://images-cdn.9gag.com/photo/a0Q558q_700b.jpg",
                VideoUrl = "http://img-9gag-fun.9cache.com/photo/a0Q558q_460sv.mp4",
                PageUrl  = "http://9gag.com/gag/a0Q558q",
                Title    = "Old but Gold"
            };
            await MemeRepository.CreateAsync(meme1);

            Meme meme2 = new Meme
            {
                Id       = "a0QQZoL",
                ImageUrl = "https://images-cdn.9gag.com/photo/a0QQZoL_700b.jpg",
                VideoUrl = "http://img-9gag-fun.9cache.com/photo/a0QQZoL_460sv.mp4",
                PageUrl  = "http://9gag.com/gag/a0QQZoL",
                Title    = "Austin was listed for a heart transplant, and the doctor said he would deliver the news a heart was available dressed as Chewbacca."
            };
            await MemeRepository.CreateAsync(meme2);
        }