Exemplo n.º 1
0
        private static ApplicationDbContext GetInMemoryDbContext()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var context = new ApplicationDbContext(options);

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            UserPhoneEntity userPhoneEntity = UserPhoneEntityData;

            context.Add <UserPhoneEntity>(userPhoneEntity);
            context.SaveChanges();

            return(context);
        }
Exemplo n.º 2
0
        public async Task <_ <UserPhoneEntity> > SetPhone(string uid, string phone)
        {
            uid.Should().NotBeNullOrEmpty("set phone uid");
            phone.Should().NotBeNullOrEmpty("set phone phone");

            var res = new _ <UserPhoneEntity>();

            if (!this.__valid_phone__(phone, out var msg))
            {
                return(res.SetErrorMsg(msg));
            }

            if (await this.IsPhoneExist(phone))
            {
                return(res.SetErrorMsg("手机号已存在"));
            }

            var db = this._userRepo.Database;

            var set = db.Set <UserPhoneEntity>();

            var data = await set.Where(x => x.UserUID == uid).ToArrayAsync();

            if (data.Any())
            {
                set.RemoveRange(data);
            }

            var map = new UserPhoneEntity()
            {
                UserUID = uid,
                Phone   = phone
            };

            map.InitSelf();

            set.Add(map);

            await db.SaveChangesAsync();

            return(res.SetSuccessData(map));
        }