Esempio n. 1
0
        public async Task Registration(PersonModel model)
        {
            var userInDb = await _context.Persons.FirstOrDefaultAsync(x => x.PhoneNumber == model.PhoneNumber);

            if (userInDb != null)
            {
                throw new Exception("Пользователь уже зарегистрирован. Пожалуйста, укажите другой номер телефона");
            }
            var person = new Persons
            {
                Fio         = model.Fio,
                Password    = SecurePasswordHasher.HashPassword(model.Password),
                Address     = model.Address,
                Balance     = model.Balance ?? default(decimal),
                PhoneNumber = model.PhoneNumber,
                Role        = model.Role ?? (byte)PersonTypes.Client
            };

            _context.Persons.Add(person);
            await _context.SaveChangesAsync();
        }
Esempio n. 2
0
        public async Task Registration(PatientModel user)
        {
            if (!DateTime.TryParseExact(user.DateBirth, "dd/MM/yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out var dateBirth))
            {
                throw new Exception("Date parsing error");
            }
            var userInDb = await _context.Users.FirstOrDefaultAsync(x => x.PhoneNumber == user.PhoneNumber);

            if (userInDb != null)
            {
                throw new Exception("User exists");
            }

            var newUser = new Users
            {
                CreatedDate = DateTime.UtcNow,
                Password    = SecurePasswordHasher.HashPassword(user.Password),
                PhoneNumber = user.PhoneNumber,
                Role        = (byte)RoleTypes.Patient
            };

            _context.Users.Add(newUser);
            await _context.SaveChangesAsync();

            var patient = new Patients
            {
                DateBirth = dateBirth,
                Fio       = user.Fio,
                Gender    = bool.Parse(user.Gender),
                WorkPlace = user.WorkPlace,
                UserId    = newUser.UserId
            };

            _context.Patients.Add(patient);
            await _context.SaveChangesAsync();
        }