예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddCoalesce(builder =>
            {
                builder
                .AddContext <AppDbContext>()
                .UseDefaultDataSource(typeof(MyDataSource <,>))
                .UseDefaultBehaviors(typeof(MyBehaviors <,>));

                // This breaks on non-windows platforms, see https://github.com/dotnet/corefx/issues/11897
                builder.UseTimeZone(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                    ? TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time")
                    : TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles"));
            });

            services.AddAuthentication(DemoMiddleware.AuthenticationScheme).AddCookie(DemoMiddleware.AuthenticationScheme);

            RoleMapping.Add("Admin", "S-1-5-4"); // Interactive user.
            RoleMapping.Add("User", "S-1-1-0");  // Everyone who has logged on
        }
예제 #2
0
        // 返回用户对应的角色, 在实际中, 可以从SQL数据库中读取用户的角色信息
        private string GetRole(string UserName)
        {
            if (string.IsNullOrEmpty(UserName))
            {
                return("游客");
            }
            else
            {
                UserDto   dto = new UserDto();
                DataTable dt  = CMSService.SelectOne("User", "CMSUser", "UserName='******'");
                foreach (DataRow dataRow in dt.Rows)
                {
                    dto = UserMapping.getDTO(dataRow);
                }


                string   userRoles = "";
                string   roleName  = "";
                string   s         = dto.UserRoles;
                string[] sArray    = s.Split(',');
                foreach (string i in sArray)
                {
                    DataTable dataTable = CMSService.SelectOne("Role", "CMSRole", "RoleId=" + int.Parse(i));
                    foreach (DataRow dataRow in dataTable.Rows)
                    {
                        RoleDto roleDto = new RoleDto();
                        roleDto  = RoleMapping.getDTO(dataRow);
                        roleName = roleDto.RoleName;
                    }
                    userRoles = userRoles + roleName + ",";
                    userRoles = userRoles.Substring(0, userRoles.Length - 1);
                }
                return(userRoles);
            }
        }
        public void GetCustomerProfileTest_InvalidIsacPrifile()
        {
            bool IsNewCustomer = true;
            CustomerHPIDUtils             custUtils    = new CustomerHPIDUtils();
            TokenDetails                  sessionToken = new TokenDetails();
            UserAuthenticationInterchange hppAuthInt   = new UserAuthenticationInterchange()
            {
                ClientId = "hpsa9"
            };

            User aProfile = new User()
            {
                EmailConsent = true
            };

            List <RoleMapping> roleMappings = new List <RoleMapping>();
            RoleMapping        role         = new RoleMapping();

            role.RoleId        = 1;
            role.RoleMappingId = 1;
            role.UserId        = 1;
            role.CreatedDate   = DateTime.UtcNow;
            roleMappings.Add(role);
            aProfile.RoleMappings = roleMappings;

            sessionToken.AccessToken = "sessionToken";
            hpidUtilsMock.Setup(x => x.GetIdsAndProfile(It.IsAny <CustomerIds>(), It.IsAny <string>(), It.IsAny <GetProfileResponse>())).Returns(true);

            isacMock.Setup(x => x.FindOrInsertHPIDProfile(It.IsAny <ResponseBase>(), It.IsAny <RequestFindOrInsertHPIDProfile>(), out IsNewCustomer)).Returns(aProfile);

            GetProfileResponse response = custUtils.GetCustomerProfileforHPID(hppAuthInt, sessionToken, false, It.IsAny <APIMethods>());

            Assert.IsTrue(response.ErrorList.Count == 1);
            Assert.IsTrue(IsNewCustomer);
        }
예제 #4
0
        public ActionResult Edit(RoleModel model)
        {
            try{
                RoleDto   dto = new RoleDto();
                DataTable dt  = CMSService.SelectOne("Role", "CMSRole", "RoleId=" + model.RoleId);
                foreach (DataRow dr in dt.Rows)
                {
                    dto                 = RoleMapping.getDTO(dr);
                    dto.RoleName        = model.RoleName;
                    dto.RoleDescription = model.RoleDescription;
                }
                string  JsonString = JsonHelper.JsonSerializerBySingleData(dto);
                Message msg        = CMSService.Update("Role", JsonString);
                // TODO: Add update logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                Message msg = new Message();
                msg.MessageStatus = "Error";
                msg.MessageInfo   = "操作出错了";
                ViewBag.Status    = msg.MessageStatus;
                ViewBag.msg       = msg.MessageInfo;
                return(View());
            }
        }
예제 #5
0
        private MappingRoleToRoleGroupEntryModel CreateEntryModel(int roleGroupPK)
        {
            tblM_RoleGroup roleGroup = Db.tblM_RoleGroup.Find(roleGroupPK);

            if (roleGroup == null)
            {
                throw new KairosException($"Role group id '{roleGroupPK}' is not found.");
            }

            MappingRoleToRoleGroupEntryFormData formData = new MappingRoleToRoleGroupEntryFormData();
            List <Control> formControls = CreateFormControls(roleGroupPK);

            var roleGroupDTO = new RoleGroup.Queries.RoleGroupQuery(Db).GetByPrimaryKey(roleGroupPK);
            var roleMapping  = new RoleMapping();

            roleMapping.RoleGroup_PK            = roleGroupPK;
            roleMapping.Title                   = roleGroupDTO.Title;
            roleMapping.Description             = roleGroupDTO.Description;
            roleMapping.MappingRoleToRoleGroups = mappingRoleToRoleGroupQuery.GetMappingListByRoleGroupPk(roleGroupPK);

            return(new MappingRoleToRoleGroupEntryModel()
            {
                FormData = formData,
                FormControls = formControls,
                Model = roleMapping,
            });
        }
예제 #6
0
        //
        // GET: /Role/Delete/5
        public ActionResult Delete(int id)
        {
            try{
                RoleDto   dto = new RoleDto();
                DataTable dt  = CMSService.SelectOne("Role", "CMSRole", "RoleId=" + id);
                foreach (DataRow dr in dt.Rows)
                {
                    dto = RoleMapping.getDTO(dr);
                }
                string    strwhere = "CHARINDEX('" + dto.RoleName + "', UserRoles)>0";
                DataTable userdt   = CMSService.SelectSome("User", "CMSUser", strwhere);

                Message msg = new Message();
                if (userdt.Rows.Count > 0)
                {
                    msg.MessageInfo = "此角色还有" + userdt.Rows.Count + "条相关数据,不允许删除";
                    return(RedirectTo("/Role/Index", msg.MessageInfo));
                }
                else
                {
                    msg             = CMSService.Delete("Role", "CMSRole", "RoleId=" + id);
                    msg.MessageInfo = "数据删除操作成功";
                    return(RedirectTo("/Role/Index", msg.MessageInfo));
                }
            }
            catch
            {
                Message msg = new Message();
                msg.MessageStatus = "Error";
                msg.MessageInfo   = "操作出错了";
                ViewBag.Status    = msg.MessageStatus;
                ViewBag.msg       = msg.MessageInfo;
                return(View());
            }
        }
예제 #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // Add Entity Framework services to the services container.
            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddMvc().AddJsonOptions(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

                var resolver = options.SerializerSettings.ContractResolver;
                if (resolver != null)
                {
                    (resolver as DefaultContractResolver).NamingStrategy = null;
                }

                options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

                options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            });

            ReflectionRepository.AddContext <AppDbContext>();

            RoleMapping.Add("Admin", "S-1-5-4"); // Interactive user.
            RoleMapping.Add("User", "S-1-1-0");  // Everyone who has logged on.
        }
예제 #8
0
        //
        // GET: /Role/
        public ActionResult Index(int?p)
        {
            Pager pager = new Pager();

            pager.table      = "CMSRole";
            pager.strwhere   = "1=1";
            pager.PageSize   = 10;
            pager.PageNo     = p ?? 1;
            pager.FieldKey   = "RoleId";
            pager.FiledOrder = "RoleId Desc";
            pager            = CMSService.SelectAll("Role", pager);

            List <RoleDto> list = new List <RoleDto>();

            foreach (DataRow dr in pager.EntityDataTable.Rows)
            {
                RoleDto dto = RoleMapping.getDTO(dr);
                list.Add(dto);
            }
            pager.Entity = list.AsQueryable();

            ViewBag.PageNo      = p ?? 1;
            ViewBag.PageCount   = pager.PageCount;
            ViewBag.RecordCount = pager.Amount;
            ViewBag.Message     = pager.Amount;

            return(View(pager.Entity));
        }
예제 #9
0
        private RoleMappingModel MapToModel(RoleMapping entity, string requestId = "")
        {
            // Perform mapping
            var model = RoleMappingModel.Empty;

            model.Id          = entity.Id ?? String.Empty;
            model.AdGroupName = entity.AdGroupName ?? String.Empty;
            model.Role        = new RoleModel
            {
                Id          = entity.Role.Id,
                DisplayName = entity.Role.DisplayName
            };
            model.Permissions = new List <PermissionModel>();
            foreach (var item in entity.Permissions)
            {
                var permissionmodel = new PermissionModel()
                {
                    Id   = item.Id,
                    Name = item.Name
                };
                model.Permissions.Add(permissionmodel);
            }

            return(model);
        }
예제 #10
0
        public static IMapping CreatMapping(string DtoName)
        {
            IMapping Mapping = null;

            if (DtoName == "User")
            {
                Mapping = new UserMapping();
            }
            if (DtoName == "Role")
            {
                Mapping = new RoleMapping();
            }
            if (DtoName == "Category")
            {
                Mapping = new CategoryMapping();
            }
            if (DtoName == "Article")
            {
                Mapping = new ArticleMapping();
            }
            if (DtoName == "Image")
            {
                Mapping = new ImageMapping();
            }
            if (DtoName == "Customer")
            {
                Mapping = new CustomerMapping();
            }
            if (DtoName == "Tizhi")
            {
                Mapping = new TizhiMapping();
            }
            if (DtoName == "Xueya")
            {
                Mapping = new XueyaMapping();
            }
            if (DtoName == "Jianyan")
            {
                Mapping = new JianyanMapping();
            }
            if (DtoName == "Chufang")
            {
                Mapping = new ChufangMapping();
            }
            if (DtoName == "Jixiao")
            {
                Mapping = new JixiaoMapping();
            }
            if (DtoName == "Fankui")
            {
                Mapping = new FankuiMapping();
            }
            if (DtoName == "Yuyue")
            {
                Mapping = new YuyueMapping();
            }
            return(Mapping);
        }
        public AuthorizationPolicyManager(IConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            _roleMapping = new RoleMapping(config);
            _options     = new AccessPolicyOptions(config);
        }
예제 #12
0
        public IActionResult OnPostRole(int id, [FromForm] int newRoleId)
        {
            var mapping = new RoleMapping {
                AccountId = id,
                RoleId    = newRoleId
            };

            _roleMappingRepo.Insert(mapping);
            return(RedirectToPage());
        }
예제 #13
0
        public IActionResult OnGetRole(int id, int roleId)
        {
            var mapping = new RoleMapping {
                AccountId = id,
                RoleId    = roleId
            };

            _roleMappingRepo.Remove(mapping);
            return(RedirectToPage());
        }
예제 #14
0
        public bool Exist(RoleMapping model)
        {
            using var conn = new MySqlConnection(_connStr);
            conn.Open();
            var sql = $@"
                SELECT COUNT(1) FROM RoleMappings
                WHERE
                  RoleId = @{nameof(RoleMapping.RoleId)} AND AccountId = @{nameof(RoleMapping.AccountId)};
            ";

            return(conn.ExecuteScalar <bool>(sql, model));
        }
예제 #15
0
        public bool Remove(RoleMapping model)
        {
            using var conn = new MySqlConnection(_connStr);
            conn.Open();
            var sql = $@"
                DELETE FROM RoleMappings
                WHERE
                  RoleId = @{nameof(RoleMapping.RoleId)} AND AccountId = @{nameof(RoleMapping.AccountId)};
            ";

            return(conn.Execute(sql, model) == 1);
        }
예제 #16
0
        //用户角色列表
        public static List <RoleDto> GetRolesList(string strwhere)
        {
            List <RoleDto> RolesList = new List <RoleDto>();
            DataTable      dt        = CMSService.SelectSome("Role", "CMSRole", strwhere);

            foreach (DataRow dr in dt.Rows)
            {
                RoleDto dto = RoleMapping.getDTO(dr);
                RolesList.Add(dto);
            }

            return(RolesList);
        }
예제 #17
0
 public void Mapping()
 {
     RoleMapping.Add("test", "1");
     Assert.True(RoleMapping.Map("test").Count() == 1);
     RoleMapping.Add("test", "2");
     Assert.True(RoleMapping.Map("test").Count() == 2);
     RoleMapping.Add("test", "1");
     Assert.True(RoleMapping.Map("test").Count() == 2);
     RoleMapping.Remove("test", "1");
     Assert.True(RoleMapping.Map("test").Count() == 1);
     RoleMapping.Remove("best", "3");
     Assert.True(RoleMapping.AllMaps.Count() == 2);
 }
예제 #18
0
 public NtlmAuthorizationPolicy(string roles, RoleMapping mapping)
 {
     Assert = (ctx) => {
         foreach (var r in roles.Split(','))
         {
             string role = r.Trim();
             if (!string.IsNullOrEmpty(role) && mapping.IsUserInRole(ctx.User, role))
             {
                 return(true);
             }
         }
         return(false);
     };
 }
예제 #19
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // Add Entity Framework services to the services container.
            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddCoalesce(builder => builder
                                 .AddContext <AppDbContext>()
                                 .UseDefaultDataSource(typeof(MyDataSource <,>))
                                 .UseDefaultBehaviors(typeof(MyBehaviors <,>))
                                 .UseTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"))
                                 );

            var internalConfig = new InternalConfig();

            Configuration.Bind(internalConfig);

            services.AddSingleton <IInternalConfig, InternalConfig>(provider => internalConfig);

            services.AddCors();

            services.AddMvc().AddJsonOptions(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

                if (options.SerializerSettings.ContractResolver is DefaultContractResolver resolver)
                {
                    resolver.NamingStrategy = null;
                }
                options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

                options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            });

            services.AddHttpClient();

            services.AddMemoryCache();

            services.AddScoped <IWeatherService, WeatherService>();

            services.AddAuthentication(DemoMiddleware.AuthenticationScheme)
            .AddCookie(DemoMiddleware.AuthenticationScheme, options => {
                options.AccessDeniedPath = "/Account/AccessDenied/";
                options.LoginPath        = "/Account/Login";
                options.LogoutPath       = "/Account/LogOff";
            });

            RoleMapping.Add("Admin", "S-1-5-4"); // Interactive user.
            RoleMapping.Add("User", "S-1-1-0");  // Everyone who has logged on.
        }
예제 #20
0
        public void SubmitIdeaAssignments(RestAPIAddIdeaStateResponse response, int UserId, int IdeaId, int ideaState)
        {
            DatabaseWrapper.databaseOperation(response,
                                              (context, query) =>
            {
                Role roles = null;
                RoleMapping roleMapping   = null;
                IdeaAssignment assignment = null;

                if (ideaState == (int)IdeaStatusTypes.ReviewPending)
                {
                    roles = query.GetAllRoleMappings(context, RoleTypes.REVIEWER.ToString());
                }
                else if (ideaState == (int)IdeaStatusTypes.SponsorPending)
                {
                    roles = query.GetAllRoleMappings(context, RoleTypes.SPONSOR.ToString());
                }
                else if (ideaState == (int)IdeaStatusTypes.Sponsored)
                {
                    roles = query.GetAllRoleMappings(context, RoleTypes.SALES.ToString());
                }

                if (roles == null || roles.RoleMappings.Count == 0)
                {
                    response.ErrorList.Add(Faults.ReviewerNotExists);
                    return;
                }

                roleMapping = query.GetUserRoleMappingByRoleId(context, roles.RoleId);
                assignment  = query.GetAssignmentByIdeaId(context, IdeaId);

                if (assignment != null)
                {
                    assignment.ReviewByUserId = roleMapping.UserId;
                }
                else
                {
                    IdeaAssignment ideaassignment = new IdeaAssignment()
                    {
                        IdeaId = IdeaId, ReviewByUserId = roleMapping.UserId, IsActive = true, CreatedDate = DateTime.UtcNow
                    };
                    query.AddIdeaAssignment(context, ideaassignment);
                }

                context.SubmitChanges();
            }
                                              , readOnly: false
                                              );
        }
예제 #21
0
        private RoleMappingModel MapToModel(RoleMapping entity, string requestId = "")
        {
            // Perform mapping
            var model = RoleMappingModel.Empty;

            model.Id          = entity.Id ?? String.Empty;
            model.AdGroupName = entity.AdGroupName ?? String.Empty;
            model.AdGroupId   = entity.AdGroupId ?? String.Empty;
            model.RoleName    = entity.RoleName ?? String.Empty;
            model.ProcessStep = entity.ProcessStep ?? String.Empty;
            model.ProcessType = entity.ProcessType ?? String.Empty;
            model.Channel     = entity.Channel ?? String.Empty;

            return(model);
        }
예제 #22
0
        //
        // GET: /Role/Edit/5
        public ActionResult Edit(int id)
        {
            RoleModel model = new RoleModel();
            DataTable dt    = CMSService.SelectOne("Role", "CMSRole", "RoleId=" + id);

            foreach (DataRow dr in dt.Rows)
            {
                RoleDto dto = new RoleDto();
                dto                   = RoleMapping.getDTO(dr);
                model.RoleName        = dto.RoleName;
                model.RoleDescription = dto.RoleDescription;
                model.RoleId          = dto.RoleId;
            }

            return(View(model));
        }
예제 #23
0
        public bool Insert(RoleMapping model)
        {
            //Do not insert existing mapping, it thorws exceptions.
            if (Exist(model))
            {
                return(false);
            }

            using var conn = new MySqlConnection(_connStr);
            conn.Open();
            var sql = $@"
                INSERT INTO RoleMappings(RoleId, AccountId)
                VALUES (@{nameof(RoleMapping.RoleId)}, @{nameof(RoleMapping.AccountId)});
            ";

            return(conn.Execute(sql, model) == 1);
        }
예제 #24
0
        public IHttpActionResult CreateRange([FromBody] RoleMapping roleMapping)
        {
            ThrowIfUserHasNoRole(createRole);

            if (roleMapping.RoleGroup_PK == 0)
            {
                throw new KairosException("Role group primary key is 0, it's not allowed.");
            }

            using (var roleMappingCreateHandler = new RoleMappingCreateHandler(Db, ActiveUser, new MappingRoleToRoleGroupValidator(), new MappingRoleToRoleGroupFactory(Db, ActiveUser), new MappingRoleToRoleGroupQuery(Db), AccessControl))
            {
                using (var transaction = new TransactionScope())
                {
                    var saveResult = roleMappingCreateHandler.Save(roleMapping: roleMapping, dateStamp: DateTime.Now);
                    transaction.Complete();
                    return(Ok(new SuccessResponse(saveResult, "SUCCESS")));
                }
            }
        }
예제 #25
0
 public int CreateRoleMapping(RoleMapping c)
 {
     try
     {
         SqlParameter[] m = new SqlParameter[4];
         m[0]           = new SqlParameter("@UserID", c.UserID);
         m[1]           = new SqlParameter("@RoleID", c.RoleID);
         m[2]           = new SqlParameter("@MappedDate", c.MappedDate);
         m[3]           = new SqlParameter("@MapID", SqlDbType.Int);
         m[3].Direction = ParameterDirection.Output;
         SqlHelper.ExecuteNonQuery(Connection.Connection_string, CommandType.StoredProcedure, "LP_Coupon_Insert", m);
         object ivalue = m[3].Value;
         return((int)ivalue);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #26
0
        public RoleServiceTest()
        {
            var roleStore = Mock.Of <IRoleStore <Role> >();

            roleManager = new Mock <RoleManager <Role> >(roleStore, null, null, null, null);

            var userStore = Mock.Of <IUserStore <User> >();

            userManager = new Mock <UserManager <User> >(userStore, null, null, null, null, null, null, null, null);

            repository = new Mock <IRoleRepository>();

            var roleMappingProfile  = new RoleMapping();
            var mapperConfiguration = new MapperConfiguration(cfg => cfg.AddProfile(roleMappingProfile));

            mapper = new Mapper(mapperConfiguration);

            roleService = new RoleService(roleManager.Object, userManager.Object, repository.Object, mapper);
        }
        public void GetCustomerProfileByAuthenticationTest_Success()
        {
            bool IsNewCustomer             = false;
            CustomerHPIDUtils custUtils    = new CustomerHPIDUtils();
            RoleUtils         rlUtils      = new RoleUtils();
            TokenDetails      sessionToken = new TokenDetails();

            sessionToken.AccessToken = "sessionToken";
            hpidUtilsMock.Setup(x => x.GetHPIDSessionToken(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <GetProfileResponse>(), It.IsAny <string>(), It.IsAny <int>())).Returns(sessionToken);
            hpidUtilsMock.Setup(x => x.GetIdsAndProfile(It.IsAny <CustomerIds>(), It.IsAny <string>(), It.IsAny <GetProfileResponse>())).
            Callback((CustomerIds i, string u, GetProfileResponse r) =>
            {
                i = new CustomerIds()
                {
                    HPIDid = "hpidid", HPPid = "hppid"
                };
                r.CustomerProfileObject = new CustomerProfile();
            }).Returns(true);


            User aProfile = new User()
            {
                EmailConsent = true
            };

            List <RoleMapping> roleMappings = new List <RoleMapping>();
            RoleMapping        role         = new RoleMapping();

            role.RoleId        = 1;
            role.RoleMappingId = 1;
            role.UserId        = 1;
            role.CreatedDate   = DateTime.UtcNow;
            roleMappings.Add(role);
            aProfile.RoleMappings = roleMappings;
            isacMock.Setup(x => x.FindOrInsertHPIDProfile(It.IsAny <ResponseBase>(), It.IsAny <RequestFindOrInsertHPIDProfile>(), out IsNewCustomer)).Returns(aProfile);



            GetProfileResponse response = custUtils.GetCustomerProfileByAuthentication(new UserAuthenticationInterchange(), It.IsAny <bool>(), "access", "url", It.IsAny <APIMethods>());

            Assert.IsTrue(response.ErrorList.Count == 0);
            Assert.IsTrue(response.CustomerProfileObject.EmailConsent.Equals(EmailConsentType.Y.ToString()));
        }
        public void Insert(RoleMapping mappingRole, DateTime dateStamp)
        {
            if (mappingRole == null)
            {
                throw new ArgumentNullException("MappingRoleToRoleGroup model is null.");
            }

            Delete(mappingRole.RoleGroup_PK);
            Db.SaveChanges();

            foreach (var mappingRoleToRoleGroupDTO in mappingRole.MappingRoleToRoleGroups)
            {
                mappingRoleToRoleGroupDTO.RoleGroup_PK = mappingRole.RoleGroup_PK;
                if (mappingRoleToRoleGroupDTO.IsChecked)
                {
                    tblM_MappingRoleToRoleGroup mappingRoleToRoleGroup = mappingRoleToRoleGroupFactory.CreateFromDTO(mappingRoleToRoleGroupDTO, dateStamp);
                    Db.tblM_MappingRoleToRoleGroup.Add(mappingRoleToRoleGroup);
                }
            }
        }
예제 #29
0
        //多个用户角色,从ID转化成名字
        public static string RolesIdToRolesName(string RoesId)
        {
            string userRoles = "";
            string roleName  = "";
            string s         = RoesId;

            string[] sArray = s.Split(',');
            foreach (string i in sArray)
            {
                DataTable dt = CMSService.SelectOne("Role", "CMSRole", "RoleId=" + int.Parse(i));
                foreach (DataRow dataRow in dt.Rows)
                {
                    RoleDto roleDto = new RoleDto();
                    roleDto  = RoleMapping.getDTO(dataRow);
                    roleName = roleDto.RoleName;
                }
                userRoles = userRoles + roleName + ",";
            }
            userRoles = userRoles.Substring(0, userRoles.Length - 1);
            return(userRoles);
        }
예제 #30
0
            public static RoleMapping roleMapping(S_RoleMapping item)
            {
                if (item == null)
                {
                    return(null);
                }

                var data = new RoleMapping()
                {
                    id     = item.id,
                    role   = item.role,
                    userId = item.userId
                };

                if (item.S_Role != null)
                {
                    data.roleObj = role(item.S_Role);
                }

                return(data);
            }