public async Task <IEnumerable <OnlineProfile> > DeleteSocialProfile(OnlineProfile profile, UserId userId) { logWriter.LogInformation($"{nameof(DeleteSocialProfile)}({nameof(profile.Type)}={profile.Type}, {nameof(profile.Profile)}={profile.Profile}, {nameof(userId)}={userId.Value})"); var user = await GetUserById(userId); var onlineProfiles = user.OnlineProfiles?.ToList() ?? new List <OnlineProfile>(); int profileIndex = onlineProfiles.FindIndex(x => x.Type == profile.Type && x.Profile.Equals(profile.Profile, StringComparison.OrdinalIgnoreCase)); if (profileIndex >= 0) { var dbItem = Mappers.UserModel.ToDbItem(user); string updateExpression = $"REMOVE OnlineProfiles[{profileIndex}]"; UpdateItemRequest request = new UpdateItemRequest { TableName = tableName, Key = Mappers.UserModel.ToDbKey(user), UpdateExpression = updateExpression }; await dynamoDbCore.UpdateItem(request); onlineProfiles.RemoveAt(profileIndex); user.OnlineProfiles = onlineProfiles; } return(onlineProfiles); }
public async Task <IActionResult> DeleteOnlineProfile([FromBody] OnlineProfile profile) { var userId = GetCurrentUserId(); IEnumerable <OnlineProfile> profiles = await usersService.DeleteSocialProfile(profile, userId); return(Json(profiles.Select(x => x.ToPublic()))); }
private static void SaveOnlineProfile(OnlineProfile profile, string path) { profile.name = profile.username; var assetPath = Path.Combine(path, profile.name + ".asset"); // Only save profiles once if (File.Exists(Path.Combine(Application.dataPath.Replace("/Assets", ""), assetPath))) { return; } if (profile.picture) { var texturePath = Path.Combine(path, "Textures"); if (!AssetDatabase.IsValidFolder(texturePath)) { AssetDatabase.CreateFolder(path, "Textures"); } profile.picture = SaveImage(profile.picture.texture, Path.Combine(texturePath, profile.name + ".png")); } AssetDatabase.CreateAsset(profile, assetPath); }
public static PublicOnlineProfile ToPublic(this OnlineProfile input) { return(new PublicOnlineProfile { Type = input.Type.ToString(), Profile = input.Profile }); }
public async Task Map(string source, OnlineProfile expected) { // Arrange // Act var result = await OnlineProfileMapper.MapAsync(new List <string> { source }); // Assert result.Count.Should().Be(1); result[0].Should().Be(expected); }
public async Task <IActionResult> AddOnlineProfile([FromBody] OnlineProfile profile) { var userId = GetCurrentUserId(); if (profile == null) { logger.LogInformation($"Call to {nameof(AddOnlineProfile)} with null input (user {userId})"); return(BadRequest()); } IEnumerable <OnlineProfile> profiles = await usersService.AddSocialProfile(profile, userId); return(Json(profiles.Select(x => x.ToPublic()))); }
public Task <IEnumerable <OnlineProfile> > AddSocialProfile(OnlineProfile profile, Guid userId) { if (profile.Type == OnlineProfileType.Instagram || profile.Type == OnlineProfileType.Twitter) { // strip @-prefix from profile name for storage profile.Profile = profile.Profile.TrimStart('@'); } else if (profile.Type == OnlineProfileType.Web) { // default to https:// if protocol is missing if (!profile.Profile.StartsWith("http://", StringComparison.OrdinalIgnoreCase) && !profile.Profile.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) { profile.Profile = $"https://{profile.Profile}"; } } return(userRepository.AddSocialProfile(profile, userId)); }
public async Task AddSocialProfileAsync(OnlineProfileType profileType, string profile, string expectedProfile) { Guid userId = Guid.Parse("a1a537ea-6a78-49f5-bdbe-63099197cd49"); userRepositoryMock .Setup(x => x.AddSocialProfile(It.IsAny <OnlineProfile>(), It.IsAny <UserId>())) .Returns <OnlineProfile, UserId>((p, uid) => Task.FromResult(new[] { p }.AsEnumerable())); var service = GetUsersService(); var input = new OnlineProfile { Type = profileType, Profile = profile }; var result = await service.AddSocialProfile(input, userId); result.First().Profile.ShouldBe(expectedProfile); }
public async Task <IEnumerable <OnlineProfile> > AddSocialProfile(OnlineProfile onlineProfile, UserId userId) { var user = await GetUserById(userId); var onlineProfiles = user.OnlineProfiles?.ToList() ?? new List <OnlineProfile>(); var existingProfile = onlineProfiles.FirstOrDefault(x => x.Type == onlineProfile.Type && x.Profile.Equals(onlineProfile.Profile, StringComparison.OrdinalIgnoreCase)); if (existingProfile != null) { // if the online profile was found, just update it (might be casing differences) existingProfile.Profile = onlineProfile.Profile; } else { onlineProfiles.Add(onlineProfile); } user.OnlineProfiles = onlineProfiles; UpdateItemRequest request = new UpdateItemRequest { TableName = tableName, Key = Mappers.UserModel.ToDbKey(user), ExpressionAttributeNames = new Dictionary <string, string> { { "#OnlineProfiles", FieldMappings.User.OnlineProfiles } }, ExpressionAttributeValues = new Dictionary <string, AttributeValue> { { ":OnlineProfiles", Mappers.UserModel.ToDbItem(user)[FieldMappings.User.OnlineProfiles] } }, UpdateExpression = "SET #OnlineProfiles = :OnlineProfiles" }; await dynamoDbCore.UpdateItem(request); return(user.OnlineProfiles); }
public Task <IEnumerable <OnlineProfile> > DeleteSocialProfile(OnlineProfile profile, Guid userId) { return(userRepository.DeleteSocialProfile(profile, userId)); }
public override void OnInspectorGUI() { MessageFeed feed = Selection.activeObject as MessageFeed; if (!feed) { return; } if (feed.messages == null) { feed.messages = new List <Message>(); } for (int i = fadeStatus.Count; i < feed.messages.Count; i++) { fadeStatus.Add(true); } EditorGUILayout.LabelField("Messages", EditorStyles.boldLabel); GUILayout.BeginHorizontal(); if (GUILayout.Button("Expand All", GUILayout.Width(100))) { for (int i = 0; i < fadeStatus.Count; i++) { fadeStatus[i] = true; } } if (GUILayout.Button("Collapse All", GUILayout.Width(100))) { for (int i = 0; i < fadeStatus.Count; i++) { fadeStatus[i] = false; } } GUILayout.EndHorizontal(); for (int i = 0; i < feed.messages.Count; i++) { string details = fadeStatus[i] ? "" : " [" + feed.messages[i].message + "]"; fadeStatus[i] = EditorGUILayout.BeginFoldoutHeaderGroup(fadeStatus[i], "Message " + (i + 1) + details); if (fadeStatus[i]) { var message = feed.messages[i]; EditMessage(ref message); EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Insert Before", GUILayout.Width(100))) { InsertMessage(feed.messages, i); } if (GUILayout.Button("Insert After", GUILayout.Width(100))) { InsertMessage(feed.messages, i + 1); } GUILayout.Space(100); if (GUILayout.Button("Delete", GUILayout.Width(100))) { feed.messages.RemoveAt(i); fadeStatus.RemoveAt(i); i--; } GUILayout.EndHorizontal(); } EditorGUILayout.EndFoldoutHeaderGroup(); } EditorGUILayout.Separator(); if (GUILayout.Button("Add Message", GUILayout.Width(100))) { feed.messages.Add(new Message()); } EditorGUILayout.Separator(); EditorGUILayout.LabelField("Editing options", EditorStyles.boldLabel); onlineProfile = (OnlineProfile)EditorGUILayout.ObjectField(onlineProfile, typeof(OnlineProfile), false); if (GUILayout.Button("Append from file")) { var lines = LoadLines(); feed.AppendMessages(lines); } if (GUILayout.Button("Import from file (removes existing!)")) { var lines = LoadLines(); feed.SetMessages(lines); } startIndex = EditorGUILayout.IntField(startIndex); if (GUILayout.Button("Set Every Second Profile")) { for (int i = startIndex; i < feed.messages.Count; i += 2) { var message = feed.messages[i]; message.profile = onlineProfile; feed.messages[i] = message; } } EditorUtility.SetDirty(feed); }