private void RegisterAccount(NHibernate.ISession session, UserAccountEF user, string aggregatorGroupId) { switch (user.UserType) { case RegisterType.Contrator: ContractorUser cu = new ContractorUser(); cu.AggGroupId = aggregatorGroupId; cu.ContractStatus = (int)ContractStatusCodes.Signing; cu.UserId = user.Id; session.SaveAsync(cu); Task t = _userManager.AddToRoleAsync(user, UserRoleTypes.Contractor); t.Wait(); break; //case RegisterType.Supervisor: // var role_add_result = await _userManager.AddToRoleAsync(user, UserRoleTypes.Supervisor); // //_userManager.AddClaimAsync(user, new Claim()) // SupervisorUser supervisorUser = new SupervisorUserEF(); // supervisorUser.UserId = user.Id; // await _accountContext.SupervisorUsers.AddAsync(supervisorUser); // break; case RegisterType.Aggregator: Task ta = _userManager.AddToRoleAsync(user, UserRoleTypes.Aggregator); ta.Wait(); //_userManager.AddClaimAsync(user, new Claim()) AggregatorUser aggregatorUser = new AggregatorUser(); aggregatorUser.AggGroupId = aggregatorGroupId; aggregatorUser.UserId = user.Id; session.SaveAsync(aggregatorUser); break; } }
//[ValidateAntiForgeryToken] public async Task <IActionResult> SignonAggregator([FromBody] AggregatorRegistModel model) { if (ModelState.IsValid) { AggregatorGroup aggregatorGroup = _accountContext.AggregatorGroups.FirstOrDefault(x => x.AggName == model.Company); if (aggregatorGroup == null) { aggregatorGroup = new AggregatorGroup(); aggregatorGroup.ID = Guid.NewGuid().ToString(); aggregatorGroup.AggName = model.Company; aggregatorGroup.Representation = ""; aggregatorGroup.Address = model.Address; aggregatorGroup.CreateDT = DateTime.Now; aggregatorGroup.PhoneNumber = model.PhoneNumber; await _accountContext.AddAsync(aggregatorGroup); } var user = CreateUserAccount(model, RegisterType.Aggregator); var result = await _userManager.CreateAsync(user, model.Password); //result.Errors if (result.Succeeded) { var role_add_result = await _userManager.AddToRoleAsync(user, UserRoleTypes.Aggregator); //_userManager.AddClaimAsync(user, new Claim()) AggregatorUser aggregatorUser = new AggregatorUser(); aggregatorUser.AggregatorGroup = aggregatorGroup; aggregatorUser.UserId = user.Id; await _accountContext.AggregatorUsers.AddAsync(aggregatorUser); await _accountContext.SaveChangesAsync(); string email_contents = htmlGenerator.GenerateHtml("NotifyEmail.html", new { Name = $"{user.FirstName} {user.LastName}", Company = model.Company, Email = model.Email, Phone = model.PhoneNumber, Address = model.Address, Aggregator = aggregatorGroup.AggName }); string sender = "PEIU 운영팀"; var aggregator_account_users = await _userManager.GetUsersInRoleAsync(UserRoleTypes.Supervisor); await _emailSender.SendEmailAsync(sender, "새로운 중계거래자 가입이 요청되었습니다", email_contents, aggregator_account_users.Select(x => x.Email).ToArray()); return(Ok(new { Result = result })); } else { return(BadRequest(new { Result = result })); } } return(BadRequest()); }