Esempio n. 1
0
        public async Task <_ <ExternalLoginMapEntity> > SaveExternalProviderMapping(ExternalLoginMapEntity model)
        {
            model.Should().NotBeNull("save external provider mapping model");
            model.ProviderKey.Should().NotBeNullOrEmpty("save external provider mapping provder key");
            model.UserID.Should().NotBeNullOrEmpty("save external provider mapping user uid");

            var res = new _ <ExternalLoginMapEntity>();

            model.InitSelf();
            if (!model.IsValid(out var msg))
            {
                return(res.SetErrorMsg(msg));
            }

            var db    = this._userRepo.Database;
            var table = db.Set <ExternalLoginMapEntity>();

            //删除之前的绑定
            var old = await table.Where(x =>
                                        x.ProviderKey == model.ProviderKey &&
                                        x.UserID == model.UserID &&
                                        x.UID != model.UID).ToArrayAsync();

            if (old.Any())
            {
                table.RemoveRange(old);
            }
            table.Add(model);

            await db.SaveChangesAsync();

            return(res.SetSuccessData(model));
        }
Esempio n. 2
0
        public async Task <_ <ExternalLoginMapEntity> > SaveExternalProviderMapping(ExternalLoginMapEntity model)
        {
            model.Should().NotBeNull("save external provider mapping model");
            model.ProviderKey.Should().NotBeNullOrEmpty("save external provider mapping provder key");
            model.UserID.Should().NotBeNullOrEmpty("save external provider mapping user uid");

            var res = await this.userAccountRepository.SaveExternalProviderMapping(model);

            return(res);
        }