Ejemplo n.º 1
0
        public Scenario CreateScenario([FromBody] Scenario input)
        {
            if (User.Claims.FirstOrDefault(x => x.Type == ClaimsIdentity.DefaultRoleClaimType).Value ==
                Constants.RoleNames.SimpleUser)
            {
                throw new Exception("Не доступно простому пользователю");
            }
            if (User.Claims.FirstOrDefault(x => x.Type == ClaimsIdentity.DefaultRoleClaimType).Value ==
                Constants.RoleNames.Admin)

            {
                var returningScenario = _scenarioRepository.CreateScenario(input);
                _scenarioRepository.SaveChanges();
                return(returningScenario);
            }
            var children = _userGroupRepository.GetChildrenGroups(GetUserGroupId());

            if (children.Contains(input.UserGroupId))
            {
                var returningScenario = _scenarioRepository.CreateScenario(input);
                _scenarioRepository.SaveChanges();
                return(returningScenario);
            }
            else
            {
                throw new Exception("эта группа пользователей вам недоступна");
            }
        }
Ejemplo n.º 2
0
        public string Init()
        {
            _loginService.Register(
                new Model.DTO.UserInfoDTO.LoginPassword()
            {
                Login    = "******",
                Password = "******"
            },
                Constants.RoleNames.Admin);
            _adminRepository.Create(new Admin()
            {
                FIO   = "DimaK",
                Login = "******"
            });
            _userLoginInfoRepository.SaveChanges();
            _loginService.Register(
                new Model.DTO.UserInfoDTO.LoginPassword()
            {
                Login    = "******",
                Password = "******"
            },
                Constants.RoleNames.Integrator);
            var ug = _userGroupRepository.Create(new UserGroup()
            {
                Name = "test1",
            });

            _userRepository.Create(new User()
            {
                Login       = "******",
                UserGroupId = ug.Id,
                UserType    = UserType.Integrator
            });
            var sc = _scenarioRepository.CreateScenario(new Scenario()
            {
                Author      = "DimaIntegr",
                Description = "test",
                Name        = "test",
                Publicity   = false,
                Script      = "TestScript",
                Type        = 1,
                UserGroupId = ug.Id
            });
            var ct = _controllerRepository.CreateController(new SmartController()
            {
                Adress      = "http://localhost:5000/api",
                Description = "test",
                Name        = "test",
                Password    = "******",
                Type        = 1,
                UserGroupId = ug.Id
            });
            var list = new List <KeyValuePair <long, bool> >();

            list.Add(new KeyValuePair <long, bool>(sc.Id, true)
                     );
            _connections.Set(list, ct.Id);
            _userGroupRepository.SaveChanges();
            return(ct.Id.ToString() + " " + sc.Id.ToString());
        }
Ejemplo n.º 3
0
        public Scenario CreateScenario([FromBody] Scenario input)
        {
            var children = _userGroupRepository.GetChildrenGroups(GetUserGroupId());

            if (children.Contains(input.UserGroupId))
            {
                var returningScenario = _scenarioRepository.CreateScenario(input);
                _scenarioRepository.SaveChanges();
                return(returningScenario);
            }
            else
            {
                throw new Exception("эта группа пользователей вам недоступна");
            }
        }