public async Task <IHttpActionResult> Register([FromBody] RegisterUser registerUser) { WebModelIsSucceed model = new WebModelIsSucceed(); UserAdapter userAdapter = new UserAdapter(); string userEmail = registerUser.UserEmail; UserModel user = await userAdapter.LoadUserByUserEmail(userEmail); string telphone = registerUser.Telphone; UserModel userph = await userAdapter.LoadUserByUserPhone(telphone); int result = 0; //验证电话号 if (userph != null && !string.IsNullOrEmpty(userph.Telphone)) { if (userph.IsLogin == 1) { //未激活 userph.IsLogin = 0; result = await userAdapter.AddOrUpdateAsync(userph); if (result > 0) { model.IsSucceed = true; } else { model.IsSucceed = false; model.ErrorMessage = "用户激活失败!"; } } else { //已激活 model.IsSucceed = false; model.ErrorMessage = "此电话号码已激活,无需注册!"; } } //验证邮箱 else if (user != null && !string.IsNullOrEmpty(user.UserEmail)) { if (user.IsLogin == 1) { //未激活 user.IsLogin = 0; result = await userAdapter.AddOrUpdateAsync(user); if (result > 0) { model.IsSucceed = true; } else { model.IsSucceed = false; model.ErrorMessage = "用户激活失败!"; } } else { //已激活 model.IsSucceed = false; model.ErrorMessage = "此邮箱已激活,无需注册!"; } } else { //邮箱未存在,在判断姓名和部门 UserModel userUnit = await userAdapter.LoadByUserNameAndUnit(registerUser.SurnameChinese, registerUser.NameChinese, registerUser.UnitID); if (userUnit != null && !string.IsNullOrEmpty(Convert.ToString(userUnit.UnitID))) { //姓名和部门符合要求 if (userUnit.IsLogin == 1) { //未激活 userUnit.IsLogin = 0; result = await userAdapter.AddOrUpdateAsync(userUnit); return(Json(userUnit)); } else { //已激活 model.IsSucceed = false; model.ErrorMessage = "此姓名和部门已被注册过,无法注册!"; } } else { //添加数据 user = new UserModel(); user.UUID = Guid.NewGuid(); user.UserEmail = registerUser.UserEmail; user.Telphone = registerUser.Telphone; user.SurnameChinese = registerUser.SurnameChinese; user.SurnamePhoneticize = registerUser.SurnamePhoneticize; user.NameChinese = registerUser.NameChinese; user.NamePhoneticize = registerUser.NamePhoneticize; user.PassWord = MD5Method.Instance.MD5Encrypt(registerUser.Password); user.UnitID = registerUser.UnitID; user.DeptID = registerUser.DeptID; user.PttID = registerUser.PttID; user.ItID = registerUser.ItID; result = await userAdapter.AddOrUpdateAsync(user); if (result > 0) { model.IsSucceed = true; return(Json(user)); } else { model.IsSucceed = false; model.ErrorMessage = "插入数据有误!"; } } } return(Json(model)); }