Example #1
0
        public async Task <IActionResult> Index()
        {
            // bool b = await _redisCache.SetAsync<string>("TwBusWeb", "测试2222");

            string strApiUrl = ApiServerAddr + @"/api/v1/manage/querymenu";

            SearchMenuParamsDto paramsDto = new SearchMenuParamsDto();

            paramsDto.parentId  = 0;
            paramsDto.lstRoleId = UserInfo.lstRoleID;

            string strJson = JsonHelper.SerializeObject(paramsDto);


            HttpContent content = new StringContent(strJson);

            string strRes = await ApiHelp.ApiPostWithTokenAsync(strApiUrl, content, AccessToken);

            List <MenuDto> lstMenu = new List <MenuDto>();

            if (strRes.Contains("网络错误") == false)
            {
                lstMenu = JsonHelper.Deserialize <List <MenuDto> >(strRes);
            }

            return(View(lstMenu));
        }
        public ActionResult Getmac(string ip = "192.168.1.35")
        {
            string s   = ApiHelp.GetIP(HttpContext);
            string mac = ApiHelp.GetMacAddress(ip);

            return(Content("192.168.1.35的mac地址是:" + mac + ",系统获取的ip是:" + s));
        }
Example #3
0
        public async Task <IActionResult> Add(int?ParentId, int?MenuId)
        {
            JsonModel jm = new JsonModel();

            EntityDTO.MenuDto model = new MenuDto();
            try
            {
                //获取菜单下拉列表
                var menulist = new List <SelectListItem>();
                menulist.Add(new SelectListItem {
                    Text = "顶级菜单", Value = "0"
                });
                //var list = client.Channel.GetListHaveSortForMenu(0);
                int _parentID = 0;
                GetMenuList(menulist, _parentID);
                if (menulist != null && menulist.Count != 0)
                {
                    ViewBag.MenuList = new SelectList(menulist, "Value", "Text", ParentId);
                }
                if (MenuId == null)//添加
                {
                    ViewBag.IsEdit = "false";
                }
                else//编辑
                {
                    ViewBag.IsEdit = "true";

                    string strApiUrl = ApiServerAddr + @"/api/v1/manage/MenuFindById";

                    string strJson = JsonHelper.SerializeObject(MenuId);


                    HttpContent content = new StringContent(strJson);

                    string strRes = await ApiHelp.ApiPostWithTokenAsync(strApiUrl, content, AccessToken);

                    if (strRes.Contains("网络错误") == false)
                    {
                        model = JsonHelper.Deserialize <MenuDto>(strRes);
                    }
                    if (model == null)
                    {
                        jm.Msg          = "参数错误,找不到需要编辑的菜单项";
                        jm.Statu        = "error";
                        TempData["msg"] = jm;
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch
            {
                throw;
            }
            return(View(model));
        }
        /// <summary>
        /// 获取AccessToken
        /// </summary>
        /// <returns></returns>
        public async Task <string> GetTokenAsync()
        {
            string strToken = HttpContext.Session.GetString("token");

            if (string.IsNullOrEmpty(strToken))
            {
                //获取访问token
                AccessTokenModel tokenModel = await ApiHelp.GetAccessTokenAsync(AppId, AppKey, ApiServerAddr);

                HttpContext.Session.SetString("token", tokenModel.access_token);

                strToken = tokenModel.access_token;
            }
            return(strToken);
        }
Example #5
0
        /// <summary>
        /// 根据父ID获取菜单列表SelectList
        /// </summary>
        /// <param name="menulSelectList"></param>
        /// <param name="parentID"></param>
        public void GetMenuList(List <SelectListItem> menulSelectList, int parentID)
        {
            IList <MenuDto> list = new List <MenuDto>();

            try
            {
                string strApiUrl = ApiServerAddr + @"/api/v1/manage/querymenu";

                SearchMenuParamsDto paramsDto = new SearchMenuParamsDto();
                paramsDto.parentId = parentID;

                string strJson = JsonHelper.SerializeObject(paramsDto);

                HttpContent content = new StringContent(strJson);

                string strRes = ApiHelp.ApiPostWithTokenAsync(strApiUrl, content, AccessToken).Result;


                if (strRes.Contains("网络错误") == false)
                {
                    list = JsonHelper.Deserialize <List <MenuDto> >(strRes);
                }
            }
            catch
            {
                throw;
            }
            foreach (var item in list)
            {
                SelectListItem selectitem = new SelectListItem();
                string         name       = item.Name;
                string         id         = item.id.ToString();
                if (item.Class_layer == parentID)
                {
                    menulSelectList.Add(new SelectListItem {
                        Text = name, Value = id
                    });
                }
                else
                {
                    name = "├ " + name;
                    name = Utils.StringOfChar(item.Class_layer - 1, " ") + name;
                    menulSelectList.Add(new SelectListItem {
                        Text = name, Value = id
                    });
                }
            }
        }
        private async Task <List <MenuDto> > GetMenuAsync(UserViewModel user)
        {
            string strToken = HttpContext.Session.GetString("token");

            if (string.IsNullOrEmpty(strToken))
            {
                //获取访问token
                AccessTokenModel tokenModel = await ApiHelp.GetAccessTokenAsync(user.JobNumber, user.Pwd, ApiServerAddr);

                HttpContext.Session.SetString("token", tokenModel.access_token);

                strToken = tokenModel.access_token;
            }

            string strApiUrl = ApiServerAddr + @"/api/v1/manage/querymenu";


            SearchMenuParamsDto paramsDto = new SearchMenuParamsDto();

            paramsDto.parentId  = 0;
            paramsDto.lstRoleId = user.lstRoleID;

            string strJson = JsonHelper.SerializeObject(paramsDto);

            HttpContent content = new StringContent(strJson);

            string strRes = await ApiHelp.ApiPostWithTokenAsync(strApiUrl, content, strToken);

            List <MenuDto> lstMenu = new List <MenuDto>();

            if (strRes.Contains("网络错误") == false)
            {
                lstMenu = JsonHelper.Deserialize <List <MenuDto> >(strRes);
            }

            return(lstMenu);
            //return Task.FromResult(_menuService.MenuGetListHaveSort(0, true, rolelist).Where(c => c.IsLock == 0).ToList());
        }
        public async Task <IActionResult> Login(LoginUser loginVm)
        {
            JsonModel jm = new JsonModel();

            if (string.IsNullOrWhiteSpace(loginVm.JobNumber.Trim()) || string.IsNullOrWhiteSpace(loginVm.Pwd.Trim()))
            {
                jm.Statu = "n";
                jm.Msg   = "工号、密码不能为空!";
                return(Json(jm));
            }

            string md5Pwd = SecurityUtility.GetMd5Hash(loginVm.Pwd.Trim()).ToUpper();

            loginVm.Pwd = md5Pwd;

            string strApiUrl = ApiServerAddr + @"/api/v1/account/SignIn";

            string strJson = JsonHelper.SerializeObject(loginVm);


            HttpContent content = new StringContent(strJson);

            UserDto       model = null;
            UserViewModel vm    = null;

            try
            {
                string strRes = await ApiHelp.ApiPostWithTokenAsync(strApiUrl, content, AccessToken);

                if (strRes.Contains("网络错误") == false)
                {
                    model = JsonHelper.Deserialize <UserDto>(strRes);

                    if (model.IsError)
                    {
                        jm.Statu = "n";
                        jm.Msg   = model.ErrorMsg;
                        return(Json(jm));
                    }


                    if (model.Status == 1)
                    {
                        jm.Statu = "n";
                        jm.Msg   = "你的账号已被冻结!";
                        return(Json(jm)); //还未审核的用户
                    }
                    vm           = new UserViewModel();
                    vm.id        = model.id;
                    vm.UserName  = model.UserName;
                    vm.JobNumber = model.JobNumber;
                    vm.Pwd       = model.Pwd;
                    //vm. = model.Sex;

                    //vm.s = model.SchoolID;
                    vm.Status = model.Status;
                    if (model.Status == 0)
                    {
                        vm.StatuName = "已启用";
                    }
                    else
                    {
                        vm.StatuName = "已冻结";
                    }

                    vm.lstRoleID = model.LstRoleID;

                    vm.LastLoginTime = model.LastLoginTime;
                    vm.RegisterTime  = model.RegisterTime;
                    vm.Remark        = model.Remark;

                    HttpContext.Session.Set <Models.UserViewModel>("UserInfo", vm);
                    jm.Statu = "y";
                    jm.Msg   = "登录成功";
                }
                else
                {
                    jm.Statu = "n";
                    jm.Msg   = "网络错误,请确认网络连接!";
                }

                return(Json(jm));
            }
            catch (Exception ex)
            {
                jm.Statu = "n";
                jm.Msg   = ex.Message;
                return(Json(jm));
            }
        }
Example #8
0
        public async Task <IActionResult> Add(MenuDto viewmodel)
        {
            EntityDTO.MenuDto model = new MenuDto();
            JsonModel         rjson = new JsonModel();
            UserViewModel     uinfo = UserInfo;

            try
            {
                string strApiUrl = ApiServerAddr + @"/api/v1/manage/MenuFindById";

                string strJson = JsonHelper.SerializeObject(viewmodel.ParentId);


                HttpContent content = new StringContent(strJson);

                string strRes = await ApiHelp.ApiPostWithTokenAsync(strApiUrl, content, AccessToken);

                EntityDTO.MenuDto parentmodel = null;

                if (strRes.Contains("网络错误") == false)
                {
                    parentmodel = JsonHelper.Deserialize <MenuDto>(strRes);
                }

                if (parentmodel != null)
                {
                    model.Class_layer = parentmodel.Class_layer + 1;
                }
                else
                {
                    model.Class_layer = 1;
                }
                if (viewmodel.id != 0)
                {
                    strJson = JsonHelper.SerializeObject(viewmodel.id);

                    content = new StringContent(strJson);

                    strRes = await ApiHelp.ApiPostWithTokenAsync(strApiUrl, content, AccessToken);

                    if (strRes.Contains("网络错误") == false)
                    {
                        model = JsonHelper.Deserialize <MenuDto>(strRes);
                    }

                    if (model == null)
                    {
                        rjson.Msg   = "参数错误,找不到需要编辑的菜单项";
                        rjson.Statu = "y";
                        return(Json(rjson));
                    }
                }
                model.ActionName     = viewmodel.ActionName;
                model.Class_list     = viewmodel.Class_list;
                model.ControllerName = viewmodel.ControllerName;
                model.IconCss        = viewmodel.IconCss;
                model.IsLock         = viewmodel.IsLock;
                model.LinkPara       = viewmodel.LinkPara;
                model.Name           = viewmodel.Name;
                model.ParentId       = viewmodel.ParentId;
                model.Remark         = viewmodel.Remark;
                model.SortID         = viewmodel.SortID;
                model.UpdateTime     = DateTime.Now;
                model.UpdateUser     = uinfo.id.ToString();
                int res = 0;
                if (viewmodel.id == 0)
                {
                    model.AddTime = DateTime.Now;
                    model.AddUser = uinfo.id.ToString();

                    strApiUrl = ApiServerAddr + @"/api/v1/manage/MenuAdd";
                }
                else
                {
                    strApiUrl = ApiServerAddr + @"/api/v1/manage/MenuUpdate";
                }


                strJson = JsonHelper.SerializeObject(model);

                content = new StringContent(strJson);

                strRes = await ApiHelp.ApiPostWithTokenAsync(strApiUrl, content, AccessToken);

                if (strRes.Contains("网络错误") == false)
                {
                    res = int.Parse(JsonHelper.Deserialize <string>(strRes));
                }

                if (res > 0)
                {
                    HttpContext.Session.Set <string>("MenuCustomId", Guid.NewGuid().ToString());

                    rjson.Msg   = "提交成功";
                    rjson.Statu = "y";
                }
                else
                {
                    rjson.Msg   = "提交失败";
                    rjson.Statu = "n";
                }
            }
            catch (Exception ex)
            {
                rjson.Msg   = Utils.GetServiceErrMsg(ex);
                rjson.Statu = "n";
            }

            return(Json(rjson));
        }
Example #9
0
 public MainWindow()
 {
     InitializeComponent();
     ApiHelp.InitializeClient();
 }