Ejemplo n.º 1
0
        /// <summary>
        /// 新增角色信息
        /// </summary>
        /// <returns></returns>
        public bool AddRole(RoleOperateDTO dto)
        {
            var result = false;

            using (var tcdmse = new Entities.TCDMS_MasterDataEntities())
            {
                var pp = tcdmse.master_RoleInfo.AsNoTracking().Where(p => p.RoleName == dto.RoleName).FirstOrDefault();
                if (pp != null)
                {
                    throw new Exception("角色名不能重复!");
                }
                var newrole = new master_RoleInfo();
                newrole = Mapper.Map <RoleOperateDTO, master_RoleInfo>(dto);
                tcdmse.master_RoleInfo.Add(newrole);
                tcdmse.SaveChanges();
                if (dto.RoleAuthority != null && dto.RoleAuthority.Count > 0)
                {
                    for (int i = 0; i < dto.RoleAuthority.Count; i++)
                    {
                        var newauth = new master_RoleAuthority()
                        {
                            RoleButtonAuthority = dto.RoleAuthority[i].RoleButtonAuthority,
                            StructureID         = dto.RoleAuthority[i].StructureID,
                            RoleID = newrole.RoleID
                        };
                        tcdmse.master_RoleAuthority.Add(newauth);
                    }
                }


                result = tcdmse.SaveChanges() >= 0;
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 修改角色信息
        /// </summary>
        /// <returns></returns>
        public bool UpdateRole(RoleOperateDTO dto)
        {
            var result = false;

            using (var tcdmse = new Entities.TCDMS_MasterDataEntities())
            {
                var pp = tcdmse.master_RoleInfo.Where(p => p.RoleID == dto.RoleID).FirstOrDefault();
                if (pp == null)
                {
                    throw new Exception("此条信息不存在");
                }
                var ss = tcdmse.master_RoleInfo.AsNoTracking().Where(p => p.RoleName == dto.RoleName && p.RoleID != dto.RoleID).FirstOrDefault();
                if (ss != null)
                {
                    throw new Exception("角色名不能重复!");
                }
                dto.CreateTime = pp.CreateTime;
                dto.CreateUser = pp.CreateUser;
                Mapper.Map <RoleOperateDTO, master_RoleInfo>(dto, pp);
                var remove = tcdmse.master_RoleAuthority.Where(p => p.RoleID == pp.RoleID).ToList();
                tcdmse.master_RoleAuthority.RemoveRange(remove);
                if (dto.RoleAuthority != null && dto.RoleAuthority.Count > 0)
                {
                    for (int i = 0; i < dto.RoleAuthority.Count; i++)
                    {
                        var newauth = new master_RoleAuthority()
                        {
                            RoleButtonAuthority = dto.RoleAuthority[i].RoleButtonAuthority,
                            StructureID         = dto.RoleAuthority[i].StructureID,
                            RoleID = pp.RoleID
                        };
                        tcdmse.master_RoleAuthority.Add(newauth);
                    }
                }
                result = tcdmse.SaveChanges() > 0;
            }

            return(result);
        }
Ejemplo n.º 3
0
        public HttpResponseMessage UpdateRole(RoleOperateDTO dto)
        {
            ResultDTO <object> actionresult = new ResultDTO <object>();

            try
            {
                actionresult.SubmitResult = _IUserAuthorityServices.UpdateRole(dto);
            }
            catch (Exception e)
            {
                actionresult.SubmitResult = false;
                actionresult.Message      = e.Message;
            }
            HttpResponseMessage result = new HttpResponseMessage
            {
                Content = new StringContent(JsonConvert.SerializeObject(actionresult),
                                            System.Text.Encoding.GetEncoding("UTF-8"),
                                            "application/json")
            };

            return(result);
        }
Ejemplo n.º 4
0
        public void TestMethod1()
        {
            //角色管理
            //新增
            RoleSearchDTO adddto       = new RoleSearchDTO();
            var           searchdtostr = TransformHelper.ConvertDTOTOBase64JsonString(adddto);

            testcontroller.GetRoleList(searchdtostr);
            RoleOperateDTO adddtotest = new RoleOperateDTO();

            adddtotest.RoleName = "单元测试角色";
            var addresult   = JsonConvert.DeserializeObject <ResultDTO <object> >(testcontroller.AddRole(adddtotest).Content.ReadAsStringAsync().Result);
            var resultlist1 = JsonConvert.DeserializeObject <List <RoleResultDTO> >(testcontroller.GetRoleList(searchdtostr).Content.ReadAsStringAsync().Result);
            var target      = resultlist1.Where(m => m.RoleName == "单元测试角色").FirstOrDefault();

            Assert.IsNotNull(target);

            //修改
            adddtotest.RoleID   = target.RoleID;
            adddtotest.RoleName = "修改成功的单元测试角色";
            var updateresult = JsonConvert.DeserializeObject <ResultDTO <object> >(testcontroller.UpdateRole(adddtotest).Content.ReadAsStringAsync().Result);
            var resultlist2  = JsonConvert.DeserializeObject <List <RoleResultDTO> >(testcontroller.GetRoleList(searchdtostr).Content.ReadAsStringAsync().Result);

            target = resultlist2.Where(m => m.RoleName == "修改成功的单元测试角色").FirstOrDefault();
            Assert.IsNotNull(target);

            //删除
            RoleSearchDTO deleteDto = new RoleSearchDTO();

            deleteDto.RoleID = target.RoleID;
            var deleteDtoster = TransformHelper.ConvertDTOTOBase64JsonString(deleteDto);
            var deleteresult  = JsonConvert.DeserializeObject <ResultDTO <object> >(testcontroller.DeleteRole(deleteDtoster).Content.ReadAsStringAsync().Result);
            var resultlist3   = JsonConvert.DeserializeObject <List <RoleResultDTO> >(testcontroller.GetRoleList(searchdtostr).Content.ReadAsStringAsync().Result);

            target = resultlist3.Where(m => m.RoleID == target.RoleID).FirstOrDefault();
            Assert.IsNull(target);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 修改角色信息
        /// </summary>
        /// <returns></returns>
        public static ResultData <object> UpdateRole(RoleOperateDTO dto)
        {
            var result = PutAPI <ResultData <object> >(WebConfiger.MasterDataServicesUrl + "Role", dto);

            return(result);
        }