public async Task <ActionResult <ApplicationUser> > Register(ApplicationUserCreate applicationUserCreate) { var applicationUserIdentity = new ApplicationUserIdentity { Username = applicationUserCreate.Username, Email = applicationUserCreate.Email, Fullname = applicationUserCreate.Fullname }; var result = await _userManager.CreateAsync(applicationUserIdentity, applicationUserCreate.Password); if (result.Succeeded) { applicationUserIdentity = await _userManager.FindByNameAsync(applicationUserCreate.Username); ApplicationUser applicationUser = new ApplicationUser() { ApplicationUserId = applicationUserIdentity.ApplicationUserId, Username = applicationUserIdentity.Username, Email = applicationUserIdentity.Email, Fullname = applicationUserIdentity.Fullname, Token = _tokenService.CreateToken(applicationUserIdentity) }; return(Ok(applicationUser)); } return(BadRequest(result.Errors)); }
public async Task <IActionResult> Create([FromBody] ApplicationUserCreate _userData) { if (_userData != null && _userData.Email != null && _userData.Password != null) { var user = await GetUser(_userData.Email, _userData.Password); if (user == null) { return(Ok(_userService.CreateUser(new ApplicationUser { Email = _userData.Email, CreatedDate = TimeSpan.FromTicks(DateTime.Now.Ticks), FirstName = _userData.FirstName, LastName = _userData.LastName, Password = _userData.Password, UserName = _userData.UserName }))); } else { return(BadRequest("User already exist")); } } else { return(BadRequest()); } }
/// <summary> /// Create Creates the application user with the given properties. /// </summary> /// <exception cref="PostFinanceCheckout.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="entity">The user object with the properties which should be created.</param> /// <returns>ApiResponse of ApplicationUserCreateWithMacKey</returns> public ApiResponse <ApplicationUserCreateWithMacKey> CreateWithHttpInfo(ApplicationUserCreate entity) { // verify the required parameter 'entity' is set if (entity == null) { throw new ApiException(400, "Missing required parameter 'entity' when calling ApplicationUserService->Create"); } var localVarPath = "/application-user/create"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new List <KeyValuePair <String, String> >(); var localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json;charset=utf-8" }; String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json;charset=utf-8" }; String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (entity != null && entity.GetType() != typeof(byte[])) { localVarPostBody = this.Configuration.ApiClient.Serialize(entity); // http body (model) parameter } else { localVarPostBody = entity; // byte array } this.Configuration.ApiClient.ResetTimeout(); // make the HTTP request IRestResponse localVarResponse = (IRestResponse)this.Configuration.ApiClient.CallApi(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("Create", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <ApplicationUserCreateWithMacKey>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (ApplicationUserCreateWithMacKey)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(ApplicationUserCreateWithMacKey)))); }
/// <summary> /// Create Creates the application user with the given properties. /// </summary> /// <exception cref="PostFinanceCheckout.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="entity">The user object with the properties which should be created.</param> /// <returns>ApplicationUserCreateWithMacKey</returns> public ApplicationUserCreateWithMacKey Create(ApplicationUserCreate entity) { ApiResponse <ApplicationUserCreateWithMacKey> localVarResponse = CreateWithHttpInfo(entity); return(localVarResponse.Data); }