Exemplo n.º 1
0
        public virtual async Task <_ <AdminEntity> > AddAccount(AdminEntity model, string specific_uid = null)
        {
            model.Should().NotBeNull();
            model.UserName.Should().NotBeNullOrEmpty();

            var data = new _ <AdminEntity>();

            model.InitEntity();
            if (ValidateHelper.IsNotEmpty(model.PassWord))
            {
                model.PassWord = this._passHelper.Encrypt(model.PassWord);
            }
            if (!this.__valid_user_name__(model.UserName, out var msg))
            {
                return(data.SetErrorMsg(msg));
            }
            //检查用户名是否存在
            if (await this.IsUserNameExist(model.UserName))
            {
                return(data.SetErrorMsg("用户名已存在"));
            }

            if (ValidateHelper.IsNotEmpty(specific_uid))
            {
                model.SetId(specific_uid);
            }

            await this.adminAccountRepository.InsertAsync(model);

            data.SetSuccessData(model);
            return(data);
        }