//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #endregion #region Select Token User Update methods. // ================================================================================== /// <summary> /// This method gets generates the page object for the UniFORM client. /// </summary> /// <param name="TokenUserProfile">Evado.Model.EusTokenUserProfile object</param> /// <returns>String</returns> /// <remarks> /// This method consists of the following steps: /// /// 1. /// </remarks> // ---------------------------------------------------------------------------------- public EvEventCodes UpdateTokenUserProfile ( Evado.Model.EusTokenUserProfile TokenUserProfile ) { this.LogMethod ( "UpdateTokenUserProfile" ); this.LogValue ( "LoggingLevel: " + this.LoggingLevel ); try { // // Initialise the Evado clinical adapter object. // this._ApplicationAdapter = new Evado.Digital.Adapter.EuAdapter ( this._ClientVersion, this._GlobalObjects, this._ServiceUserProfile, this._ExitCommand, this._ApplicationPath, this._UniForm_BinaryFilePath, this._UniForm_BinaryServiceUrl ); this._ApplicationAdapter.LoggingLevel = this.LoggingLevel; this.LogValue ( "ApplicationAdapter.LoggingLevel: " + this._ApplicationAdapter.LoggingLevel ); // // Call the adapter token user update method. // EvEventCodes result = this._ApplicationAdapter.UpdateTokenUserProfile ( TokenUserProfile ); this.LogApplication ( this._ApplicationAdapter.AdapterLog ); this.LogMethodEnd ( "UpdateTokenUserProfile" ); return result; } catch ( Exception Ex ) { this.LogException ( Ex ); } this.LogMethodEnd ( "UpdateTokenUserProfile" ); return EvEventCodes.Token_User_Profile_Update_Error; }//END UpdateTokenUserProfile method
public Stream updateTokenUserProfileService(string ClientVersion, Stream content) { Global.ClearApplicationLog( ); this.LogMethod("updateTokenUserProfileService web service"); this.LogDebug("ClientVersion content {0}", ClientVersion); String SessionId = String.Empty; try { // // Initialise the methods variables and object. // string json = String.Empty; Evado.Model.EusTokenUserProfile tokenUserProfile = new Evado.Model.EusTokenUserProfile( ); String hostUrl = this._Context.Request.Headers ["Host"]; this.LogDebug("hostUrl: {0} ", hostUrl); this.LogDebug("Request.Url: {0} ", this._Context.Request.Url); this.LogDebug("Request.UserHostAddress: {0} ", this._Context.Request.UserHostAddress); this.LogDebug("Request.UserHostName: {0} ", this._Context.Request.UserHostName); if (Global.ValidTokenUserProfileIpAddresses.Contains(this._Context.Request.UserHostAddress) == false) { this.LogDebug("ValidTokenUserProfileIpAddresses NOT found"); return(this.WebServiceResponse("ERROR")); } // // first load the POST payload into a string // the POST content comes from the content param above // as it is the only param that is not listed in the URI template // string content_value = new StreamReader(content).ReadToEnd( ); this.LogDebug("Post content \r\n{0}", content_value); // // Log the transaction if (content_value == String.Empty) { return(this.WebServiceResponse("ERROR")); } // // serialise the client groupCommand // Evado.Model.EusTokenUserProfile UserProfie = JsonConvert.DeserializeObject <Evado.Model.EusTokenUserProfile> (content_value); this.LogDebug("AppId: " + UserProfie.ApplicationID); this.LogDebug("TokenId: " + UserProfie.Token); this.LogDebug("UserId: " + UserProfie.UserId); this.LogDebug("GivenName: " + UserProfie.GivenName); this.LogDebug("FamilyName: " + UserProfie.FamilyName); this.LogDebug("EmailAddress: " + UserProfie.EmailAddress); this.LogDebug("UserType: " + UserProfie.UserType); this.LogDebug("UserStatus: " + UserProfie.UserStatus); EvEventCodes result = this.UpdateTokenUserProfile(UserProfie); // // send the web service response to the device app. // return(this.WebServiceResponse(result.ToString())); } catch (Exception Ex) { string EventMessage = "Evado.Digital.WebService.TokenService event method.\r\n" + EvStatics.getException(Ex); this.LogEvent(EventMessage); return(WebServiceResponse(EvEventCodes.Token_User_Profile_Update_Error.ToString())); } // Close catch } //END Create web method.
}//END saveItem method #endregion #region Class update methods // ===================================================================================== /// <summary> /// This method updates user profile for token authentication process. /// </summary> /// <param name="TokenUser">Evado.Model.EusTokenUserProfile object</param> /// <param name="UserTypeList">EdSelectionList object containing the user category options.</param> /// <returns>EvEventCodes: an event code for saving items</returns> // ------------------------------------------------------------------------------------- public EvEventCodes updateTokenUser( Evado.Model.EusTokenUserProfile TokenUser, EvSelectionList UserTypeList) { this.FlushLog( ); this.LogMethod("updateTokenUser"); this.LogDebug("TokenUser.UserId {0}", TokenUser.UserId); this.LogDebug("UserTypeList.Items Title: {0}, items {1}", UserTypeList.Title, UserTypeList.Items.Count); // // Initialise the methods variables and objects. // EvEventCodes result = EvEventCodes.Ok; Evado.Digital.Model.EdUserProfile userProfile = new EdUserProfile( ); Evado.Digital.Model.EdUserProfile existingUserProfile = new EdUserProfile( ); // // Import the user token data. // userProfile.ImportTokenProfile(TokenUser); // // Check that the user id is valid // if (userProfile.UserId == String.Empty) { this.LogEvent("UserId is empty"); return(EvEventCodes.Token_User_Profile_UserId_Empty); } // // validate that the user does not already exist. // existingUserProfile = this._Dal_UserProfiles.GetItem(userProfile.Guid); this.LogDebug(" userProfile.Guid: '{0}', UserId '{1}'", userProfile.Guid, userProfile.UserId); this.LogDebug(" existingUserProfile.Guid: '{0}', UserId '{1}'", existingUserProfile.Guid, existingUserProfile.UserId); if (existingUserProfile.UserId != userProfile.UserId && existingUserProfile.Guid != Guid.Empty) { this.LogDebug("UserId does NOT match the Token value."); this.LogMethodEnd("updateTokenUser"); return(EvEventCodes.Token_User_Profile_UserId_Error); } // // If a new user exists the update their details as a subscribed user. // if (existingUserProfile.UserId == userProfile.UserId && TokenUser.UserStatus == EusTokenUserProfile.UserStatusCodes.New_User) { this.LogDebug("Existing User to update details as a subscribed user."); TokenUser.UserStatus = EusTokenUserProfile.UserStatusCodes.Subscribed_User; } // // if the user does not have an organisation create one for them. // if (userProfile.OrgId == String.Empty) { userProfile.OrgId = existingUserProfile.OrgId; this.LogDebug("No Organisation so create one for the user."); this.AddTokenOrganisation(userProfile); } // // match the user category with the user type. // if (UserTypeList.Items.Count > 0) { this.LogDebug("Updating the use category"); this.LogDebug("UserType {0}.", userProfile.UserType); foreach (EvSelectionList.Item item in UserTypeList.Items) { this.LogDebug("Item C: {0}, V: {1}, D: {2}", item.Category, item.Value, item.Description); if (userProfile.UserType == item.Value) { userProfile.UserCategory = item.Category; break; } } } this.LogDebug("UserCatetory {0}.", userProfile.UserCategory); // // if the role is empty set to the category as a default. // if (userProfile.Roles == String.Empty) { userProfile.Roles = userProfile.UserCategory; } // // based on the user status select the method of user update. // this.LogDebug("UserStatus {0}.", TokenUser.UserStatus); switch (TokenUser.UserStatus) { case EusTokenUserProfile.UserStatusCodes.New_User: { this.LogValue("Add User"); result = this._Dal_UserProfiles.AddItem(userProfile); this.LogDebug(this._Dal_UserProfiles.Log); this.LogMethodEnd("updateTokenUser"); return(result); } case EusTokenUserProfile.UserStatusCodes.Subscribed_User: { this.LogValue("update User"); result = this._Dal_UserProfiles.UpdateItem(userProfile); this.LogDebug(this._Dal_UserProfiles.Log); this.LogMethodEnd("updateTokenUser"); return(result); } default: { this.LogValue("Disable user access"); userProfile.Roles = String.Empty; userProfile.UserCategory = String.Empty; userProfile.UserType = String.Empty; result = this._Dal_UserProfiles.UpdateItem(userProfile); this.LogDebug(this._Dal_UserProfiles.Log); this.LogMethodEnd("updateTokenUser"); return(result); } } }//END updateTokenUser method