public IActionResult UpdateProfile(int profileId, [FromBody] JsonPatchDocument <ProfilePatch> patchDocument) { Profile initialProfile = _profileRepository.GetProfile(profileId); if (initialProfile == null) { return(NotFound()); } ProfilePatch patchProfile = new ProfilePatch { Name = initialProfile.Name, ProfilePictureUrl = initialProfile.ProfilePictureUrl, Friends = initialProfile.Friends }; patchDocument.ApplyTo(patchProfile, ModelState); if (!ModelState.IsValid) { return(BadRequest()); } initialProfile.Name = patchProfile.Name; initialProfile.ProfilePictureUrl = patchProfile.ProfilePictureUrl; initialProfile.Friends = patchProfile.Friends; _profileRepository.UpdateProfile(profileId, initialProfile); return(NoContent()); }
public static void AssertProfileUpdate(ProfileResource updatedProfile, ProfilePatch updateOptions) { Assert.AreEqual(updatedProfile.Data.Tags.Count, updateOptions.Tags.Count); foreach (var kv in updatedProfile.Data.Tags) { Assert.True(updateOptions.Tags.ContainsKey(kv.Key)); Assert.AreEqual(kv.Value, updateOptions.Tags[kv.Key]); } }
public async Task Update() { SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync(); ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-"); string afdProfileName = Recording.GenerateAssetName("AFDProfile-"); ProfileResource afdProfile = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor); ProfilePatch updateOptions = new ProfilePatch(); updateOptions.Tags.Add("newTag", "newValue"); var lro = await afdProfile.UpdateAsync(WaitUntil.Completed, updateOptions); ProfileResource updatedAfdProfile = lro.Value; ResourceDataHelper.AssertProfileUpdate(updatedAfdProfile, updateOptions); }
public bool PatchProfileById(int profileID, JsonPatchDocument <ProfilePatch> profilePatch) { Profile profile = GetProfileById(profileID); if (profile) { // TODO: All of this seems like unnecessary clutter ProfilePatch patchProfile = new ProfilePatch { FriendIDs = profile.FriendIDs, ImageURL = profile.ImageURL }; profilePatch.ApplyTo(patchProfile); profile.FriendIDs = patchProfile.FriendIDs; profile.ImageURL = patchProfile.ImageURL; return(true); } return(false); }