Example #1
0
        public async Task <IActionResult> Remove(string id)
        {
            JsonMsg msg = new JsonMsg();

            try
            {
                int ret = await this._service.RemoveRole(id);

                if (ret > 0)
                {
                    msg.status = 0;
                }
                else
                {
                    msg.status  = -1;
                    msg.message = "操作不成功,请稍后重试";
                }
            }
            catch (Exception ex)
            {
                msg.status  = -1;
                msg.message = "操作不成功:" + ex.Message;
            }
            return(Json(msg));
        }
Example #2
0
        public async Task <IActionResult> RemoveRoleUser(string id, string roleCode)
        {
            JsonMsg msg = new JsonMsg();

            try
            {
                string userId = id;
                int    ret    = await this._service.RomveRoleUser(roleCode, userId);

                if (ret > 0)
                {
                    msg.status = 0;
                }
                else
                {
                    msg.status  = -1;
                    msg.message = "操作不成功,请稍后重试";
                }
            }
            catch (Exception ex)
            {
                msg.status  = -1;
                msg.message = "操作不成功:" + ex.Message;
            }
            return(Json(msg));
        }
Example #3
0
        public async Task <IActionResult> Login(LoginModel model)
        {
            JsonMsg msg = new JsonMsg();

            try
            {
                int state = await this._uservice.CheckLogin(model.UserId, model.Password);

                if (state == 0)
                {
                    var claims = new[] { new Claim(ClaimTypes.Name, model.UserId) };

                    var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));

                    //重新登录后,重置角色和权限的缓存
                    var pCacheKey = Constans.APP_CODE + "_" + model.UserId + "_P";
                    var rCacheKey = Constans.APP_CODE + "_" + model.UserId + "_R";
                    await _cache.RemoveAsync(pCacheKey);

                    await _cache.RemoveAsync(rCacheKey);
                }
                else
                {
                    msg.status  = -1;
                    msg.message = "用户名或密码错误";
                }
            }
            catch (Exception ex)
            {
                msg.status  = -1;
                msg.message = "登录失败:" + ex.Message;
            }
            return(Json(msg));
        }
        protected JsonMsg JsonMsg(int status, object data)
        {
            JsonMsg msg = JsonMsgFactory.GetJsonMsg(status);

            msg.data = data;
            return(msg);
        }
Example #5
0
        public async Task <IActionResult> Remove(string appCode)
        {
            JsonMsg msg = new JsonMsg();

            try
            {
                if (appCode == Constans.APP_CODE)
                {
                    msg.status  = -1;
                    msg.message = "内置系统不能为删除";
                }
                else
                {
                    int ret = await this._service.RemoveAppInfo(appCode);

                    if (ret > 0)
                    {
                        msg.status = 0;
                    }
                    else
                    {
                        msg.status  = -1;
                        msg.message = "操作不成功,请稍后重试";
                    }
                }
            }
            catch (Exception ex)
            {
                msg.status  = -1;
                msg.message = "操作不成功:" + ex.Message;
            }
            return(Json(msg));
        }
        protected JsonMsg JsonMsg(object data)
        {
            JsonMsg msg = JsonMsgFactory.GetJsonMsg(200);

            msg.data = data;
            return(msg);
        }
Example #7
0
        /// <summary>
        ///  根据文件id获取文件url多个以","分隔,返回文件路径相对路径,需要自行拼接ftp的域:端口,空表示未找到文件
        /// </summary>
        /// <param name="fileId">文件id</param>
        /// <param name="imgFileType">图片类型 1原图,2缩略图,3大图</param>
        /// <returns></returns>
        public static JsonMsg <List <PluginsFileInfo> > GetFileUrl(string fileId, int imgFileType = 1, string hostname = "localhost")
        {
            //提示信息
            var result = JsonMsg <List <PluginsFileInfo> > .Error(null, "查询成功");

            if (fileId.IsNullOrEmpty())
            {
                result.msg = "文件id不能为空";
                return(result);
            }
            //根据网络请求获取ftp地址信息
            SetFtpUrl(hostname);
            //判断文件id是否为空
            if (!fileId.IsNullOrEmpty())
            {
                var requesturl = ftpurl + "/FTPService.asmx/GetFileUrl";
                try
                {
                    //fileId, imgFileType
                    string filetype = "o";
                    if (imgFileType == 2)
                    {
                        filetype = "s";
                    }
                    else if (imgFileType == 3)
                    {
                        filetype = "m";
                    }
                    Dictionary <string, string> parameters = new Dictionary <string, string>();
                    parameters.Add("fileId", fileId);
                    parameters.Add("imgFileType", filetype);
                    var resultStr = WebServiceHttpHelper.GetResponseString(requesturl, HttpMethod.Post, parameters, Encoding.UTF8, Encoding.UTF8, 30000);
                    if (!resultStr.IsNullOrEmpty())
                    {
                        //转换为ftp返回对象
                        FtpAjaxResult ftpresult = SerializeHelper.GetXmlData <FtpAjaxResult>(resultStr);
                        if (ftpresult != null && ftpresult.code == AjaxResultType.成功)
                        {
                            var items = ftpresult.data.CopyModel <List <PluginsFileInfo> >();
                            if (items != null && items.Any())
                            {
                                foreach (var item in items)
                                {
                                    item.filepath = ftpurl + item.filepath;
                                }
                                result.data = items;
                                result.code = ResponseCode.Success;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = "调用ftp服务发生异常";
                    Log.Error(msg, ex);
                }
            }
            return(result);
        }
Example #8
0
        public async Task <IActionResult> SaveOrg(int type, DtoOrganization entity)
        {
            JsonMsg msg = new JsonMsg();

            try
            {
                string errMsg;
                bool   valid = ValidateOrg(entity, out errMsg);
                if (!valid)
                {
                    msg.status  = -1;
                    msg.message = errMsg;
                    return(Json(msg));
                }
                entity.LastModifyTime     = DateTime.Now;
                entity.LastModifyUserId   = base.UserId;
                entity.LastModifyUserName = base.UserId;
                if (entity.ParentCode == rootId)
                {
                    entity.ParentCode = null;
                }
                var user = await base.GetSignedUser();

                string viewRootCode = user.ViewRootCode;
                if (!string.IsNullOrEmpty(viewRootCode) && viewRootCode != rootId)
                {
                    bool admin = await this._contextService.IsInRole(base.UserId, Constans.SUPPER_ADMIN_ROLE);

                    if (admin)
                    {
                        viewRootCode = "";
                    }
                }
                if (viewRootCode == rootId)
                {
                    viewRootCode = "";
                }
                int ret = await this._service.SaveOrgInfo(entity, type, viewRootCode);

                if (ret > 0)
                {
                    msg.status = 0;
                }
                else
                {
                    msg.status  = -1;
                    msg.message = "操作不成功,请稍后重试";
                }
            }
            catch (Exception ex)
            {
                msg.status  = -1;
                msg.message = "操作不成功:" + ex.Message;
            }
            return(Json(msg));
        }
Example #9
0
        /// <summary>
        /// 医生登录,陈洁修改
        /// </summary>
        /// <param name="account_name">登录账户-手机号</param>
        /// <param name="password">登录密码</param>
        /// <returns></returns>
        public JsonMsg <LoginInfoModel> DoctorLogin(string account_name, string password)
        {
            string passwordMD5 = QWPlatform.SystemLibrary.Utils.Strings.StrToMD5(password);
            var    result      = JsonMsg <LoginInfoModel> .OK(null, "人员登录成功!");

            LoginInfoModel loginInfo = null;

            try
            {
                using (var db = new DbContext())
                {
                    //定义sql执行对象
                    var sqlBuilder = db.Sql("");
                    //SQL动态参数
                    List <string> list = new List <string>();
                    //如果包括account_name参数则使用account_name
                    sqlBuilder.Parameters("account", account_name);
                    list.Add("account");
                    sqlBuilder.Parameters("password", passwordMD5);
                    list.Add("password");
                    //获取执行的sql
                    string sql = db.GetSql("AB00001-平台身份认证", null, list.ToArray());
                    //执行数据查询
                    var items = sqlBuilder.SqlText(sql).GetModelList <LoginInfoModel>();
                    if (items == null || !items.Any())
                    {
                        result.msg  = "账户或密码不正确!";
                        result.code = ResponseCode.Error;
                        return(result);
                    }
                    loginInfo = items.FirstOrDefault(x => x.account_status == 1);
                    if (loginInfo == null)
                    {
                        result.msg  = "账户已被停用,请与管理员联系!";
                        result.code = ResponseCode.Error;
                        return(result);
                    }
                    loginInfo = items.FirstOrDefault(x => x.account_status == 1 && x.status == 1);
                    if (loginInfo == null)
                    {
                        result.msg  = "该账户已被停用,请与管理员联系!";
                        result.code = ResponseCode.Error;
                        return(result);
                    }
                    result.data = loginInfo;
                }
            }
            catch (Exception ex)
            {
                result.msg  = "查询人员登录信息发生异常!";
                result.code = ResponseCode.Error;
                Logger.Instance.Error(result.msg, ex);
            }
            return(result);
        }
Example #10
0
        public async Task <IActionResult> SaveRolePrivileges([FromForm] string roleCode, [FromForm] string privilegeCodes)
        {
            JsonMsg msg = new JsonMsg();

            try
            {
                string errMsg = null;
                if (string.IsNullOrEmpty(roleCode))
                {
                    errMsg = "roleCode 不能为空";
                }

                if (!string.IsNullOrEmpty(errMsg))
                {
                    msg.status  = -1;
                    msg.message = errMsg;
                    return(Json(msg));
                }
                privilegeCodes = privilegeCodes ?? "";

                string[] arrCode = privilegeCodes.Split(",");

                List <IRolePrivilege> plist = new List <IRolePrivilege>();
                foreach (string code in arrCode)
                {
                    plist.Add(new DtoRolePrivilege()
                    {
                        RoleCode = roleCode, PrivilegeCode = code
                    });
                }

                int ret = await this._service.SaveRolePrivileges(roleCode, plist);

                if (ret > 0)
                {
                    msg.status = 0;
                }
                else
                {
                    msg.status  = -1;
                    msg.message = "操作不成功,请稍后重试";
                }
            }
            catch (Exception ex)
            {
                msg.status  = -1;
                msg.message = "操作不成功:" + ex.Message;
            }
            return(Json(msg));
        }
Example #11
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="uploadfile">上传文件信息</param>
        /// <returns>返回文件id</returns>
        public static JsonMsg <string> Upload(UploadFileModel uploadfile, string hostname = "localhost")
        {
            //提示信息
            var result = JsonMsg <string> .Error(null, "查询成功");

            if (uploadfile == null || uploadfile.file_items == null || !uploadfile.file_items.Any())
            {
                result.msg = "上传文件不能为空";
                return(result);
            }
            //根据网络请求获取ftp地址信息
            SetFtpUrl(hostname);
            string fileid     = string.Empty;
            var    requesturl = ftpurl + "/FTPService.asmx/uploadBase64";

            foreach (var item in uploadfile.file_items)
            {
                try
                {
                    //fileData, string fileName, string type
                    Dictionary <string, string> parameters = new Dictionary <string, string>();
                    parameters.Add("fileData", item.filestr);
                    parameters.Add("fileName", item.filename);
                    parameters.Add("type", uploadfile.upload_type.ToString());
                    var resultStr = WebServiceHttpHelper.GetResponseString(requesturl, HttpMethod.Post, parameters, Encoding.UTF8, Encoding.UTF8, 30000);
                    if (!resultStr.IsNullOrEmpty())
                    {
                        //转换为ftp返回对象
                        FtpAjaxResult ftpresult = SerializeHelper.GetXmlData <FtpAjaxResult>(resultStr);
                        if (ftpresult != null && ftpresult.code == AjaxResultType.成功)
                        {
                            fileid     += ftpresult.data.ToString() + ",";
                            result.code = ResponseCode.Success;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = "调用ftp服务发生异常";
                    Log.Error(msg, ex);
                }
            }
            if (result.code == ResponseCode.Success)
            {
                result.data = fileid.Trim(',');
            }
            return(result);
        }
Example #12
0
        public async Task <IActionResult> GetApps()
        {
            JsonMsg msg = new JsonMsg();

            try
            {
                var list = await this._service.QueryAppInfoList("", "");

                msg.status = 0;
                msg.data   = list;
            }
            catch (Exception ex)
            {
                msg.status  = -1;
                msg.message = "操作不成功:" + ex.Message;
            }
            return(Json(msg));
        }
Example #13
0
        public async Task <IActionResult> GetMyApps()
        {
            JsonMsg msg = new JsonMsg();

            try
            {
                List <IAppInfo> list = await this._service.GetUserViewApp(base.UserId);

                msg.status = 0;
                msg.data   = list;
            }
            catch (Exception ex)
            {
                msg.status  = -1;
                msg.message = "操作不成功:" + ex.Message;
            }
            return(Json(msg));
        }
Example #14
0
        public async Task <IActionResult> AddRoleUsers([FromForm] string roleCode, [FromForm] string userIds)
        {
            JsonMsg msg = new JsonMsg();

            try
            {
                string errMsg = "";

                if (string.IsNullOrEmpty(roleCode))
                {
                    errMsg += "权限标识不能为空;";
                }
                if (string.IsNullOrEmpty(userIds))
                {
                    errMsg += "用户不能为空;";
                }

                if (!string.IsNullOrEmpty(errMsg))
                {
                    msg.status  = -1;
                    msg.message = errMsg;
                    return(Json(msg));
                }

                int ret = await this._service.AddRoleUserBatch(roleCode, userIds);

                if (ret > 0)
                {
                    msg.status = 0;
                }
                else
                {
                    msg.status  = -1;
                    msg.message = "操作不成功,请稍后重试";
                }
            }
            catch (Exception ex)
            {
                msg.status  = -1;
                msg.message = "操作不成功:" + ex.Message;
            }
            return(Json(msg));
        }
Example #15
0
 public ActionResult List(SearchEntity searchEntity)
 {
     try
     {
         var     data = orderMonitorService.GetList(searchEntity).Result.AsList();
         int     rows = orderMonitorService.GetCount(searchEntity).Result;
         JsonMsg json = new JsonMsg()
         {
             Data   = data,
             Msg    = "success",
             Status = 0
         };
         return(Json(new { rows = data, Msg = "success", Status = 0, total = rows }, JsonSettings));
     }
     catch (System.Exception e)
     {
         return(Json(new { rows = 0, Msg = e.Message + "<br/>" + e.StackTrace, Status = 1, total = 0 }, JsonSettings));
     }
 }
Example #16
0
        /// <summary>
        /// 平台身份认证
        /// </summary>
        /// <param name="account">登录账户</param>
        /// <param name="password">登录密码</param>
        /// <returns></returns>
        public Task <JsonMsg <AuthInfo> > GetUserAuth(string account, string password)
        {
            //返回对象
            var result = JsonMsg <AuthInfo> .Error(null, "平台身份认证失败!");

            if (account.IsNullOrEmpty() || password.IsNullOrEmpty())
            {
                result.msg = "账户及密码不能为空";
            }
            try
            {
                result = this.Logic.GetUserAuth(account, password);
            }
            catch (Exception ex)
            {
                result.msg = "平台身份认证发生异常:" + ex.Message;
                Logger.Instance.Error(result.msg, ex);
            }
            return(Task.FromResult(result));
        }
        public HttpResponseMessage GetUser([FromBody] User user)
        {
            var vm        = new GitHubUserViewModel();
            var msg       = new JsonMsg();
            var formatter = new JsonMediaTypeFormatter();

            try
            {
                if (string.IsNullOrEmpty(user.UserName))
                {
                    throw new ArgumentNullException("UserName", "Username cannot be empty");
                }

                var gitHubUser     = new UserService(new ApiHelper());
                var reposToDisplay = Convert.ToInt32(ConfigurationManager.AppSettings["UserReposToDisplay"]);

                GitHubUserModel userDetails = gitHubUser.GetUserDetails(user.UserName);

                vm.UserName           = userDetails.UserName;
                vm.AvatarUrl          = userDetails.AvatarUrl;
                vm.Location           = userDetails.Location;
                vm.GitHubRepositories = gitHubUser.GetTopXRepos(userDetails.GitHubRepositories, reposToDisplay)
                                        .Select(item => new GitHubRepoViewModel()
                {
                    RepositoryName  = item.RepositoryName,
                    RepositoryUrl   = item.RepositoryUrl,
                    StarGazersCount = item.StarGazersCount
                }).ToList();

                msg.result = !string.IsNullOrEmpty(vm.UserName);
                msg.data   = vm;
                return(Request.CreateResponse(HttpStatusCode.OK, msg, formatter));
            }

            catch (Exception ex)
            {
                Log.Error(ex);
                var errorMessage = ex.InnerException.ToString();
                return(Request.CreateResponse(errorMessage.Contains("404") ? HttpStatusCode.OK : HttpStatusCode.BadRequest, msg, formatter));
            }
        }
        /// <summary>
        /// 查询数据字典信息
        /// </summary>
        /// <returns></returns>
        public JsonMsg <List <DicInfo> > GetDicItems(DicParam entity)
        {
            //提示信息
            var result = JsonMsg <List <DicInfo> > .OK(null, "查询成功");

            //个人id必传
            if (entity.type <= 0)
            {
                result.code = ResponseCode.Error;
                result.msg  = "请选择需要查询的字典信息!";
                return(result);
            }
            var param = new List <string>();

            try
            {
                using (var db = new DbContext())
                {
                    var     sqlBuilder = db.Sql("");
                    DicType dictype    = (DicType)entity.type;
                    //字典表名
                    string tablename = dictype.ToString();
                    //获取字典信息
                    var sqlStr = $"SELECT '{tablename}' as 表名,编码, 简码, 名称  FROM { tablename}";
                    //执行SQL脚本
                    var items = sqlBuilder.SqlText(sqlStr)
                                .GetModelList <DicInfo>();
                    result.data = items;
                }
            }
            catch (Exception ex)
            {
                result.code = ResponseCode.Error;
                result.msg  = "查询数据字典信息发生异常!";
                Logger.Instance.Error(result.msg, ex);
            }
            return(result);
        }
Example #19
0
        public async Task <IActionResult> SaveAppInfo(int type, DtoAppInfo entity)
        {
            JsonMsg msg = new JsonMsg();

            try
            {
                string errMsg;
                bool   valid = ValidateAppInfo(entity, out errMsg);
                if (!valid)
                {
                    msg.status  = -1;
                    msg.message = errMsg;
                    return(Json(msg));
                }
                entity.LastModifyTime     = DateTime.Now;
                entity.LastModifyUserId   = base.UserId;
                entity.LastModifyUserName = base.UserId;

                int ret = await this._service.SaveAppInfo(entity, type);

                if (ret > 0)
                {
                    msg.status = 0;
                }
                else
                {
                    msg.status  = -1;
                    msg.message = "操作不成功,请稍后重试";
                }
            }
            catch (Exception ex)
            {
                msg.status  = -1;
                msg.message = "操作不成功:" + ex.Message;
            }
            return(Json(msg));
        }
Example #20
0
        private static void WriteToFile(object msg)
        {
            lock (LogfileWriteLock)
            {
                try
                {
                    if (_logFileStream == null || _logFileStream.BaseStream.CanWrite != true)
                    {
                        if (IsNullOrWhiteSpace(_options.LogFile)) return;

                        var fs = new FileStream(_options.LogFile, FileMode.Append, FileAccess.Write);

                        _logFileStream = new StreamWriter(fs) { AutoFlush = true };
                    }

                    var jsonMsg = new JsonMsg() { EventMessage = msg.ToString(), EventTags = _options.DescriptorTags };

                    var formattedMsg = JsonConvert.SerializeObject(jsonMsg);
                  
                    _logFileStream.WriteLine(formattedMsg);
                }
                catch (Exception)
                {
                    Debug.WriteLine("Concurrency error writing to log file...");
                    _logFileStream?.Close();
                    _logFileStream?.Dispose();
                }
            }
        }