public ResGetUser Get([FromForm] ReqGetUser user) { ResGetUser retValue = new ResGetUser(); try { using (var db = DbContext.GetInstance()) { var my = db.Queryable <T_USERS>() .Where(s => s.ID == user.ID) .FirstOrDefault(); UsersBase users = new UsersBase(); //转化成前端友好的数据 users = ModelConvert.FromTo <T_USERS, UsersBase>(my, users); retValue.SuccessDefalut(users, 1, "不存在该用户"); } } catch (Exception ex) { retValue.FailDefalut(ex); } return(retValue); }
public ResGetUser GetUrl([FromForm] ReqGetUser user) { ResGetUser retValue = new ResGetUser(); string logContent = string.Empty; try { using (var db = DbContext.GetInstance(ref logContent)) { var my = db.Queryable <T_USERS>() .Where(s => s.ID == user.ID) .FirstOrDefault(); //转化成前端友好的数据 UsersBase users = new UsersBase(); users = ModelConvert.FromTo <T_USERS, UsersBase>(my, users); retValue.SuccessDefalut(users, 1, "不存在该用户"); //记录日志 Startup.log.Info(LogHelper.LogDetails(logContent, user, retValue)); } } catch (Exception ex) { retValue.FailDefalut(ex); Startup.log.Error(logContent, ex); } return(retValue); }
public Stream GetUser(Stream data) { #region 查找数据 ResGetUser response = new ResGetUser(); bool success = true; try { DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(ReqGetUser)); //读取器 StreamReader sr = new StreamReader(data); string dataString = String.Empty; while (!sr.EndOfStream) { dataString = sr.ReadToEnd(); Console.WriteLine(dataString); #region 日志输出 CommonInfo.Log(dataString); #endregion //反序列化json为对象注意顺序很重要 ReqGetUser request = new ReqGetUser(); MemoryStream temp = new MemoryStream(Encoding.UTF8.GetBytes(dataString)); request = json.ReadObject(temp) as ReqGetUser; //关闭临时流 temp.Close(); //调用用户更新密码接口 if (request != null) { //**********(此处加入代码) 根据查询条件 加入业务逻辑代码************* if (request.account != null && request.account != String.Empty && request.token != null && request.token != String.Empty) { if (request.user_id != null && request.user_id != String.Empty) { DataTable user = UserEntity.getUserInfo(request.user_id); response.user = ResGetUser.getUserInfo(user); //设置成功状态 success = true; } } } } sr.Close(); Console.WriteLine(data); } catch (Exception ex) { Console.WriteLine(ex.Message); #region 日志输出 CommonInfo.Error("获取特定用户数据错误" + ex.Message); #endregion } //返回消息体 if (success) { response.SetSuccess(); } else { ////默认是失败 //response.SetFailed(); } //将消息序列化为Json格式数据 DataContractJsonSerializer obj2Json = new DataContractJsonSerializer(typeof(ResGetUser)); MemoryStream ms = new MemoryStream(); obj2Json.WriteObject(ms, response); //注意一定要设置流的位置到开始位置,否则没有消息输出 ms.Position = 0; return(ms); #endregion }