Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        public static RoleDto getDTO(DataRow dr)
        {
            RoleDto roleDto = new RoleDto();

            roleDto.RoleId = int.Parse(dr["RoleId"].ToString());
            roleDto.RoleName = dr["RoleName"].ToString();
            roleDto.RoleDescription = dr["RoleDescription"].ToString();

            return roleDto;
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
0
        public ActionResult Create(RoleModel model)
        {
            try
            {
                RoleDto dto = new RoleDto();

                dto.RoleName = model.RoleName;
                dto.RoleDescription = model.RoleDescription;

                string JsonString = JsonHelper.JsonSerializerBySingleData(dto);
                Message msg = CMSService.Insert("Role", JsonString);
                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();
            }
        }
Exemplo n.º 5
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();
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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;
        }
 public void UpdateRole(RoleDto roleDto)
 {
     throw new NotImplementedException();
 }