/// <summary> /// 新增 /// </summary> /// <param name="entity"></param> /// <returns></returns> public Sys_Account Add(Add_Sys_Account_Input inputModel) { if (inputModel.Authority.Count == 0 || inputModel.User_Id.IsNullOrEmpty() || inputModel.NickName.IsNullOrEmpty() || inputModel.Password.IsNullOrEmpty()) { throw new Exception("不能为空"); } //检查User_Id重复 //if (base.GetCount(w => w.User_Id == inputModel.User_Id) > 0) throw new Exception("用户id已存在,请填写其他"); if (GetAllByCache().Count(w => w.User_Id == inputModel.User_Id) > 0) { throw new Exception("用户id已存在,请填写其他"); } Sys_Account model = new Sys_Account(); //model.Id = StringHelper.GuidTo16String(); model.Create_Time = DateTime.Now; model.Authority = string.Join(',', inputModel.Authority); model.User_Id = inputModel.User_Id; model.NickName = inputModel.NickName; model.Password_Salt = Guid.NewGuid().ToString(); model.Password = GetEncryptPwd(inputModel.Password, model.Password_Salt); model.Avatar = inputModel.Avatar; model.Disable = inputModel.Disable ?? false; base.Add(model); RemoveCache(); return(model); }
public ActionRes Add([FromBody] Add_Sys_Account_Input model) { //检查权限分组(防止别人乱来) var authorities = Cat.M.Public.Services.Constants.Authority.AllAuthority; if (model.Authority.Count > 0) { foreach (var item in model.Authority) { if (!authorities.Contains(item)) { throw new Exception($"不合法的权限分组[{item}]"); } } } // var res = AllServices.SysAccountService.Add(model); return(ActionRes.Success(res)); }