Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        public async Task <ApplicationUserIdentity> Register(RegisterAccountDTO registerAccountDTO)
        {
            ApplicationUserIdentity registerUser = Mapper.Map <ApplicationUserIdentity>(registerAccountDTO);
            await TheUnitOfWork.AccountRepo.Register(registerUser);

            TheUnitOfWork.SaveChanges();

            return(registerUser);
        }
Ejemplo n.º 4
0
        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
                }));
            }
        }
Ejemplo n.º 5
0
        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));
            }
        }
Ejemplo n.º 6
0
 public async Task <IActionResult> Register(RegisterAccountDTO model)
 {
     return(Ok(await _authenticateService.Register(model)));
 }