/// <summary> /// 获取用户对象 /// </summary> /// <param name="id">用户id</param> /// <returns></returns> public string FindMember(long id) { try { InvokeCheck(); MemberLogic logic = _memberLogic as MemberLogic; if (logic != null) { var entity = logic.Find(id); return(new ResultFormat(1, new { member_id = entity.member_id, name = entity.name, phone = entity.phone, mail = entity.mail, address = entity.address, default_community = entity.default_community }).ToString()); } return(new ResultFormat(0, string.Empty).ToString()); } catch (Exception ex) { return(new ResultFormat(0, ex.Message).ToString()); } }
/// <summary> /// 更新用户 /// </summary> /// <param name="id"></param> /// <param name="memberJson">需更新的属性</param> /// <returns></returns> public string UpdateMember(long id, string memberJson) { try { InvokeCheck(); MemberLogic logic = _memberLogic as MemberLogic; member orignal = null; if (logic != null) { orignal = logic.Find(id); } if (orignal == null) { return(new ResultFormat(0, "There is not exist this member id.").ToString()); } var memb = JsonConvert.DeserializeObject <member>(memberJson, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); if (memb == null) { return(new ResultFormat(0, "The parameter 'memberJson' format is wrong.").ToString()); } if (string.CompareOrdinal(memb.name, orignal.name) == 0) { return(new ResultFormat(0, "The member name can not be changed!").ToString()); } if (memb.address != null) { orignal.address = memb.address; } if (orignal.default_community.HasValue && orignal.default_community > 0) { if (memb.default_community.HasValue && memb.default_community > 0 && memb.default_community != orignal.default_community) { var comm = _communityLogic.Find(Convert.ToInt64(memb.default_community)); if (comm != null) { orignal.community = comm; orignal.default_community = memb.default_community; } } } else { if (memb.default_community.HasValue && memb.default_community > 0) { var comm = _communityLogic.Find(Convert.ToInt64(memb.default_community)); if (comm != null) { orignal.community = comm; orignal.default_community = memb.default_community; } } } if (memb.mail != null) { orignal.mail = memb.mail; } if (!string.IsNullOrWhiteSpace(memb.member_key)) { orignal.member_key = AuthCodeSecurity.Sha256(memb.member_key); } if (memb.phone != null) { orignal.phone = memb.phone; } var success = _memberLogic.Update(orignal); return(new ResultFormat(success ? 1 : 0, string.Empty).ToString()); } catch (Exception ex) { return(new ResultFormat(0, ex.ToString()).ToString()); } }