public async Task Add(CityHall cityHall) { if (!ExecuteValidation(new CityHallValidation(), cityHall)) { return; } bool userExists = await _userService.FirebaseUserExistsByEmail(cityHall.Email); if (userExists) { Notify("Endereço de e-mail já cadastrado no sistema."); return; } await _repository.Add(cityHall); CityHall newCityHall = await _repository.GetById(cityHall.Id); if (newCityHall != null) { UserRecordArgs args = new UserRecordArgs() { DisplayName = newCityHall.Name, Email = newCityHall.Email, Password = newCityHall.CNPJ }; UserRecord fbUser = await _firebaseAuth.CreateUserAsync(args); if (fbUser != null) { User newUser = new User() { FirebaseUserId = fbUser.Uid, Email = fbUser.Email, CreationDate = DateTime.Now, FirstName = fbUser.DisplayName, CityHallId = newCityHall.Id }; await _userService.Add(newUser); // await _relationHandler.UpdateRelationAsync(newUser.Id, newCityHall.Id, true); var claims = new Dictionary <string, object>() { { "app_user_id", newUser.Id }, { "user", true }, { "city_hall", true } }; await _roleService.UpdateUserRole("user", newUser.Id, true); await _roleService.UpdateUserRole("city_hall", newUser.Id, true); await _roleService.UpdateUserClaims(newUser.Id, claims); } } }
public CityHall AddNewCityHall(CreateCityHallDto dto) { if (CheckIfCityHallExist(dto.Name)) { return(null); } var cityHall = mapper.Map <CityHall>(dto); cityHallRepository.Add(cityHall); return(cityHall); }