public string AddUser(string fullName, string password, string email) { ReqAddUser request = new ReqAddUser { FullName = fullName, Password = password, Email = email }; return(this.Call <string, ReqAddUser>(request, "AddUser")); }
public Stream AddUser(Stream data) { #region 查找数据 ResAddUser response = new ResAddUser(); bool success = true; try { DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(ReqAddUser)); //读取器 StreamReader sr = new StreamReader(data); string dataString = String.Empty; while (!sr.EndOfStream) { dataString = sr.ReadToEnd(); Console.WriteLine(dataString); #region 日志输出 CommonInfo.Log(dataString); #endregion //反序列化json为对象注意顺序很重要 ReqAddUser request = new ReqAddUser(); MemoryStream temp = new MemoryStream(Encoding.UTF8.GetBytes(dataString)); request = json.ReadObject(temp) as ReqAddUser; //关闭临时流 temp.Close(); //调用用户更新密码接口 if (request != null) { //**********(此处加入代码) 根据查询条件 加入业务逻辑代码************* if (request.account != null && request.account != String.Empty && request.token != null && request.token != String.Empty) { if (request.user != null) { Console.WriteLine("开始新增用户"); PatrolUserInfo userinfo = new PatrolUserInfo(); userinfo.UserCD = request.user.user_id; userinfo.UserPassword = CommonInfo.DefaultPassword + userinfo.UserCD; userinfo.SearchRange = SetSearchRange(request.user.search_range); userinfo.IsAdmin = SetAdmin(request.user.isadmin); userinfo.IsAvailable = "1"; userinfo.CreatedAt = DateTime.Now; userinfo.Creator = request.account; Console.WriteLine("我的测试数据" + userinfo.IsAdmin); success = UserEntity.InsertUser(userinfo); } } else { Console.WriteLine("用户验证失败"); } } else { Console.WriteLine("请求对象为空"); } } sr.Close(); } 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(ResAddUser)); MemoryStream ms = new MemoryStream(); obj2Json.WriteObject(ms, response); //注意一定要设置流的位置到开始位置,否则没有消息输出 ms.Position = 0; return(ms); #endregion }
protected void btnsubmit_Click(object sender, EventArgs e) { try { if (txtusername.Text == "" || txtusername.Text == null) { ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('Please Enter The UserName');", true); txtusername.Focus(); return; } ReqAddUser objUserReq = new ReqAddUser(); objUserReq.UserName = txtusername.Text; objUserReq.FirstName = txtFirstName.Text; objUserReq.LastName = txtLastName.Text; if (objds == null) { objds = new DataSet(); } RespAddUser objRes = new RespAddUser(); using (WebClient client = new WebClient()) { client.Headers[HttpRequestHeader.ContentType] = "text/json"; DataContractJsonSerializer objJsonSerSend = new DataContractJsonSerializer(typeof(ReqAddUser)); MemoryStream memStrToSend = new MemoryStream(); objJsonSerSend.WriteObject(memStrToSend, objUserReq); string data = Encoding.Default.GetString(memStrToSend.ToArray()); string result = client.UploadString(URL + "/AddUser", "POST", data); MemoryStream memstrToReceive = new MemoryStream(Encoding.UTF8.GetBytes(result)); DataContractJsonSerializer objJsonSerRecv = new DataContractJsonSerializer(typeof(RespAddUser)); objRes = (RespAddUser)objJsonSerRecv.ReadObject(memstrToReceive); if (objRes.Result == true) { var page1 = HttpContext.Current.CurrentHandler as Page; add = "User Create Successfully ! User Password = @" + objRes.Password; Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "Success('" + add + "');", true); Log.Write("User Create Successfully", ""); } else if (objRes.Error.ToLower().Contains("username already added")) { add = "Username Allready added Please try diffrent ! "; Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "Warning('" + add + "');", true); Log.Write("Username Allready added", ""); } else { add = "User Create Failed ! "; Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "Failed('" + add + "');", true); Log.Write("User Create Failed", ""); } } } catch (Exception excp) { Log.Write("Exception in Creat User :- " + excp, ""); } }