Exemplo n.º 1
0
        public async Task <Guid> CreateUser(string number, string password)
        {
            number = number.FormatToNumber();
            if (!number.ValidateNumber())
            {
                throw new ArgumentException("Плохой номер телефона");
            }
            await _config.VerifyPassword(password);

            var user = new User()
            {
                Number = number,
                Token  = Guid.NewGuid(),
                Status = UserStatus.Registering
            };

            _db.Users.AddOrUpdate(user, x => x.Number == user.Number);
            await _db.SaveChangesAsync();

            return(user.Token);
        }
Exemplo n.º 2
0
        public async Task <Guest> AddGuest(int barrierId, DateTime expires, string password)
        {
            if (IsExpired(expires))
            {
                throw new ArgumentException($"Время {expires} уже прошло");
            }
            await _configService.VerifyPassword(password);

            var barrier = await _domainContext.GetBarrierById(barrierId)
                          .ThrowIfNull(barrierId);

            var guest = new Guest()
            {
                Id      = Guid.NewGuid(),
                Barrier = barrier,
                Expires = expires
            };
            await _domainContext.AddAsync(guest);

            await _domainContext.SaveChangesAsync();

            return(guest);
        }