public async Task <JsonResult> SignUpUser(OAuth2UserIdentity userIdentity) { ServiceResponse response = default(ServiceResponse); using (Session session = ApplicationModel.Current.CreateSession(new SecurityToken(this.HttpContext.Request.Url.Host, this.HttpContext.User.Identity.Name))) { try { IDataPortal portal = DependencyInjection.Get <IDataPortal>(); OAuth2UserIdentity value = portal.SignUpUser(userIdentity); // Set the status on HTTP and response level. if (value == null) { HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; } ResponseStatus status = value == null ? ResponseStatus.NO_DATA : ResponseStatus.OK; response = new ServiceDataResponse(RestVersion0100Controller.API_VERSION, status, value); } catch (Exception ex) { HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; response = new ServiceErrorResponse(RestVersion0100Controller.API_VERSION, ResponseStatus.ERROR, new ServiceError(ex)); } } return(this.Json(response)); }