public async Task <Account> CreateAccount(RegisterAccountDTO registerAccountDTO) { var account = _mapper.Map <Account>(registerAccountDTO); account.HashPassword = BCrypt.Net.BCrypt.HashPassword(registerAccountDTO.Password); account.Role = RoleNames.User; account.CreatedAt = DateTime.UtcNow; var isExistedAcc = (await _accountRepository.FindByCondition(a => a.Email == account.Email || a.Username == account.Username)) .FirstOrDefault(); if (isExistedAcc != null) { throw new AppException(StatusCodes.Status400BadRequest, "Account has already existed!"); } var result = await _accountRepository.Insert(account); if (!result) { throw new AppException(StatusCodes.Status500InternalServerError, "Something went wrong, cannot register account!"); } return(account); }
public async Task <ApiResponse <AccountDTO> > Register(RegisterAccountDTO registerAccountDTO) { var account = await _accountService.CreateAccount(registerAccountDTO); _logger.Information($"Created user {account.Username} on {TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, "SE Asia Standard Time")}."); return(await Login(account.Username, registerAccountDTO.Password)); }
public async Task <ApplicationUserIdentity> Register(RegisterAccountDTO registerAccountDTO) { ApplicationUserIdentity registerUser = Mapper.Map <ApplicationUserIdentity>(registerAccountDTO); await TheUnitOfWork.AccountRepo.Register(registerUser); TheUnitOfWork.SaveChanges(); return(registerUser); }
public async Task <IActionResult> Register(RegisterAccountDTO registerAccountDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bool isUsernameExist = await _accountAppService.checkUsernameExist(registerAccountDTO.UserName); if (isUsernameExist) { return(BadRequest(new Response { Message = "Username already exist" })); } bool isEmailExist = await _accountAppService.checkEmailExist(registerAccountDTO.Email); if (isEmailExist) { return(BadRequest(new Response { Message = "Email already exist" })); } try { registerAccountDTO.IsDoctor = false; ApplicationUserIdentity registerUser = await _accountAppService.Register(registerAccountDTO); await _accountAppService.AssignToRole(registerUser.Id, UserRoles.Patient); _generalAppService.CommitTransaction(); return(Ok(new Response { Message = "Account created successfully" })); } catch (Exception ex) { _generalAppService.RollbackTransaction(); return(BadRequest(new Response { Message = ex.Message })); } }
public IHttpActionResult RegisterAccount(RegisterAccountDTO AccountPer) { try { object PersBirthDtm = DateTime.Parse(AccountPer.PersBirthDtm, culture); var objNames = new object[] { "AccountPwd", "EmailAddress", "FirstName", "LastName", "LandLine" , "PersBirthDtm", "PersHomePhonePhN", "PersonType", "PrimaryRoleID", "OtherPersonDetails" , "PersPermanentAddressText", "CountryID", "CityProvinceID", "DistrictID", "NationnalityCode", "Perscode", "JTID", "V_AccountType" }; var objValues = new object[] { AccountPer.AccountPwd, AccountPer.EmailAddress, AccountPer.FirstName , AccountPer.LastName, AccountPer.LandLine , PersBirthDtm, AccountPer.PersHomePhonePhN, AccountPer.PersonType , AccountPer.PrimaryRoleID, AccountPer.OtherPersonDetails, AccountPer.PersPermanentAddressText , AccountPer.CountryID, AccountPer.CityProvinceID, AccountPer.DistrictID, AccountPer.NationnalityCode, AccountPer.Perscode, AccountPer.JTID, AccountPer.V_AccountType }; var result = this.Repository.ExecuteStoreScalar("usp_RegisterAccount", objNames, objValues); //sendmail //_sendmail.RegisterAccount(to, subject, AccountID, ActivationCode, Url) //RegisterAccount if (result != null) { foreach (DataRow dr in result.Tables[0].Rows) { if (dr["ReturnCode"].ToString() == "0") { string to = dr["EmailAddress"].ToString(); string subject = "Đăng Ký Tài Khoản Thành Công"; string ActivationCode = dr["ActivationCode"].ToString(); string Url = AccountPer.Url; _sendmail.RegisterAccount(to, subject, ActivationCode, Url); } break; } } return(Ok(PocoHelper.GetTableRows(result.Tables[0]))); } catch (Exception ex) { log.Error(ex.Message); return(Content(HttpStatusCode.BadRequest, ex.Message)); } }
public async Task <IActionResult> Register(RegisterAccountDTO model) { return(Ok(await _authenticateService.Register(model))); }