private async Task <ProfileDetails> InitUserProfile(string liveId, string accessToken) { if (string.IsNullOrEmpty(liveId)) { return(null); } var profileDetails = ProfileService.GetProfile(liveId); if (profileDetails == null) { if (string.IsNullOrEmpty(accessToken)) { return(null); } var svc = new LiveIdAuth(); var getResult = await svc.GetMeInfo(accessToken); var jsonResult = getResult; profileDetails = new ProfileDetails(jsonResult) { IsSubscribed = true, UserType = UserTypes.Regular }; // While creating the user, IsSubscribed to be true always. // When creating the user, by default the user type will be of regular. profileDetails.ID = ProfileService.CreateProfile(profileDetails); // This will used as the default community when user is uploading a new content. // This community will need to have the following details: var communityDetails = new CommunityDetails { CommunityType = CommunityTypes.User, // 1. This community type should be User CreatedByID = profileDetails.ID, // 2. CreatedBy will be the new USER. IsFeatured = false, // 3. This community is not featured. Name = Resources.UserCommunityName, // 4. Name should be NONE. AccessTypeID = (int)AccessType.Private, // 5. Access type should be private. CategoryID = (int)CategoryType.GeneralInterest // 6. Set the category ID of general interest. We need to set the Category ID as it is a foreign key and cannot be null. }; var communityService = DependencyResolver.Current.GetService(typeof(ICommunityService)) as ICommunityService; var notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService; // 7. Create the community communityService.CreateCommunity(communityDetails); // Send New user notification. notificationService.NotifyNewEntityRequest(profileDetails, HttpContext.Request.Url.GetServerLink()); } SessionWrapper.Set("CurrentUserID", profileDetails.ID); SessionWrapper.Set("CurrentUserProfileName", profileDetails.FirstName + " " + profileDetails.LastName); SessionWrapper.Set("ProfileDetails", profileDetails); return(profileDetails); }
public async Task <bool> RegisterUser() { var profileDetails = await ValidateAuthentication(); if (profileDetails == null) { var svc = new LiveIdAuth(); dynamic jsonResult = svc.GetMeInfo(System.Web.HttpContext.Current.Request.Headers["LiveUserToken"]); profileDetails = new ProfileDetails(jsonResult); // While creating the user, IsSubscribed to be true always. profileDetails.IsSubscribed = true; // When creating the user, by default the user type will be of regular. profileDetails.UserType = UserTypes.Regular; profileDetails.ID = ProfileService.CreateProfile(profileDetails); // This will used as the default community when user is uploading a new content. // This community will need to have the following details: var communityDetails = new CommunityDetails { CommunityType = CommunityTypes.User, // 1. This community type should be User CreatedByID = profileDetails.ID, // 2. CreatedBy will be the new USER. IsFeatured = false, // 3. This community is not featured. Name = Resources.UserCommunityName, // 4. Name should be NONE. AccessTypeID = (int)AccessType.Private, // 5. Access type should be private. CategoryID = (int)CategoryType.GeneralInterest // 6. Set the category ID of general interest. We need to set the Category ID as it is a foreign key and cannot be null. }; // 7. Create the community _communityService.CreateCommunity(communityDetails); // Send New user notification. _notificationService.NotifyNewEntityRequest(profileDetails, HttpContext.Request.Url.GetServerLink()); } else { throw new WebFaultException <string>("User already registered", HttpStatusCode.BadRequest); } return(true); }