public static string Add(HttpContext context) { string uid = context.Request.Form["uid"].ToStringExt(); if (string.IsNullOrEmpty(uid)) throw new ArgumentNullException("uid", "不能为空"); string pwd = context.Request.Form["pwd"].ToStringExt(); if (string.IsNullOrEmpty(pwd)) throw new ArgumentNullException("pwd", "不能为空"); string name = context.Request.Form["name"]; string sex = context.Request.Form["sex"]; string birthday = context.Request.Form["birthday"]; string email = context.Request.Form["email"]; Model.User_Model user = new User_Model(); user.Email = email; user.Birthday = birthday.StrToDateTime(DateTime.MaxValue); user.Name = name; user.Password = pwd; user.UserID = uid; user.Sex = sex.ToInt(0); JsonTpl<string> jsonTemplate = new JsonTpl<string>(); jsonTemplate.msg = "添加失败"; jsonTemplate.code = -11; jsonTemplate.data = ""; bool addSucess = Bll.User_Bll.InsertUser(user); if (addSucess) { jsonTemplate.msg = "添加成功"; jsonTemplate.code = 1; } string jsonResult = Common.json.JsonHelper<JsonTpl<string>>.Serialize2Object(jsonTemplate); return jsonResult; }
public string List(HttpRequest request) { Logic.JsonTpl<List<Logic.Model.User>> json = new JsonTpl<List<Logic.Model.User>>(); json.info = new ApiInfo(1, "操作成功"); json.data = new List<Logic.Model.User>() { new Logic.Model.User() {ID = 1, Name = "k1", Email = "*****@*****.**", Sex = "男"}, new Logic.Model.User() {ID = 2, Name = "k2", Email = "*****@*****.**", Sex = "男"} }; string extjson = Common.json.JsonHelper<JsonTpl<List<Logic.Model.User>>>.Serialize2Object(json); return extjson; }
public static string Add(HttpContext context) { var session = context.Session; Logic.JsonTpl<string> jsonTemplate = new JsonTpl<string>(); jsonTemplate.info = new ApiInfo(-11, "添加失败"); jsonTemplate.data = ""; bool addSucess = true; if (addSucess) { jsonTemplate.info = new ApiInfo(1, "添加成功"); } string jsonResult = Common.json.JsonHelper<JsonTpl<string>>.Serialize2Object(jsonTemplate); return jsonResult; }
public static string List(HttpContext context) { if (string.IsNullOrEmpty(App.UserID)) throw new AuthenticationException("用户未登录"); Logic.JsonTpl<List<Logic.Model.User>> json = new JsonTpl<List<Logic.Model.User>>(); json.info = new ApiInfo(1, "操作成功"); json.data = new List<Logic.Model.User>() { new Logic.Model.User() {ID = 1, Name = "k1", Email = "*****@*****.**", Sex = "男"}, new Logic.Model.User() {ID = 2, Name = "k2", Email = "*****@*****.**", Sex = "男"} }; string extjson = Common.json.JsonHelper<JsonTpl<List<Logic.Model.User>>>.Serialize2Object(json); return extjson; }
public static string GetOne(HttpContext context) { string id = context.Request.GetValExt("id"); if (string.IsNullOrEmpty(id)) throw new ArgumentNullException("id", "缺少参数id"); Where where = new Where(new Where.Item("ID", "=", id)); Model.User_Model userModel = Bll.User_Bll.GetOneUser(where, "*"); JsonTpl<Model.User_Model> jsonTpl = new JsonTpl<User_Model>() {code = SystemCode.Error, msg = "exception"}; if (userModel.ID > 0) { jsonTpl.data = userModel; jsonTpl.code = SystemCode.Success; jsonTpl.msg = "success"; } return jsonTpl.ToJson(); }