public async Task <Result> Handle(SendConfirmCodeCommand request, CancellationToken cancellationToken) { var user = await _userRepository.GetAsync(x => x.Mobile == request.Mobile && x.IsDelete == false, cancellationToken); if (user is null) { return(Result.Failed(new BadRequestObjectResult(new ApiMessage(ResponseMessage.UserNotFound)))); } user.ExpiredCode = DateTime.Now.AddDays(2); user.ActiveCode = new Random().Next(10000, 99999).ToString(); var employee = await _employeeRepository.GetAsync(x => x.IsDeleted == false && x.User.Id == user.Id, cancellationToken); //if user exist in employee consider as approved if (employee != null) { employee.IsApproved = true; await _employeeRepository.UpdateAsync(employee); } await _userRepository.UpdateAsync(user); await _payamakService.SendMessage(request.Mobile, user.ActiveCode); return(Result.SuccessFul()); }
public async Task <Result <RegisterResult> > Handle(RegisterCommand request, CancellationToken cancellationToken) { var user = _mapper.Map <User>(request); var role = await _roleRepository.GetAsync(x => x.Name == Role.User, cancellationToken); user.Roles = new List <Role> { role }; await _userRepository.AddAsync(user); await _payamakService.SendMessage(request.Mobile, user.ActiveCode); return(Result <RegisterResult> .SuccessFul(new RegisterResult { Mobile = user.Mobile })); }
public async Task <Result <RegisterResult> > Handle(RegisterEmployeeCommand request, CancellationToken cancellationToken) { var user = await _userRepository.GetAsync(x => x.Mobile == request.Mobile && x.IsDelete == false, cancellationToken); if (user is null) { return(Result <RegisterResult> .Failed(new BadRequestObjectResult(new ApiMessage(ResponseMessage.UserNotFound)))); } user.IsMobileConfirm = true; user.ExpiredCode = DateTime.Now.AddMinutes(2); await _userRepository.UpdateAsync(user); await _payamakService.SendMessage(user.Mobile, user.ActiveCode); return(Result <RegisterResult> .SuccessFul(new RegisterResult { Mobile = user.Mobile })); }