public ActionResult Add(AddUsersInput modle) { modle.CreateDate = DateTime.Now; modle.LastLoginDate = DateTime.Now; this.Service.Add(modle); return(this.SuccessMsg("添加成功")); }
void Trim(AddUsersInput input) { if (input.UserName.IsNotNullOrEmpty()) { input.UserName = input.UserName.Trim(); } if (input.Mobile.IsNotNullOrEmpty()) { input.Mobile = input.Mobile.Trim(); } if (input.Email.IsNotNullOrEmpty()) { input.Email = input.Email.Trim(); } }
public Users Add(AddUsersInput input) { //this.InsertFromDto(input); this.Trim(input); input.Validate(); //if (input.UserName.IsNullOrEmpty() && input.Mobile.IsNullOrEmpty() && input.Email.IsNullOrEmpty()) //{ // throw new InvalidInputException("用户名/手机号码/邮箱至少填一个"); //} //string userName = null; //if (input.UserName.IsNotNullOrEmpty()) //{ // userName = input.UserName.ToLower(); // AceUtils.EnsureAccountNameLegal(userName); // bool exists = this.DbContext.Query<Users>().Where(a => a.UserName == userName).Any(); // if (exists) // throw new InvalidInputException("用户名[{0}]已存在".ToFormat(input.UserName)); //} //string mobilePhone = null; //if (input.Mobile.IsNotNullOrEmpty()) //{ // mobilePhone = input.Mobile; // if (AceUtils.IsMobilePhone(mobilePhone) == false) // throw new InvalidInputException("请输入正确的手机号码"); // bool exists = this.DbContext.Query<Users>().Where(a => a.Mobile == mobilePhone).Any(); // if (exists) // throw new InvalidInputException("手机号码[{0}]已存在".ToFormat(mobilePhone)); //} //string email = null; //if (input.Email.IsNotNullOrEmpty()) //{ // email = input.Email.ToLower(); // if (AceUtils.IsEmail(email) == false) // throw new InvalidInputException("请输入正确的邮箱地址"); // bool exists = this.DbContext.Query<Users>().Where(a => a.Email == email).Any(); // if (exists) // throw new InvalidInputException("邮箱地址[{0}]已存在".ToFormat(input.Email)); //} string userSecretkey = UserHelper.GenUserSecretkey(); string encryptedPassword = PasswordHelper.Encrypt(input.UserPass, userSecretkey); Users user = new Users(); user.CreateDate = DateTime.Now; user.Email = input.Email; user.FromID = input.FromID; user.LastLoginDate = DateTime.Now; user.Mobile = input.Mobile; user.RoleID = 0; user.Sex = 0; user.ST = 0; user.UserName = input.UserName; user.UserPass = encryptedPassword; user.UserSecretkey = userSecretkey; user.OpenID = input.OpenID; user.ShopID = input.ShopID; user.UserIcon = input.UserIcon; user.Id = IdHelper.CreateStringSnowflakeId(); return(this.DbContext.Insert(user)); }