Пример #1
0
        public Role GetRole(Guid roleId)
        {
            RoleWithPermissionsQuery query = new RoleWithPermissionsQuery(dbContext.Roles);
            RoleMapper roleMapper          = new RoleMapper();

            return(roleMapper.Map(query.Execute(roleId)));
        }
Пример #2
0
 public ManagerController(IGroupProvider groupProvider,
                          IProjectProvider projectProvider,
                          IScrumMasterProvider scrumMasterProvider,
                          ITraineeProvider traineeProvider,
                          TraineeMapper traineeMapper,
                          IMentorProvider mentorProvider,
                          ISpecializationProvider specializationProvider,
                          IUsersProvider userProvider,
                          ProjectMapper projectMapper,
                          GroupMapper groupMapper,
                          MentorMapper mentorMapper,
                          UserMapper userMapper,
                          RoleMapper roleMapper)
 {
     _groupProvider          = groupProvider;
     _projectProvider        = projectProvider;
     _scrumMasterProvider    = scrumMasterProvider;
     _traineeProvider        = traineeProvider;
     _traineeMapper          = traineeMapper;
     _mentorProvider         = mentorProvider;
     _specializationProvider = specializationProvider;
     _userProvider           = userProvider;
     _projectMapper          = projectMapper;
     _groupMapper            = groupMapper;
     _mentorMapper           = mentorMapper;
     _userMapper             = userMapper;
     _roleMapper             = roleMapper;
 }
Пример #3
0
        public IReadOnlyCollection <Role> GetRoles()
        {
            var        query      = new RolesQuery(dbContext.Roles);
            RoleMapper roleMapper = new RoleMapper();

            return(roleMapper.Map(query.Execute()).ToList());
        }
Пример #4
0
        public ActionResult AddRole(RolePO form)
        {
            ActionResult response = null;

            if (ModelState.IsValid)
            {
                try
                {
                    //sets user inputted role name to a variable and checks to see if the name exists in the database
                    string name       = form.Name;
                    bool   roleExists = _dataAccess.RoleExists(name);

                    if (!roleExists)
                    {
                        RoleDO dataObject = RoleMapper.RolePOToDO(form);
                        _dataAccess.AddRole(dataObject);
                        response = RedirectToAction("Index", "Role");
                    }
                    else
                    {
                        ModelState.AddModelError("Name", "Role name already in use, please choose another.");
                        response = View();
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
                }
            }
            else
            {
                response = View(form);
            }
            return(response);
        }
 public JWTAuthenticationService(IOptions <TokenManagement> tokenManagement, UserRepository userRepo, RoleMapper roleMapper, PasswordCryptoService cryptoService)
 {
     _tokenManagement = tokenManagement.Value;
     _userRepo        = userRepo;
     _roleMapper      = roleMapper;
     _cryptoService   = cryptoService;
 }
Пример #6
0
        public override void PreInitialize()
        {
            // Pages
            Configuration.Authorization.Providers.Add <AbpLearningAuthorizationProvider>();

            // 云书单权限
            Configuration.Authorization.Providers.Add <CloudBookListAuthorizationProvider>();

            // File
            Configuration.Authorization.Providers.Add <FileAuthorizationProvider>();

            // 自定义类型映射
            Configuration.Modules.AbpAutoMapper().Configurators.Add(configuration =>
            {
                BookMapper.CreateMappings(configuration);

                BookListMapper.CreateMappings(configuration);

                RoleMapper.CreateMappings(configuration);

                PermissionMapper.CreateMappings(configuration);

                UserMapper.CreateMappings(configuration);

                OrganizationMapper.CreateMappings(configuration);
            });
        }
Пример #7
0
        public ActionResult Delete(int id)
        {
            var role          = _role.GetRoleById(id);
            var serializeRole = RoleMapper.SerializeRole(role);

            return(PartialView(serializeRole));
        }
Пример #8
0
        public ActionResult UpdateRole(int userID, string userFullName, int roleID, RoleModel iRoleModel)
        {
            // Must be admin to access view
            if (((LoginModel)Session["loginModel"]) != null && ((LoginModel)Session["loginModel"]).RoleIDFK == 1)
            {
                ViewBag.ID       = userID;
                ViewBag.FullName = userFullName;


                RoleMapper iRoleMapper = new RoleMapper();
                Role       iRole       = new Role();
                iRole = iRoleMapper.MapRole(iRoleModel);
                RoleBLL iRoleBLL = new RoleBLL();

                List <Role> listRoles = iRoleBLL.CollectRoles(iRole);


                /* Get Role values from database and set it to
                *   viewbag to pass it to view for drop downlist*/
                IEnumerable <SelectListItem> roles = listRoles.Select(m => new SelectListItem
                {
                    Value = m.RoleID.ToString(),
                    Text  = m.RoleName
                });
                ViewBag.RoleId = roles;

                return(View(listRoles));
            }
            else
            {
                return(RedirectToAction("login", "home"));
            }
        }
Пример #9
0
        public void Create(RoleModel roleModel)
        {
            try
            {
                if (Validate(roleModel))
                {
                    return;
                }
                //using (var transaction = dbContext.Database.BeginTransaction())
                //{
                AspNetRole aspNetRole = new AspNetRole();
                roleModel.Id = Guid.NewGuid().ToString();
                aspNetRole.SetDefaultValues();
                RoleMapper.Map(roleModel, aspNetRole);
                dbContext.AspNetRoles.Add(aspNetRole);

                base.SaveChanges();
                // transaction.Commit();
                //remove all roles cache with sitemap nodes cache
                Common.Helpers.CacheHelper.RemoveCache(new CacheMemberKey()
                {
                    CacheKey = LookUps.CacheKeys.Roles, ObjectId = LookUps.CacheKeys.Roles.ToString()
                });

                roleModel.AddSuccess(Resources.RoleAddedSuccessfully, LookUps.SuccessType.Full);
                // }
            }
            catch (Exception ex)
            {
                base.HandleError(roleModel, CommonLayer.LookUps.ErrorType.Exception, ex);
                base.UndoUpdates();
            }
        }
Пример #10
0
        public async Task <PagedResultDTO <PostDTO> > GetPageAsync(int id, int page, int pageSize, bool justMyPosts, string srchStr = null)
        {
            var pagedResult = await _db.Posts.GetPageAsync(id, page, pageSize, justMyPosts, srchStr);

            pagedResult.Data.ForEach(p =>
                                     p.PostFiles = p.PostFiles.Count > 0 ?
                                                   new List <PostFile>()
            {
                p.PostFiles.First()
            }
                : new List <PostFile>()
                                     );

            Func <Post, PostDTO> func = post =>
            {
                var postDTO = PostMapper.ConvertToPostDTO(post);
                postDTO.Files       = FileMapper.ConvertToFileInfoDTOCollection(post.PostFiles);
                postDTO.UserDTO     = UserMapper.ConvertToUserDTO(post.User);
                postDTO.CommentsDTO = CommentMapper.ConvertToCommentDTOCollection(post.Comments);
                var usersDTOLikes = new List <UserDTO>();
                post.PostLikes.ToList().ForEach(pl =>
                {
                    var userDTO     = UserMapper.ConvertToUserDTO(pl.User);
                    userDTO.RoleDTO = RoleMapper.ConvertToRoleDTO(pl.User.Role);
                    usersDTOLikes.Add(userDTO);
                });
                postDTO.UsersLikes = usersDTOLikes;
                return(postDTO);
            };

            var pageResultDTO = PagedResultMapper.MapToDTO(pagedResult, func);

            return(pageResultDTO);
        }
        public void CreateDTOTest()
        {
            RoleMapper roleMapper = MapperFactory.createRoleMapper();
            var        result     = roleMapper.CreateDTO(role);

            Assert.IsInstanceOf <RoleDTO>(result);
        }
        public List <RoleDTO> GetAll()
        {
            var roles = _context.ApplicationRole
                        .Select(r => RoleMapper.RoleToDTO(r))
                        .ToList();

            return(roles);
        }
Пример #13
0
        public async Task <IActionResult> List([FromQuery] RoleListSearchRequest request)
        {
            var result = await _roleService.GetPagedList(RoleMapper.ToRoleSearchDto(request));

            var viewModels = RoleMapper.ToPagedListViewModel(result);

            return(Ok(viewModels));
        }
        public void CreateEntityTest()
        {
            RoleMapper roleMapper = MapperFactory.createRoleMapper();
            RoleDTO    roleDTO    = DTOFactory.CreateRoleDTO(role.Id, role.Name);
            var        result     = roleMapper.CreateEntity(roleDTO);

            Assert.IsInstanceOf <Role>(result);
        }
Пример #15
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder().SetBasePath(env.ContentRootPath).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
            RoleMapper.Initialize();
        }
Пример #16
0
        public void ConvertToRole_should_throw_argument_null_exception_when_input_is_null()
        {
            //arrange
            RoleDTO inputRoleDTO = null;

            //act
            var exception = Assert.Throws <ArgumentNullException>(() =>
                                                                  RoleMapper.ConvertToRole(inputRoleDTO));
        }
        public void Map_DependencyMap_Test()
        {
            // Arrange
            var dummyRoleMapper    = new RoleMapper();
            var dummyUserMapper    = new UserMapper(dummyRoleMapper);
            var dummyOptionMapper  = new OptionsMapper();
            var dummySectionMapper = new SectionMapper();

            IScriptMapper mapper = new ScriptMapper(dummyUserMapper, dummyOptionMapper,
                                                    dummySectionMapper, new CookieParser());

            var script = new Script
            {
                Options = new Options
                {
                    AnnouncerName = "test"
                },
                Operator = new User
                {
                    UserId = 1
                },
                Prompter = new User
                {
                    UserId = 1
                }
            };

            var expected = new ComparableTransferScript
            {
                Options = new TransferOptions
                {
                    AnnouncerName = "test"
                },
                Operator = new TransferUser
                {
                    UserId = 1
                },
                Prompter = new TransferUser
                {
                    UserId = 1
                }
            };

            //Act:
            var actual = mapper.Map(script);

            //Assert
            Assert.That(actual.Options.AnnouncerName,
                        Is.EqualTo(expected.Options.AnnouncerName));

            Assert.That(actual.Operator.UserId,
                        Is.EqualTo(expected.Operator.UserId));

            Assert.That(actual.Prompter.UserId,
                        Is.EqualTo(expected.Prompter.UserId));
        }
Пример #18
0
        public static void Create(RoleDto dto)
        {
            using (var db = new MainDBModelContainer())
            {
                var entity = RoleMapper.DtoToEntity(dto);

                db.RoleSet.Add(entity);
                db.SaveChanges();
            }
        }
Пример #19
0
        public async Task <ActionResult <int> > UpdateRole([FromBody] RoleInputModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            Role dataModel = RoleMapper.ToDataModel(model);
            int  id        = (int)await dictionaryStorage.RoleAddOrUpdate(dataModel);

            return(Ok(id));
        }
Пример #20
0
        public static User Map(Database.Users user)
        {
            User newUser = new User
            {
                Id     = user.Rowid,
                UserId = user.Userid,
                Role   = RoleMapper.Map(user.UserroleNavigation)
            };

            return(newUser);
        }
Пример #21
0
        public void Parse_Null_ReturnNull()
        {
            // Arrange
            var mapper = new RoleMapper();

            // Act
            var role = mapper.Parse(null);

            // Assert
            role.Should().BeNull();
        }
        public void CreateDTOListTest()
        {
            RoleMapper  roleMapper = MapperFactory.createRoleMapper();
            List <Role> roles      = new List <Role>();

            roles.Add(role);
            roles.Add(role);
            var result = roleMapper.CreateDTOList(roles);

            Assert.IsInstanceOf <List <RoleDTO> >(result);
        }
Пример #23
0
        public ActionResult Update([FromForm] roleViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var serializeRole = RoleMapper.SerializeRole(model);
            var newRole       = _role.EditRole(serializeRole);

            return(Ok(newRole));
        }
        public IActionResult Get(string entityname, [FromQuery] Guid?roleId)
        {
            try
            {
                var stopwatch = StopwatchLogger.Start(_log);
                _log.Info("Called EntitySecurityController Get {0}=", JsonConvert.SerializeObject(entityname));
                var entityId           = _iMetadataManager.GetEntityContextByEntityName(entityname);
                var roles              = _managerRole.Roles(TenantCode, roleId);
                var functionSecurities = _managerEntitySecurity.GetFunctionSecurities(TenantCode, entityId, roleId);
                var accessLevel        = _managerEntitySecurity.GetAccessLevel();
                var operationLevel     = _managerEntitySecurity.GetOperationLevel();

                foreach (var role in roles)
                {
                    // var itsEntitySecurity=(from entitySecurity in entitySecurities where entitySecurity.RoleId==role.RoleId select entitySecurity).FirstOrDefault();

                    // if(itsEntitySecurity!=null)
                    //  itsEntitySecurity.EntityId=string.Empty;
                    var thisEntityFunctions = DataUtility.GetFunctionEntityWise(entityId);
                    foreach (var thisEntityFunction in thisEntityFunctions)
                    {
                        var itsFunctionSecurity = (from functionSecurity in functionSecurities where functionSecurity.RoleId == role.RoleId &&
                                                   functionSecurity.FunctionContext == thisEntityFunction.FunctionContext select functionSecurity).FirstOrDefault();
                        if (itsFunctionSecurity != null)
                        {
                            thisEntityFunction.EntityId         = itsFunctionSecurity.EntityId;
                            thisEntityFunction.EntitySecurityId = itsFunctionSecurity.EntitySecurityId;
                            thisEntityFunction.SecurityCode     = itsFunctionSecurity.SecurityCode;
                            thisEntityFunction.RoleId           = itsFunctionSecurity.RoleId;
                        }
                        else
                        {
                            thisEntityFunction.RoleId   = role.RoleId;
                            thisEntityFunction.EntityId = entityId;
                        }
                    }

                    role.Entity = new RoleMapperEntityInfo()
                    {
                        Functions      = thisEntityFunctions,
                        AccessLevel    = RoleMapper.GetAccessLevels(accessLevel, new Guid(AccessLevelGuid.RoleFunction)),
                        OperationLevel = RoleMapper.GetAccessLevels(operationLevel, new Guid(AccessLevelGuid.RoleFunction))
                    };
                }

                stopwatch.StopAndLog("End EntitySecurityController Get");
                return(Ok(roles));
            }
            catch (Exception ex)
            {
                _log.Error(ExceptionFormatter.SerializeToString(ex));
                return(StatusCode((int)HttpStatusCode.InternalServerError, ApiConstant.CustomErrorMessage));
            }
        }
Пример #25
0
        public void SetValue_Null_SetNullToParameter()
        {
            // Arrange
            var mapper    = new RoleMapper();
            var parameter = new SqlParameter();

            // Act
            mapper.SetValue(parameter, null);

            // Assert
            parameter.Value.Should().Be(DBNull.Value);
        }
Пример #26
0
        public void Parse_InvalidEmail_ThrowException()
        {
            // Arrange
            var roleId = 0;
            var mapper = new RoleMapper();

            // Act
            Action action = () => mapper.Parse(roleId);

            // Assert
            action.Should().Throw <ArgumentException>();
        }
Пример #27
0
        public void Parse_ValidRole_ReturnParsedRole()
        {
            // Arrange
            var validRole = Role.Basic;
            var mapper    = new RoleMapper();

            // Act
            var role = mapper.Parse(validRole.Id);

            // Assert
            role.Should().Be(validRole);
        }
Пример #28
0
 public static RoleDto Read(int id)
 {
     using (var db = new MainDBModelContainer())
     {
         var data = db.RoleSet.Find(id);
         if (data != null)
         {
             return(RoleMapper.EntityToDto(data));
         }
         throw new ElementNotFoundException();
     }
 }
Пример #29
0
        public ActionResult Edit(EditUserViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var user = UserMapper.Map(viewModel);
                //userService.Update(user);
                RoleService.SetUserRoles(RoleMapper.GetRoles(viewModel.UserInRoles), user.Id);
                return(RedirectToAction("Index"));
            }

            return(View());
        }
Пример #30
0
        /// <summary>
        /// Recupera los roles que son exclusivamente de usuarios web
        /// </summary>
        /// <returns></returns>
        public List <Role> GetForWebUser()
        {
            RoleMapper  roleMapper = new RoleMapper();
            List <Role> roles      = roleMapper.GetForWebUser();

            if (roles == null)
            {
                AddError(new ResultBE(ResultBE.Type.EMPTY_PROFILE, "No existen roles."));
            }

            return(roles);
        }
Пример #31
0
        public ActionResult MapRole()
        {
            try
            {
                var catetoryId = int.Parse(Request.Form["Category"]);
                var locationId = int.Parse(Request.Form["Location"]);
                var terminalId = int.Parse(Request.Form["Terminal"]);
                var subTerminalId = int.Parse(Request.Form["SubTerminal"]);
                var roleId = int.Parse(Request.Form["Role"]);

                AP1Entities e = new AP1Entities();
                RoleMapper role = e.Roles.Where(r => r.CategoryId == catetoryId &&
                                                       r.BandaraId == locationId &&
                                                       r.TerminalId == terminalId &&
                                                       r.SubTerminalId == subTerminalId &&
                                                       r.Role == roleId).FirstOrDefault();
                if (role == null)
                {
                    string roleName = GetRoleName(catetoryId, roleId);
                    role = new RoleMapper(catetoryId, locationId, terminalId, subTerminalId, roleId, roleName, "TenantPage");
                    e.Roles.Add(role);
                }
                else
                {
                    role.CategoryId = catetoryId;
                    role.BandaraId = locationId;
                    role.TerminalId = terminalId;
                    role.SubTerminalId = subTerminalId;
                    role.Name = GetRoleName(catetoryId, roleId);
                    role.HomePage = "TenantPage";
                }

                e.SaveChanges();
                ViewBag.HasError = false;
            }
            catch (Exception ex)
            {
                ViewBag.HasError = true;
                ViewBag.ErrorMessage = ex.Message;
            }

            return View("MapRoleResult");
        }
Пример #32
0
        public static RoleEntity isAuthorized(string username, string formPath)
        {
            if (formPath.Contains("?"))
            {
                formPath = formPath.Substring(0 ,formPath.IndexOf("?"));
            }

            List<RoleEntity> roles = new RoleMapper().GetRoleForUser(username);

            foreach (RoleEntity role in roles)
            {
                if (new RoleMapper().RoleCanViewForm(role.Id, formPath))
                {
                    return roles[0];
                }
            }

            return null;
        }
Пример #33
0
        public CascadingDropDownNameValue[] GetRoles(string knownCategoryValues, string category)
        {
            List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

            List<RoleEntity> list = new RoleMapper().List("");
            foreach (RoleEntity ent in list)
            {
                CascadingDropDownNameValue cdnv = new CascadingDropDownNameValue(ent.Title, ent.Id.ToString());
                values.Add(cdnv);
            }

            return values.ToArray();
        }
 public IReadOnlyCollection<Role> GetRoles()
 {
     var query = new RolesQuery(dbContext.Roles);
     RoleMapper roleMapper = new RoleMapper();
     return roleMapper.Map(query.Execute()).ToList();
 }
 public Role GetRole(Guid roleId)
 {
     RoleWithPermissionsQuery query = new RoleWithPermissionsQuery(dbContext.Roles);
     RoleMapper roleMapper = new RoleMapper();
     return roleMapper.Map(query.Execute(roleId));
 }