public JsonResult AddUser([System.Web.Http.FromBody] iot_user model) { int count = db.iot_user.Where(u => u.OpenId.Equals(model.OpenId)).Count(); if (count != 0) { return(Json(new { status = StatusCode.FAIL, meassage = "该用户已经注册" })); } iot_user user = new iot_user { NickName = model.NickName, OpenId = model.OpenId, Gender = model.Gender, Province = model.Province, Country = model.Country, City = model.City, AvatarUrl = model.AvatarUrl, CreateTime = new DateTime().Date, EditTime = null }; db.iot_user.Add(user); var taskinfo = new { status = StatusCode.SUCCESS, message = "添加用户成功" }; int uprows = db.SaveChanges(); if (uprows < 1) { taskinfo = new { status = StatusCode.FAIL, message = "添加用户失败" }; } return(Json(taskinfo, JsonRequestBehavior.AllowGet)); }
public void UpUser(iot_user model) { var data = db.iot_user.Where(u => u.OpenId == model.OpenId).FirstOrDefault(); if (data != null) { if (data.AvatarUrl != model.AvatarUrl) { data.AvatarUrl = model.AvatarUrl; } if (data.NickName != model.NickName) { data.NickName = model.NickName; } } int uprows = db.SaveChanges(); }
public JsonResult EditUser(string openId, [System.Web.Http.FromBody] iot_user model) { var user = db.iot_user.Where(u => u.OpenId == openId).FirstOrDefault(); var taskinfo = new { status = StatusCode.SUCCESS, message = "用户信息更新成功" }; user.Province = model.Province; user.NickName = model.NickName; user.Gender = model.Gender; user.Country = model.Country; user.City = model.City; user.AvatarUrl = model.AvatarUrl; user.EditTime = new DateTime().Date; int uprows = db.SaveChanges(); if (uprows < 1) { taskinfo = new { status = StatusCode.FAIL, message = "用户信息更新失败" }; } return(Json(taskinfo, JsonRequestBehavior.AllowGet)); }