Esempio n. 1
0
        public async Task <User> SignUpUserAsync(SignUpInput userData)
        {
            if (await usersRepository.FirstOrDefaultAsync(u => u.Phone == userData.Phone) != null)
            {
                throw new BadInputException("user already exists");
            }

            if (!await smsService.CodeIsValidAsync(userData.Phone, userData.SmsCode))
            {
                throw new BadInputException("code is invalid");
            }

            // it would be better to move this somewhere
            var user = mapper.Map <User>(userData);

            user.Roles = new[] { "client", "worker" };
            user.DateOfRegistration = DateTime.Now;
            user.Profile.Phone      = user.Phone;

            var worker = new Worker {
                StatusId = (int)WorkersStatuses.Offline
            };

            // linq2db can't save both entities in 1 method call
            worker.Id = user.Profile.Id = user.Id = await usersRepository.InsertWithIdAsync(user);

            await profilesRepository.InsertAsync(user.Profile);

            await workersRepository.InsertAsync(worker);

            return(user);
        }