public ActionResult PostCreateEditRole(ROLE role)
 {
     try
     {
         result = new Result();
         if (role.RoleId > 0)
         {
             ROLE find = db.ROLEs.Find(role.RoleId);
             //   find.hierarchy_level = role.hierarchy_level;
             //  find.parent_id = role.parent_id;
             find.IsActive        = role.IsActive;
             find.IsPublic        = role.IsPublic;
             find.RoleName        = role.RoleName;
             db.Entry(find).State = System.Data.Entity.EntityState.Modified;
             result.Message       = string.Format(BaseConst.MSG_SUCCESS_UPDATE, "Role");
         }
         else
         {
             ////   role.application_type_id = SessionUtil.GetApplicationTypeID();
             long prevRoleBit = db.ROLEs.Where(x => x.CompanyId == role.CompanyId).Max(x => x.RoleBit);
             role.RoleBit   = prevRoleBit * 2;
             role.CompanyId = role.CompanyId;
             db.ROLEs.Add(role);
             result.Message = string.Format(BaseConst.MSG_SUCCESS_CREATE, "Role");
         }
         BaseUtil.SetSessionValue(UserInfo.IsCompanyAddUpdate.ToString(), "0");
         db.SaveChanges();
         BaseUtil.SetSessionValue(UserInfo.IsCompanyAddUpdate.ToString(), "1");
     }
     catch (Exception ex)
     {
         result.Message = ex.Message;
     }
     return(Json(result));
 }
        private void btnAddUser_Click(object sender, RoutedEventArgs e)
        {
            if (EditUser != null && objdbDataAccess.CheckUserNameAvailability(txtUserName.Text))
            {
                MessageBox.Show("Username already Exists!!!", "Username Error", MessageBoxButton.OK, MessageBoxImage.Error);
                clearFields();
                return;
            }
            USER objnewUser = new USER();

            objnewUser.UserName        = txtUserName.Text;
            objnewUser.Password        = txtPassword.Password;
            objnewUser.ConfirmPassword = txtConfirmPassword.Password;
            objnewUser.EmailId         = txtEmailId.Text;
            objnewUser.CreatedDate     = DateTime.Now;
            ROLE role = (ROLE)cRoles.SelectedItem;

            objnewUser.RoleId = Convert.ToInt32(role.RoleID);
            bool isNewUserInserted = objdbDataAccess.saveUser(objnewUser);

            if (isNewUserInserted)
            {
                MessageBox.Show("User Inserted Successfully");
                clearFields();
            }
        }
Пример #3
0
        public async Task <bool> AssignUserToTeamWithBasicRole(string userId, string assignerId, int teamId)
        {
            TEAM team = _teamRepository.GetTeamById(teamId);
            USER user = await _userRepository.GetUserById(userId);

            if (team != null && user != null)
            {
                USER_TEAM userTeam = new USER_TEAM
                {
                    TEAM = team,
                    USER = user
                };

                ROLE            basicRole    = _roleRepository.GetBasicRole();
                USER_TEAM_ROLES userTeamRole = new USER_TEAM_ROLES
                {
                    USER = user,
                    TEAM = team,
                    ROLE = basicRole
                };

                _teamRepository.AssignUserToTeamWithRole(userTeam, userTeamRole);
                await _messageService.RemoveTeamJoinRequestByUserFrom(user.Id, team.ID);

                await _messageService.CreateNewMessageForUser(user.Id, assignerId, "You have been assigned to " + team.NAME);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
        public RoleAssignViewModel GetMembersToAssign(int teamId, int roleId)
        {
            TEAM team = _teamRepository.GetTeamById(teamId);
            ROLE role = _roleRepository.GetRoleById(roleId);

            if (team != null && role != null)
            {
                var roleMembers      = _roleRepository.GetUsersByTeamRole(role, team);
                var teamOtherMembers = _userRepository.GetUsersByTeam(team).Except(roleMembers);
                RoleAssignViewModel roleAssignModel = new RoleAssignViewModel
                {
                    RoleId      = role.ID,
                    RoleName    = role.NAME,
                    TeamId      = team.ID,
                    RoleMembers = roleMembers.Select(x => new RoleAssignMemberModel {
                        MemberId = x.Id, MemberName = x.UserName
                    }),
                    OtherTeamMembers = teamOtherMembers.Select(x => new RoleAssignMemberModel {
                        MemberId = x.Id, MemberName = x.UserName
                    })
                };

                return(roleAssignModel);
            }

            return(null);
        }
Пример #5
0
        public List <ROLE> GetRolesByUserTeam(USER user, TEAM team)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (team == null)
            {
                throw new ArgumentNullException("team");
            }

            var userTeamRoles = _ctx.USER_TEAM_ROLEs.Where(x => x.USER == user && x.TEAM == team);

            List <ROLE> roles = new List <ROLE>();

            foreach (var userTeamRole in userTeamRoles)
            {
                ROLE role = userTeamRole.ROLE;
                if (role != null)
                {
                    roles.Add(role);
                }
            }

            return(roles);
        }
Пример #6
0
        public int CountTeacher()
        {
            ROLE          role        = db.ROLEs.Where(a => a.ROLE1 == "TEACHER").FirstOrDefault();
            List <C_USER> listteacher = role.C_USER.ToList();

            return(listteacher.Count());
        }
Пример #7
0
    protected void bt_login_Click(object sender, EventArgs e)
    {
        USER myuser = new USER();

        myuser.USERNAME = this.tb_username.Text;
        string pwd          = this.tb_password.Text;
        string sqlGetUserID = "SELECT USERID FROM [USER] WHERE USERNAME='******'";
        int    userid       = Convert.ToInt16(DbHelperSQL.GetSingle(sqlGetUserID));

        myuser.GetModel(userid);
        if (userid != 0)
        {
            if (myuser.PASSWORD.Trim() == pwd.Trim())
            {
                Response.Write(MessageBox.Show("登入成功"));
                ROLE myrole = new ROLE();
                myrole.ROLEID = myuser.ROLEID;
                myrole.GetModel(myrole.ROLEID);
                Session["roleid"] = Convert.ToInt16(myrole.ROLEID);
                Response.Redirect("index.aspx");
            }
            else
            {
                Response.Write(MessageBox.Show("登入失败"));
            }
        }
    }
Пример #8
0
        public bool CreateTeam(USER user, string teamName)
        {
            bool isNameFree = true;

            if (_teamRepository.GetTeamByName(teamName) == null)
            {
                ROLE role = _roleRepository.GetRoleByName("Leader");
                TEAM team = new TEAM()
                {
                    NAME = teamName
                };
                USER_TEAM userTeam = new USER_TEAM()
                {
                    TEAM = team,
                    USER = user
                };
                USER_TEAM_ROLES userTeamRole = new USER_TEAM_ROLES()
                {
                    USER = user,
                    TEAM = team,
                    ROLE = role
                };
                _teamRepository.AddTeam(team, userTeam, userTeamRole);
            }
            else
            {
                isNameFree = false;
            }

            return(isNameFree);
        }
Пример #9
0
        public int CountStudent()
        {
            ROLE          role        = db.ROLEs.Where(a => a.ROLE1 == "STUDENT").FirstOrDefault();
            List <C_USER> liststudent = role.C_USER.ToList();

            return(liststudent.Count());
        }
Пример #10
0
        //Sets Username and Password to send with request
        public bool setAuthentication(String username, String password)
        {
            client.Authenticator = new HttpBasicAuthenticator(username, password);

            //Check login
            RestRequest request = new RestRequest();

            request.Resource    = ConfigurationManager.AppSettings["STNServicesLoginEndpoint"];
            request.RootElement = "boolean";

            CurrentUser = _instance.Execute <MEMBER>(request);

            if (CurrentUser != null)
            {
                //get the role
                if ((CurrentUser.ROLE_ID != null) || (CurrentUser.ROLE_ID != 0))
                {
                    request             = new RestRequest();
                    request.Resource    = "/Roles/{roleId}";
                    request.RootElement = "ROLE";
                    request.AddParameter("roleId", CurrentUser.ROLE_ID, ParameterType.UrlSegment);
                    CurrentRole = _instance.Execute <ROLE>(request);
                }
            }
            else
            {
                clearAuthentication();
            }

            return(CurrentUser != null);
        }
Пример #11
0
    /// <summary>
    /// 提交角色信息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btRoleAdd_Click(object sender, EventArgs e)
    {
        ROLE myrole = new ROLE();

        myrole.ROLENAME        = this.tb_rolename.Text;
        myrole.ROLEDESCRIPTION = this.tb_rolediscription.Text;
        //判断数据库里面是否存在改名称
        if (myrole.Exists(this.tb_rolename.Text))
        {
            Response.Write(MessageBox.Show("角色" + this.tb_rolename.Text + ":已经存在请重新输入其他的角色名称!"));
            this.tb_rolename.Text        = "";
            this.tb_rolediscription.Text = "";
        }
        else
        {
            myrole.Add();

            //查询出ROLEID
            string selectRoleId = "SELECT ROLEID FROM ROLE WHERE ROLENAME='" + this.tb_rolename.Text + "'";
            int    myroleid     = Convert.ToInt16(DbHelperSQL.GetSingle(selectRoleId));
            //建立关系
            Authority myAuthority = new Authority();
            //设立关系中的 角色id
            myAuthority.ROLEID = myroleid;
            for (int i = 0; i < this.cbl_quanxian.Items.Count; i++)
            {
                //设立关系中的权限id
                myAuthority.MODULEID = Convert.ToInt16(this.cbl_quanxian.Items[i].Value);
                //添加关系入数据库
                myAuthority.Add();
            }
            //添加完毕
            Response.Write(MessageBox.Show("添加成功!"));
        }
    }
Пример #12
0
        public void AddRole(object button)
        {
            var info = GridPopupMenuBase.GetGridMenuInfo((DependencyObject)button) as GridMenuInfo;

            string roleName = string.Empty;
            var    bulkEditStringsViewModel = BulkEditStringsViewModel.Create(roleName);

            if (AddRoleDialogService.ShowDialog(MessageButton.OKCancel, "Add new role", "BulkEditStrings", bulkEditStringsViewModel) == MessageResult.OK)
            {
                if (bulkEditStringsViewModel.EditValue != null)
                {
                    roleName = (string)bulkEditStringsViewModel.EditValue;
                }

                ROLE newROLE = new ROLE()
                {
                    NAME = roleName, SORTORDER = 0, PARENTGUID = Guid.Empty
                };
                string errorMessage = string.Empty;
                if (ROLECollection.IsValidEntity(newROLE, ref errorMessage))
                {
                    ROLECollection.Save(newROLE);
                }
                else
                {
                    MessageBoxService.ShowMessage(errorMessage + " already exists", "Error", MessageButton.OK, MessageIcon.Error);
                }
            }
        }
Пример #13
0
        public IHttpActionResult PutROLE(int id, ROLE rOLE)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != rOLE.ID_ROLE)
            {
                return(BadRequest());
            }

            db.Entry(rOLE).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ROLEExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #14
0
        public User(int id, string userName, string password, string name, string surname, string gender, string jMBG, string phone, string email, string role)
        {
            Id       = id;
            UserName = userName;
            Password = password;
            Name     = name;
            Surname  = surname;
            JMBG     = jMBG;
            Phone    = phone;
            Email    = email;

            if (gender.ToUpper() == "M")
            {
                this.Gender = GENDER.M;
            }
            else
            {
                this.Gender = GENDER.F;
            }
            this.Gender = gender.ToUpper() == "M" ? GENDER.M : GENDER.F;

            if (role.ToLower() == "driver")
            {
                this.Role = ROLE.Driver;
            }
            else if (role.ToLower() == "dispatcher")
            {
                this.Role = ROLE.Dispatcher;
            }
            else
            {
                this.Role = ROLE.Customer;
            }
        }
Пример #15
0
        private void InitialDataPopup()
        {
            if (ViewState["RoleId"] != null)
            {
                var cmd = new RoleService();
                _item = cmd.Select(Convert.ToInt32(ViewState["RoleId"].ToString()));
                if (_item != null)
                {
                    popTxtRoleCode.Text = _item.ROLE_CODE;
                    popTxtRoleName.Text = _item.ROLE_NAME;
                    flag.Text           = "Edit";
                }

                var cmdFunc = new RoleFunctionService();
                DataSouceRoleFunction = cmdFunc.GetALLIncludeFunction(_item.ROLE_ID);
            }
            else
            {
                DataSouceRoleFunction = new List <ROLE_FUNCTION>();
            }
            DataSouceRoleFunction.AddRange(DataSouceNewRoleFunction);

            gridFunction.DataSource = DataSouceRoleFunction;
            gridFunction.DataBind();
        }
Пример #16
0
        public int Update(int input)
        {
            string nama;

            var roles = context.Roles.Find(input);

            Console.WriteLine("\n-------Data Sebelum Diupdate---------");
            Console.WriteLine("Id   : " + roles.role_id);
            Console.WriteLine("Name : " + roles.name);
            Console.WriteLine("-------------------------------------\n");

            Console.Write("Masukan Nama Role : ");
            nama = Console.ReadLine();

            ROLE rOLE = GetById(input);

            rOLE.name = nama;

            context.Entry(rOLE).State = System.Data.Entity.EntityState.Modified;
            context.SaveChanges();

            Console.WriteLine("\n-------Data Setelah Diupdate---------");
            Console.WriteLine("Id   : " + rOLE.role_id);
            Console.WriteLine("Name : " + rOLE.name);
            Console.WriteLine("-------------------------------------");

            return(input);
        }
Пример #17
0
        public List <C_USER> detailstudent(string IDstudent)
        {
            ROLE          role        = db.ROLEs.Where(a => a.ROLE1 == "STUDENT").FirstOrDefault();
            List <C_USER> listteacher = role.C_USER.ToList();

            return(listteacher.Where(a => a.ID == IDstudent).Select(x => new C_USER
            {
                ID = x.ID,
                FIRST_NAME = x.FIRST_NAME,
                LAST_NAME = x.LAST_NAME,
                MIDDLE_NAME = x.MIDDLE_NAME,
                PHONE_NO = x.PHONE_NO,
                DoB = x.DoB,
                SEX = x.SEX,
                MAIL = x.MAIL,
                PASSWORD = x.PASSWORD,
                LASTVISITDATE = x.LASTVISITDATE,
                FACULTY = new FACULTY {
                    ID = x.FACULTY.ID, NAME = x.FACULTY.NAME
                },
                CLASS = new CLASS {
                    ID = x.CLASS.ID, NAME = x.CLASS.NAME, MAJOR = x.CLASS.MAJOR
                }
            }).ToList());
        }
Пример #18
0
 private void LoadRoles(int?selectedRole)
 {
     try
     {
         List <ROLE> roles     = ApplicationContext.Current.Users.GetAllRoles();
         ROLE        emptyRole = new ROLE()
         {
             ID = -1, Name = ""
         };
         roles.Insert(0, emptyRole);
         ddlRoles.DataSource     = roles;
         ddlRoles.DataValueField = "ID";
         ddlRoles.DataTextField  = "Name";
         if (selectedRole.HasValue)
         {
             ddlRoles.SelectedValue = selectedRole.Value.ToString();
         }
         ddlRoles.DataBind();
     }
     catch (Exception ex)
     {
         // TODO log error
         lblErrors.Visible   = true;
         lblErrors.ForeColor = Color.Red;
         lblErrors.Text      = "Error occurred: " + ex.Message;
     }
 }
Пример #19
0
        public override bool IsUserInRole(string username, string roleName)
        {
            var  ctx  = ApplicationContext.Current.Users;
            ROLE role = ctx.GetRoleByName(roleName);

            return(ctx.GetAllUserRoles(username).Contains(role));
        }
Пример #20
0
        public ActionResult DeleteConfirmed(int id)
        {
            ROLE rOLE = db.ROLEs.Find(id);

            db.ROLEs.Remove(rOLE);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #21
0
 public PlayerAgent(int player_index)
 {
     this.player_index = player_index;
     this.score_card   = new List <Card>();
     this.hand_card    = new List <Card>();
     this.score        = 0;
     this.role         = ROLE.YADANG;
 }
Пример #22
0
 public User(string name, string phoneNumber, string address, ROLE role, USER_STATUS status, string username, string password)
 {
     Name        = name;
     PhoneNumber = phoneNumber;
     Address     = address;
     Role        = role;
     Status      = status;
     Username    = username;
     Password    = password;
 }
Пример #23
0
        /// <summary>
        /// 通过角色ID查找角色全部信息
        /// </summary>
        /// <param name="id">角色ID号</param>
        /// <returns>查找到的角色信息</returns>
        public ROLE FindRoleByID(Guid id)
        {
            ROLE role = new ROLE();

            using (var ctx = new NtripProxyDB())
            {
                role = ctx.ROLEs.Include("PERMISSIONs").Include("USERs").FirstOrDefault(r => r.ID == id && r.isDelete == false);
            }
            return(role);
        }
Пример #24
0
 public ActionResult Edit([Bind(Include = "idRole,nameRole")] ROLE rOLE)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rOLE).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(rOLE));
 }
Пример #25
0
        public IHttpActionResult GetROLE(int id)
        {
            ROLE rOLE = db.ROLE.Find(id);

            if (rOLE == null)
            {
                return(NotFound());
            }

            return(Ok(rOLE));
        }
Пример #26
0
        /// <summary>
        /// 添加角色信息
        /// </summary>
        /// <param name="role">需要添加的角色信息</param>
        /// <returns>角色是否添加成功</returns>
        public bool AddRole(ROLE role)
        {
            bool result = false;

            using (var ctx = new NtripProxyDB())
            {
                ctx.ROLEs.Add(role);
                result = ctx.SaveChanges() == 1;
            }
            return(result);
        }
Пример #27
0
        public ActionResult Create([Bind(Include = "idRole,nameRole")] ROLE rOLE)
        {
            if (ModelState.IsValid)
            {
                db.ROLEs.Add(rOLE);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(rOLE));
        }
Пример #28
0
        public async Task <bool> AssignUsersToRoleAsync(RoleAssignInputModel roleAssignModel)
        {
            TEAM team      = _teamRepository.GetTeamById(roleAssignModel.TeamId);
            ROLE role      = _roleRepository.GetRoleById(roleAssignModel.RoleId);
            bool canDelete = false;

            if (team != null && role != null)
            {
                canDelete = true;

                List <USER_TEAM_ROLES> usersToRemove = new List <USER_TEAM_ROLES>();
                if (roleAssignModel.IdsToRemove != null)
                {
                    foreach (string idToRemove in roleAssignModel.IdsToRemove)
                    {
                        USER user = await _userRepository.GetUserById(idToRemove);

                        if (user != null && _teamRepository.IsTeamMember(user, team.ID))
                        {
                            usersToRemove.Add(user.USER_TEAM_ROLEs.FirstOrDefault(x => x.ROLE == role && x.TEAM == team));
                        }
                    }
                }

                List <USER_TEAM_ROLES> usersToAdd = new List <USER_TEAM_ROLES>();
                if (roleAssignModel.IdsToAdd != null)
                {
                    foreach (string idToAdd in roleAssignModel.IdsToAdd)
                    {
                        USER user = await _userRepository.GetUserById(idToAdd);

                        if (user != null && _teamRepository.IsTeamMember(user, team.ID))
                        {
                            usersToAdd.Add(new USER_TEAM_ROLES {
                                ROLE = role, TEAM = team, USER = user
                            });
                        }
                    }
                }

                if (role.IS_REQUIRED && usersToAdd.Count <= 0)
                {
                    var userRoleCount = _roleRepository.GetUsersByTeamRole(role, team).Count();
                    canDelete = usersToRemove.Count < userRoleCount;
                }

                if (canDelete)
                {
                    _roleRepository.AddAndDeleteUserTeamRoles(usersToAdd, usersToRemove);
                }
            }

            return(canDelete);
        }
Пример #29
0
        private void simpan_role()
        {
            ROLE role = new ROLE()
            {
                NAME = tr_name.Text,
            };

            _db.ROLEs.Add(role);
            _db.SaveChanges();
            dataGridRole.ItemsSource = _db.ROLEs.ToList();
        }
Пример #30
0
        public ROLE GetById(int input)
        {
            ROLE rOLE = context.Roles.Find(input);

            if (rOLE == null)
            {
                Console.Write("Id " + input + " Tidak Ada");
                Console.Read();
            }
            return(rOLE);
        }
Пример #31
0
    public void LoadAvatar()
    {
        if (!PlayerPrefs.HasKey("currentRole"))
            return;

        int roleInt = PlayerPrefs.GetInt("currentRole");
        currentRole = (ROLE)roleInt;
        int genderInt = PlayerPrefs.GetInt("currentGender");
        currentGender = (GENDER)genderInt;

        UpdateRaceList();
        raceIndex = PlayerPrefs.GetInt("raceIndex");
        currentRace = currentRaceList[raceIndex];

        avatarindex = PlayerPrefs.GetInt("avatarindex");

        UpdateModel();
    }
Пример #32
0
        private void updateRole(string args) {
            char[] delim = { ' ' };
            string[] argsSplit = args.Split(delim);

            switch (argsSplit[0]) {
                case "Hitler":
                    myRole = ROLE.Hitler;
                    break;
                case "Fascist":
                    myRole = ROLE.Fascist;
                    break;
                default:
                    myRole = ROLE.Liberal;
                    break;
            }
            Console.WriteLine(myRole.ToString());

            if (myRole == ROLE.Fascist || myRole == ROLE.Hitler) {
                fascists = new List<string>();
                hitler = argsSplit[1];
                for (int i = 2; i < argsSplit.Length; i++) {
                    fascists.Add(argsSplit[i]);
                }

                Console.WriteLine("Hitler: " + hitler);
                Console.Write("Fascists: ");
                foreach (string fascist in fascists) Console.Write(fascist + ", ");
                Console.WriteLine(" ");
            }
        }
Пример #33
0
    public void ToggleRole()
    {
        if (currentRole == ROLE.Teacher)
            currentRole = ROLE.Student;
        else
            currentRole = ROLE.Teacher;

        UpdateRaceList();
    }