public async Task <string> TaoTaiKhoanDoanhNghiep(CreateOrUpdateDoanhNghiepInfoInput input) { try { if (!string.IsNullOrEmpty(input.DoanhNghiep.TenDangNhap)) { if (checkExistTenDangNhap(input.DoanhNghiep.TenDangNhap)) { return("ten_dang_nhap_da_co"); } if (checkExistEmail(input.DoanhNghiep.EmailDoanhNghiep)) { return("email_da_co"); } if (IsValidEmail(input.DoanhNghiep.EmailXacNhan)) { if (checkExistEmail(input.DoanhNghiep.EmailXacNhan)) { return("email_da_co"); } CreateOrUpdateUserInput userDoanhNghiep = new CreateOrUpdateUserInput(); UserEditDto userdto = new UserEditDto(); userdto.Surname = input.DoanhNghiep.SurName; userdto.Name = input.DoanhNghiep.Name; userdto.EmailAddress = input.DoanhNghiep.EmailXacNhan; userdto.IsActive = false; userdto.IsLockoutEnabled = true; userdto.IsTwoFactorEnabled = false; userdto.UserName = input.DoanhNghiep.TenDangNhap.Trim(); userdto.PhoneNumber = input.DoanhNghiep.SoDienThoai; userdto.PhongBanId = null; userdto.RoleLevel = (int)CommonENum.ROLE_LEVEL.DOANH_NGHIEP; userdto.ShouldChangePasswordOnNextLogin = true; userDoanhNghiep.SendActivationEmail = true; userDoanhNghiep.SetRandomPassword = true; userDoanhNghiep.User = userdto; List <string> roleNames = new List <string>(); int tenancyDoanhNghiepId = 1; if (!ConfigurationManager.AppSettings["TENANTCY_ID_DOANH_NGHIEP"].IsNullOrEmpty()) { tenancyDoanhNghiepId = Convert.ToInt32(ConfigurationManager.AppSettings["TENANTCY_ID_DOANH_NGHIEP"]); } using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant)) { var roleDoanhNghiep = _roleManager.Roles.Where(x => x.IsDefault == true && x.TenantId == tenancyDoanhNghiepId).ToList(); if (roleDoanhNghiep != null && roleDoanhNghiep.Count() > 0) { foreach (var role in roleDoanhNghiep) { roleNames.Add(role.Name); } } } userDoanhNghiep.AssignedRoleNames = roleNames.ToArray(); if (userDoanhNghiep.AssignedRoleNames.Length > 0) { using (var unitOfWork = _unitOfWorkManager.Begin()) { var userId = await _userService.CreateUserFrontEndAsync(userDoanhNghiep); if (input.DoanhNghiep.TinhId != null) { var tinh = _tinhRepos.Get(input.DoanhNghiep.TinhId.Value); input.DoanhNghiep.Tinh = tinh != null ? tinh.Ten : ""; } if (input.DoanhNghiep.HuyenId.HasValue) { var huyen = _huyenRepos.Get(input.DoanhNghiep.HuyenId.Value); input.DoanhNghiep.Huyen = huyen != null ? huyen.Ten : ""; } if (input.DoanhNghiep.XaId.HasValue) { var xa = _xaRepos.Get(input.DoanhNghiep.XaId.Value); input.DoanhNghiep.Xa = xa != null ? xa.Ten : ""; } if (input.DoanhNghiep.LoaiHinhDoanhNghiepId != null) { var loaihinh = _loaiHinhRepos.Get(input.DoanhNghiep.LoaiHinhDoanhNghiepId.Value); input.DoanhNghiep.TenLoaiHinh = loaihinh != null ? loaihinh.TenLoaiHinh : ""; } input.DoanhNghiep.IsDaXuLy = false; input.DoanhNghiep.MaSoThue = input.DoanhNghiep.MaSoThue.Trim(); long id = await CreateOrUpdateDoanhNghiepAsync(input); UpdateUserDoanhNghiepId(userId, id); unitOfWork.Complete(); } } else { return("vai_tro_doanh_nghiep_khong_ton_tai"); } return("ok"); } else { return("email_khong_ton_tai"); } } else { return("ten_dang_nhap_khong_hop_le"); } } catch (Exception ex) { Logger.Error($"{DateTime.Now.ToString("HH:mm:ss dd/MM/yyyy")} TaoTaiKhoanDoanhNghiep {ex.Message} {JsonConvert.SerializeObject(ex)}"); return(ex.Message); } }