Esempio n. 1
0
 public static EmbedBuilder AddRule(this EmbedBuilder builder, string emote, RoleManageModel model)
 {
     return(builder
            .AddField("Reaction", emote)
            .AddField("Roles To Add", model.ToAdd.GetRoleMentions())
            .AddField("Roles To Remove", model.ToRemove.GetRoleMentions()));
 }
Esempio n. 2
0
        public async Task <ResponseModel> UpdateRoleAsync(Guid id, RoleManageModel roleManageModel)
        {
            var role = await _roleRepository.GetByIdAsync(id);

            if (role == null)
            {
                return(new ResponseModel()
                {
                    StatusCode = System.Net.HttpStatusCode.NotFound,
                    Message = "This role is not exist"
                });
            }
            else
            {
                var existedRoleName = await _roleRepository.FetchFirstAsync(x => x.Name == roleManageModel.Name && x.Id != id);

                if (existedRoleName != null)
                {
                    return(new ResponseModel()
                    {
                        StatusCode = System.Net.HttpStatusCode.BadRequest,
                        Message = "This Role name is exist. Please try again!",
                    });
                }
                else
                {
                    roleManageModel.GetRoleFromModel(role);
                    return(await _roleRepository.UpdateAsync(role));
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 获取角色列表数据
        /// </summary>
        /// <returns></returns>
        public JsonResult GetRoleManageList(DataTableParameter para, string searchValue)
        {
            int total = 0;
            List <RoleManageModel> list = new List <RoleManageModel>();
            var dataList = IdentityDA.GetRoleManageList(out total, para, searchValue);

            if (dataList.Count() > 0)
            {
                for (int index = 0; index < dataList.Count(); index++)
                {
                    RoleManageModel model   = new RoleManageModel();
                    IDENTITY        item    = dataList[index];
                    string          strHtml = "<div class='row'><div class='col-md-8'>{0}</div><div class='col-md-4' style='text-align:right'>{1}</div></div>";

                    string linkAList = "<a class='glyphicon glyphicon-cog configRole' title='配置'  RoleId='" + item.ID + "'></a>";
                    if (Userinfo.LoginName == "admin")
                    {
                        linkAList += "&nbsp;&nbsp;&nbsp;&nbsp;<a class='glyphicon glyphicon-trash deleteRole' title='删除' RoleId='" + item.ID + "'></a>";
                    }
                    strHtml          = string.Format(strHtml, item.KEYED_NAME, linkAList);
                    model.KEYED_NAME = strHtml;
                    model.Id         = item.ID;
                    if (item.DESCRIPTION.Contains(";"))
                    {
                        List <string> listStr = item.DESCRIPTION.Split(';').ToList();
                        if (listStr.Count >= 2)
                        {
                            model.Region = listStr[1];
                        }
                    }
                    //获取成员列表
                    List <IDENTITY> memberList = IdentityDA.GetMemberById(model.Id);
                    foreach (var member in memberList)
                    {
                        model.PersonList = model.PersonList + member.NAME + ";";
                    }
                    list.Add(model);
                }
            }
            return(Json(new
            {
                sEcho = para.sEcho,
                iTotalRecords = total,
                iTotalDisplayRecords = total,
                aaData = list
            }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 4
0
        /// <summary>
        /// 获取角色根据ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult GetRoleManageById(string id)
        {
            var retModel = new JsonReturnModel();

            try
            {
                RoleManageModel model  = new RoleManageModel();
                Item            result = IdentityDA.GetRoleManageById(inn, id);
                if (string.IsNullOrEmpty(result.getErrorString()))
                {
                    model.KEYED_NAME = result.getProperty("name");
                    model.Id         = result.getProperty("id");
                    string description = result.getProperty("description");
                    if (description.Contains(";"))
                    {
                        List <string> listStr = description.Split(';').ToList();
                        if (listStr.Count >= 2)
                        {
                            model.Region = listStr[1];
                        }
                    }

                    Item Relation = result.getRelationships();
                    if (Relation.getItemCount() > 0)
                    {
                        for (int i = 0; i < Relation.getItemCount(); i++)
                        {
                            Item relationObJ = Relation.getItemByIndex(i);
                            model.PersonList = model.PersonList + relationObJ.getRelatedItem().getProperty("name") + ";";
                        }
                    }
                    retModel.data = model;
                }
                else
                {
                    retModel.AddError("errorMessage", result.getErrorString());
                }
            }
            catch (Exception ex)
            {
                retModel.AddError("errorMessage", ex.Message);
            }
            return(Json(retModel, JsonRequestBehavior.AllowGet));
        }
Esempio n. 5
0
        public async Task <ResponseModel> CreateRoleAsync(RoleManageModel roleManageModel)
        {
            var role = await _roleRepository.FetchFirstAsync(x => x.Name == roleManageModel.Name);

            if (role != null)
            {
                return(new ResponseModel
                {
                    StatusCode = System.Net.HttpStatusCode.BadRequest,
                    Message = "This Role name is exist"
                });
            }
            else
            {
                role = _mapper.Map <Role>(roleManageModel);
                await _roleRepository.InsertAsync(role);

                return(new ResponseModel
                {
                    StatusCode = System.Net.HttpStatusCode.OK,
                    Data = new RoleViewModel(role),
                });
            }
        }
        public async Task <IActionResult> Update(Guid id, [FromBody] RoleManageModel roleManageModel)
        {
            var response = await _roleService.UpdateRoleAsync(id, roleManageModel);

            return(new CustomActionResult(response));
        }
        public async Task <IActionResult> Create([FromBody] RoleManageModel roleManagerModel)
        {
            var response = await _roleService.CreateRoleAsync(roleManagerModel);

            return(new CustomActionResult(response));
        }
Esempio n. 8
0
 public static ReactionRoleModel UpdateRRModel(this ReactionRoleModel model, IEmote emote, RoleManageModel rule)
 {
     if (model.Rule is not ReactionRuleModel rrModel)
     {
         return(model);
     }
     return(model with {
         Rule = rrModel.WithNewRule(emote.Name, rule)
     });
 }