private static IReadOnlyDictionary <string, string> PatchUser(PatchRequest2 patch, IRow row)
        {
            ResourceFactory <Core2EnterpriseUser> userFactory = new UserFactory(row);
            Core2EnterpriseUser user = userFactory.Create();

            user.Apply(patch);
            ColumnsFactory <Core2EnterpriseUser> userColumnsFactory = new UserColumnsFactory(user);
            IReadOnlyDictionary <string, string> result             = userColumnsFactory.CreateColumns();

            return(result);
        }
Beispiel #2
0
        public override async Task UpdateAsync(IPatch patch, string correlationIdentifier)
        {
            if (null == patch)
            {
                throw new ArgumentNullException(nameof(patch));
            }

            if (null == patch.ResourceIdentifier)
            {
                throw new ArgumentException(SqlProviderResources.ExceptionInvalidPatch);
            }

            if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier))
            {
                throw new ArgumentException(SqlProviderResources.ExceptionInvalidPatch);
            }

            if (null == patch.PatchRequest)
            {
                throw new ArgumentException(SqlProviderResources.ExceptionInvalidPatch);
            }

            PatchRequest2 patchRequest = patch.PatchRequest as PatchRequest2;

            if (null == patchRequest)
            {
                string unsupportedPatchTypeName = patch.GetType().FullName;
                throw new NotSupportedException(unsupportedPatchTypeName);
            }

            Core2EnterpriseUser user = await this.context.Users.Where(u => u.Identifier == patch.ResourceIdentifier.Identifier)
                                       .Include(u => u.Addresses)
                                       .Include(u => u.ElectronicMailAddresses)
                                       .Include(u => u.InstantMessagings)
                                       .Include(u => u.PhoneNumbers)
                                       .FirstOrDefaultAsync();

            if (user == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            user.Apply(patchRequest);
            this.context.Users.Update(user);
            await this.context.SaveChangesAsync();
        }
        public override async Task UpdateAsync(IPatch patch, string correlationIdentifier)
        {
            if (null == patch)
            {
                throw new ArgumentNullException(nameof(patch));
            }

            if (null == patch.ResourceIdentifier)
            {
                throw new ArgumentException("Invalid Patch");
            }

            if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier))
            {
                throw new ArgumentException("Invalid Patch");
            }

            if (null == patch.PatchRequest)
            {
                throw new ArgumentException("Invalid Patch");
            }

            PatchRequest2 patchRequest =
                patch.PatchRequest as PatchRequest2;

            if (null == patchRequest)
            {
                string unsupportedPatchTypeName = patch.GetType().FullName;
                throw new NotSupportedException(unsupportedPatchTypeName);
            }

            if (int.TryParse(patch.ResourceIdentifier.Identifier, out int id) && _context.Users.Find(id) is MvcMovie.Models.User modelUser)
            {
                Core2EnterpriseUser scimUser = (Core2EnterpriseUser)modelUser;
                scimUser.Apply(patchRequest);
                await ReplaceAsync(scimUser, correlationIdentifier);
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
        }
        public override Task UpdateAsync(IPatch patch, string correlationIdentifier)
        {
            if (null == patch)
            {
                throw new ArgumentNullException(nameof(patch));
            }

            if (null == patch.ResourceIdentifier)
            {
                throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch);
            }

            if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier))
            {
                throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch);
            }

            if (null == patch.PatchRequest)
            {
                throw new ArgumentException(SampleServiceResources.ExceptionInvalidPatch);
            }

            PatchRequest2 patchRequest = patch.PatchRequest as PatchRequest2;

            if (null == patchRequest)
            {
                string unsupportedPatchTypeName = patch.GetType().FullName;
                throw new NotSupportedException(unsupportedPatchTypeName);
            }

            // call service
            TargetUser target;

            try
            {
                // get user
                target = _storageService.RetrieveUser(new Guid(patch.ResourceIdentifier.Identifier));

                // patch user
                Core2EnterpriseUser patched = (Core2EnterpriseUser)target;
                patched.Apply(patchRequest);

                // update user
                _storageService.UpdateUser((TargetUser)patched);
            }
            catch (Exception err)
            {
                switch (err.Message)
                {
                case "Conflict":
                    throw new HttpResponseException(HttpStatusCode.Conflict);

                case "NotFound":
                    throw new HttpResponseException(HttpStatusCode.NotFound);

                default:
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }

            return(Task.CompletedTask);
        }