Exemplo n.º 1
0
        private async Task <bool> CreateIntitutionUserEntry(RegisterViewModel model)
        {
            bool result = false;

            //get user institution domain
            string[] userSplitn = model.Email.Split('@');
            string   userDomain = string.Empty;

            if (userSplitn != null && userSplitn.Count() == 2)
            {
                userDomain = userSplitn[1].ToUpper();
            }
            List <Institution> insts   = dbCOn.Institution.Where(x => x.Domain.ToUpper() == userDomain).ToList();
            List <User>        newUser = dbCOn.User.Where(x => x.NormalizedEmail == model.Email.ToUpper()).ToList();

            if (insts.Count > 0 && newUser.Count > 0)
            {
                InstitutionUser institutionUser = new InstitutionUser
                {
                    InstitutionId = insts[0].Id,
                    UserId        = newUser[0].Id
                };
                await dbCOn.InstitutionUser.AddAsync(institutionUser);

                await dbCOn.SaveChangesAsync();


                result = true;
            }
            return(result);
        }
        private void RegisterInstitutionUser(RegisterNewInstitutionUserCommand command,
                                             User user,
                                             out InstitutionUser institutionUser)
        {
            institutionUser = new InstitutionUser(Guid.NewGuid(),
                                                  user.Id,
                                                  command.SocialReason,
                                                  command.FantasyName,
                                                  command.CNPJ);

            _institutionUserRepository.Add(institutionUser);
        }
        private void RegisterPhones(ICollection <PhoneCommand> phones, InstitutionUser institutionUser)
        {
            if (phones == null)
            {
                return;
            }

            foreach (var phone in phones)
            {
                _phoneRepository.Add(new Phone(Guid.NewGuid(), institutionUser.Id, phone.Number));
            }
        }