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); }
/// <summary> /// Sign up a new <see cref="OAuth2User"/> account. /// </summary> /// <param name="user">The <see cref="OAuth2User"/> data transfer object.</param> /// <returns>The registered <see cref="OAuth2User"/> account.</returns> public DataTransfer.OAuth2UserIdentity SignUpUser(OAuth2UserIdentity userIdentity) { DataTransfer.OAuth2UserIdentity value = UnitOfWork.Execute<DataTransfer.OAuth2UserIdentity>(() => { IOAuth2AuthorizationStoreAgent agent = DependencyInjection.Get<IOAuth2AuthorizationStoreAgent>(); Domain.Entity.OAuth2UserIdentity _userIdentity = userIdentity.ToEntity(); Domain.Entity.OAuth2UserIdentity entity = agent.SignUpUser(_userIdentity); DataTransfer.OAuth2UserIdentity _value = entity.ToDataTransferValue(); return _value; }); return value; }