public IActionResult CreateUser([FromBody] Mpower.Rail.Model.Request.UserRegistration userDetail) { try { if (ModelState.IsValid) { using (IApplicationProcessor _processor = new ApplicationProcessor(_applicationDbContext)) { string pattern = _processor.GetPasswordRegularExpression(); if (!string.IsNullOrEmpty(pattern)) { Regex regex = new Regex(pattern); if (!regex.IsMatch(userDetail.password)) { return(Ok(new Application_ResponseWrapper() { ResponseCode = "1010", ResponseMessage = "Password not validated!", Status = "failed" })); } } else { _errorRepository. Add(new Application_Errors { applicationID = 1, errorDescription = "Password regular expression not found.", errorType = "Log", logDate = System.DateTime.Now, pageID = 0, Source = "Mpower/Rail/UserRegistration/Create" }); _errorRepository.Commit(); return(Ok(new Application_ResponseWrapper() { ResponseCode = "1010", ResponseMessage = "Password not validated!", Status = "failed" })); } } UserRegistration _userDetail = null; using (IUserProcessor _userProcessor = new UserProcessor(_applicationDbContext)) { if (_userProcessor.UserExists(userDetail.email)) { return(Ok(new Application_ResponseWrapper() { ResponseCode = "1012", ResponseMessage = "Email already registered!", Status = "failed" })); } if (_userProcessor.UserCredentialExists(userDetail.subUserId, userDetail.subUserPassword, userDetail.merchantId, userDetail.merchantAccount)) { return(Ok(new Application_ResponseWrapper() { ResponseCode = "1011", ResponseMessage = "User already registered!", Status = "failed" })); } _userDetail = _userProcessor.RegisterAgent(userManager: _userManager, userDetail: userDetail); } return(Ok(new Application_ResponseWrapper() { ResponseCode = "0", ResponseMessage = "success", Status = "success", ResponseResult = _userDetail })); } else { return(Ok(new Application_ResponseWrapper() { ResponseCode = "1000", ResponseMessage = "Invalid model", Status = "failed" })); } } catch (Exception ex) { _errorRepository. Add(new Application_Errors { applicationID = 1, errorDescription = ex.StackTrace, errorType = "Exception", logDate = System.DateTime.Now, pageID = 0, Source = "Mpower/Rail/UserRegistration/Create" }); _errorRepository.Commit(); return(Ok(new Application_ResponseWrapper() { ResponseCode = "1005", ResponseMessage = "An error has occured", Status = "failed" })); } }
/// <summary> // This Method will return the list of Merchant's agent's list. /// </summary> /// <param name="userManager">Object of Identity usermanager class injected on ConfigureServices.</param> /// <param name="userDetail">Object of UserViewModel class to register the agent detail.</param> /// <returns>this will return the UserRegistration object with user detail.</returns> public UserRegistration RegisterAgent(UserManager <UserViewModel> userManager, Mpower.Rail.Model.Request.UserRegistration userDetail) { var user = new UserViewModel { UserName = userDetail.email, Email = userDetail.email }; UserRegistration _userDetail = null; var result = userManager.CreateAsync(user, userDetail.password).Result; //Assign Role to user Here if (result.Succeeded) { var a = userManager.AddToRoleAsync(user, "Agent").Result; _userDetail = new UserRegistration() { UserId = user.Id, merchantAccount = userDetail.merchantAccount, email = userDetail.email, isActive = false, merchantId = userDetail.merchantId, subUserId = userDetail.subUserId, subUserPassword = userDetail.subUserPassword, digitalCertificate = userDetail.digitalCertificate, macId = userDetail.macId, mobNo = userDetail.mobileNo, isIRCTCActivated = true, pancard = userDetail.panCard, deviceId = userDetail.deviceId, CreatedDate = DateTime.Now, }; _userRegistrationRepository.Add(_userDetail); _userRegistrationRepository.Commit(); //var requiredDetail = "{userId:" + user.Id + ",merchantId:" + this._userManager.GetUserId(User).ToString() + "}"; //_logger.LogInformation(3, "User created a new account with password."); //return Ok(new Application_ResponseWrapper(){ResponseCode="100",ResponseMessage="ok",Status="successs",ResponseResult=requiredDetail}); } return(_userDetail); }